Ver Fonte

Visitors will now walk over paths and make decisions. Decisions not based on popularity of acts or hunger etc.

jancoow há 10 anos atrás
pai
commit
b1cd936e00

BIN
res/simulator/crosspoint.png


+ 2 - 0
src/gui/simulator/Images.java

@@ -24,6 +24,7 @@ public class Images{
 			images.add(ImageIO.read(Main.class.getResource("/simulator/uitgang.png")));
 			images.add(ImageIO.read(Main.class.getResource("/simulator/snackbar.png")));
 			images.add(ImageIO.read(Main.class.getResource("/simulator/border.png")));
+			images.add(ImageIO.read(Main.class.getResource("/simulator/crosspoint.png")));
 			images.add(ImageIO.read(Main.class.getResource("/visitor.png")));
 			images.add(ImageIO.read(Main.class.getResource("/add.png")));
 			images.add(ImageIO.read(Main.class.getResource("/ground_stone.jpg")));
@@ -61,6 +62,7 @@ public class Images{
 		Exit,
 		Snackbar,
 		Border,
+		Crosspoint,
 		Visitor,
 		Add,
 		PathGroundStone,

+ 2 - 0
src/gui/simulator/Sidebar.java

@@ -4,6 +4,7 @@ import gui.simulator.Images.ImageType;
 import gui.simulator.facilities.RestRoom;
 import gui.simulator.facilities.SimulatorStage;
 import gui.simulator.facilities.SnackBar;
+import gui.simulator.facilities.WayPoint;
 
 import java.awt.BasicStroke;
 import java.awt.Color;
@@ -84,6 +85,7 @@ public class Sidebar implements Serializable  {
 		drawableFacilities.put("Ingang",new AccessPoint(terrain, 0, 0, 0.26, 1));
 		drawableFacilities.put("Uitgang",new ExitPoint(terrain, 0, 0, 0.26, 1));
 		drawableFacilities.put("Snackbar",new SnackBar(0, 0, 0.2, 1, this.terrain));
+		drawableFacilities.put("Wegwijzer",new WayPoint(0, 0, 0.8,1, this.terrain));
 		
 		//paths
 		drawablePaths.put("Ground-stone", Images.ImageType.PathGroundStone);

+ 4 - 3
src/gui/simulator/Terrain.java

@@ -58,7 +58,7 @@ public class Terrain extends JPanel {
 	float cameraScale = 1;
 	private boolean grid;
 	private ArrayList<Visitor> visitors;
-	private ArrayList<WalkingPath> paths;
+	private WalkingPathArrayList paths;
 	Cursor rotate, pathpoint;
 	
 	Point2D lastClickPosition;
@@ -70,10 +70,11 @@ public class Terrain extends JPanel {
 
     public Terrain(int length, int width, SimulatorPane.Terrains terrain, Agenda agenda, SimulatorPane simulator){
     	//get values
+    	maxvisitors = 30;
     	setFestivalHeight(length);
     	setFestivalWidth(width);
     	visitors = new ArrayList<Visitor>();
-    	paths = new ArrayList<WalkingPath>();
+    	paths = new WalkingPathArrayList();
 
     	createCustomCursors();
     	//initialize sidebar & topbar    	
@@ -428,7 +429,7 @@ public class Terrain extends JPanel {
 	}
     public void calculate(){
     	for(Visitor v:visitors){
-    		v.update(visitors, entities);
+    		v.update(visitors, entities,paths);
     	}
     	if(Math.random()*500 <200){
     		Point2D startpoint = null;

+ 53 - 20
src/gui/simulator/Visitor.java

@@ -12,12 +12,11 @@ import javax.swing.ImageIcon;
 
 
 public class Visitor implements Serializable {
-	Point2D positie;
-	double rotation;
-	double speed;
-	Point2D target;
-	WalkingPath currentpath;
-	int currentpoint;
+	private Point2D positie, target;
+	private double rotation, speed;
+	private WalkingPath currentpath;
+	private int currentpoint;
+	private boolean walkInversed;
 	
 	Images.ImageType image = Images.ImageType.Visitor;
 	
@@ -33,7 +32,7 @@ public class Visitor implements Serializable {
 		this.target = starttarget;
 	}
 
-	void update(List<Visitor> visitors, List<DrawEngine> buildings)
+	void update(List<Visitor> visitors, List<DrawEngine> buildings, WalkingPathArrayList walkingpaths)
 	{
 		
 		Point2D difference = new Point2D.Double(
@@ -63,20 +62,41 @@ public class Visitor implements Serializable {
 				);
 		
 
-		if(hasCollision(visitors) || hasCollisionObject(buildings))
+		if(hasCollision(visitors) || hasCollisionObject(buildings)) // collision with a riged building or a visitor, rotate
 		{
 			positie = oldPositie;
 			rotation += 0.2;
 		}
 		if(currentpath != null){
 			if(hasCollision(currentpath.get(currentpoint))){
-				if(currentpoint < currentpath.getPath().size()-1){
+				DrawEngine object = collisionObject(buildings);
+				if(object != null){
+					if(currentpath.getObject1() == object || currentpath.getObject2() == object){
+						List<WalkingPath> connectedWalkingPaths = walkingpaths.getWalkingPadObject(object);
+						if(connectedWalkingPaths.isEmpty()){
+							
+						}else{
+							walkRoute(connectedWalkingPaths.get((int)(Math.random()*connectedWalkingPaths.size())), object);
+						}
+					}
+				}
+				if(walkInversed && currentpoint > 0){
+					currentpoint--;
+				}else if(currentpoint < currentpath.getPath().size()-1){
 					currentpoint++;
-					target = currentpath.get(currentpoint);
+				}
+				target = currentpath.get(currentpoint);
+			}
+		}else{ //entrance
+			DrawEngine object = collisionObject(buildings);
+			if(object != null){
+				List<WalkingPath> connectedWalkingPaths = walkingpaths.getWalkingPadObject(object);
+				if(connectedWalkingPaths.isEmpty()){ // no paths connected to the entrance, what a shame!
+				}else{
+					walkRoute(connectedWalkingPaths.get((int)(Math.random()*connectedWalkingPaths.size())),object);
 				}
 			}
 		}
-		
 	}
 	
 	void paint(Graphics2D g)
@@ -84,9 +104,7 @@ public class Visitor implements Serializable {
 		AffineTransform tx = new AffineTransform();
 		tx.translate(positie.getX()-8, positie.getY()-11);
 		tx.rotate(rotation, 4, 6);
-		
 		g.drawImage(Images.getImage(image), tx ,null);
-		
 	}
 
 	public boolean hasCollision(List<Visitor> visitors) {
@@ -94,25 +112,40 @@ public class Visitor implements Serializable {
 		{
 			if(b == this)
 				continue;
-			if(b.positie.distance(positie) < 11)
+			if(b.positie.distance(positie) < 11){
 				return true;
+			}
 		}
 		return false;
 	}
 	public boolean hasCollisionObject(List<DrawEngine> objects){
 		for(DrawEngine o:objects){
-			if (o.contains(positie))
-				return true;
+			if(o.type != SimulatorPane.Objects.WAYPOINT && o.type != SimulatorPane.Objects.EXIT && o.type != SimulatorPane.Objects.ENTRANCE )
+				if (o.contains(positie))
+					return true;
 		}
 		return false;
 	}
 	public boolean hasCollision(Point p){
 		return positie.distance(p) < 11;
 	}
-	public void walkRoute(WalkingPath p){
-		this.currentpath = p;
-		currentpoint = 0;
-		target = p.get(0);
+	public DrawEngine collisionObject(List<DrawEngine> objects){
+		for(DrawEngine o:objects){
+			if (o.contains(positie))
+				return o;
+		}
+		return null;
+	}
+	public void walkRoute(WalkingPath p, DrawEngine object){
+		if(p.getObject1() == object){
+			currentpoint = 0;
+			walkInversed = false;
+		}else{
+			currentpoint = p.getPath().size()-1;
+			walkInversed= true;
+		}
+		target = p.get(currentpoint);
+		currentpath = p;
 	}
 }
 

+ 26 - 0
src/gui/simulator/WalkingPathArrayList.java

@@ -0,0 +1,26 @@
+package gui.simulator;
+
+import java.util.ArrayList;
+import java.util.List;
+import gui.simulator.WalkingPath;
+
+public class WalkingPathArrayList extends ArrayList<WalkingPath>{
+	public List<WalkingPath> getWalkingPadType(SimulatorPane.Objects type){
+		List<WalkingPath> returnlist = new ArrayList<WalkingPath>();
+		for(WalkingPath wp:this){
+			if(wp.getObject1().type == type || wp.getObject2().type == type){
+				returnlist.add(wp);
+			}
+		}
+		return returnlist;
+	}
+	public List<WalkingPath> getWalkingPadObject(DrawEngine object){
+		List<WalkingPath> returnlist = new ArrayList<WalkingPath>();
+		for(WalkingPath wp:this){
+			if(wp.getObject1() == object|| wp.getObject2() == object){
+				returnlist.add(wp);
+			}
+		}
+		return returnlist;
+	}
+}

+ 0 - 5
src/gui/simulator/WayPoint.java

@@ -1,5 +0,0 @@
-package gui.simulator;
-
-public class WayPoint {
-
-}

+ 16 - 0
src/gui/simulator/facilities/WayPoint.java

@@ -0,0 +1,16 @@
+package gui.simulator.facilities;
+
+import gui.simulator.DrawEngine;
+import gui.simulator.Images;
+import gui.simulator.Images.ImageType;
+import gui.simulator.SimulatorPane;
+import gui.simulator.SimulatorPane.Objects;
+import gui.simulator.Terrain;
+
+public class WayPoint extends DrawEngine{
+
+	public WayPoint(int x, int y, double scale, double distance, Terrain terrain) {
+		super(Images.ImageType.Crosspoint, x, y, scale, 1, SimulatorPane.Objects.WAYPOINT, terrain);
+	}
+
+}