Sfoglia il codice sorgente

People will now walk to food, drink or restrooms when they needed to. Also they wil stay at a stage when a act is playing and leave when the act is done.

jancoow 10 anni fa
parent
commit
0258ae839a

+ 0 - 6
src/agenda/ActTime.java

@@ -132,12 +132,6 @@ public class ActTime implements Serializable, Comparable<ActTime>{
         long beginL = this.beginTime.getTimeInMillis();
         long endL = this.endTime.getTimeInMillis();
 
-        System.out.println(timeL);
-        System.out.println(beginL);
-        System.out.println(endL);
-        System.out.println(timeL >= beginL);
-        System.out.println(timeL == endL);
-
         if(timeL == beginL || endL == timeL){
             return true;
         }else if(timeL >= beginL && timeL <= endL){

+ 1 - 1
src/gui/simulator/DrawEngine.java

@@ -53,7 +53,7 @@ public abstract class DrawEngine {
     }
 
     public boolean contains(Point2D point){
-        Shape shape = new Rectangle2D.Double(0, 0, Images.getImage(image).getWidth(null),Images.getImage(image).getHeight(null));
+        Shape shape = new Rectangle2D.Double(-distanceToOtherObjects, -distanceToOtherObjects, Images.getImage(image).getWidth(null)+2*distanceToOtherObjects,Images.getImage(image).getHeight(null)+2*distanceToOtherObjects);
         return this.getAffineTransform().createTransformedShape(shape).contains(point);
     }
 

+ 1 - 2
src/gui/simulator/Terrain.java

@@ -464,7 +464,7 @@ public class Terrain extends JPanel {
     	for(Visitor v:visitors){
     		v.update(visitors, entities,paths);
     	}
-    	if(Math.random()*500 <200){
+    	if(Math.random()*500 <100){
     		Point2D startpoint = null;
     		for(DrawEngine e:entities){
     			List<AccessPoint> entrances = new ArrayList<AccessPoint>();
@@ -484,7 +484,6 @@ public class Terrain extends JPanel {
     			SimulatorStage stage = (SimulatorStage)object;
     			for(Act act:agenda.getCurrentActs(topbar.getTime())){
     				if(act.getStage() == stage.getStage()){
-    					System.out.println("test");
     					stage.setPlayingact(act);
     					continue stageloop;
     				}

+ 1 - 1
src/gui/simulator/Topbar.java

@@ -145,6 +145,6 @@ public class Topbar implements MouseListener {
 		return background;
 	}
 	public void recalculate(){
-		time.setTimeInMillis(time.getTimeInMillis()+10000);
+		time.setTimeInMillis(time.getTimeInMillis()+3000);
 	}
 }

+ 89 - 40
src/gui/simulator/Visitor.java

@@ -1,15 +1,13 @@
 package gui.simulator;
 
+import gui.simulator.facilities.SimulatorStage;
+
 import java.awt.Graphics2D;
-import java.awt.Image;
-import java.awt.Point;
 import java.awt.geom.AffineTransform;
 import java.awt.geom.Point2D;
 import java.io.Serializable;
 import java.util.List;
 
-import javax.swing.ImageIcon;
-
 
 public class Visitor implements Serializable {
 	private Point2D positie, target;
@@ -17,7 +15,7 @@ public class Visitor implements Serializable {
 	private WalkingPath currentpath;
 	private int currentpoint;
 	private boolean walkInversed;
-	
+	private double food, drink, pis;
 	Images.ImageType image = Images.ImageType.Visitor;
 	
 	public Visitor(Point2D positie, Point2D starttarget) {
@@ -30,16 +28,18 @@ public class Visitor implements Serializable {
 			this.speed = number;
 		}
 		this.target = starttarget;
+		this.food = (int)(Math.random()*100);
+		this.drink = (int)(Math.random()*100);
+		this.pis = (int)(Math.random()*100);
 	}
 
 	void update(List<Visitor> visitors, List<DrawEngine> buildings, WalkingPathArrayList walkingpaths)
 	{
-		
 		Point2D difference = new Point2D.Double(
 				target.getX() - positie.getX(),
 				target.getY() - positie.getY()
 				);
-		
+		rotation %= 360;
 		double newRotation = Math.atan2(difference.getY(), difference.getX());
 		double rotDifference = rotation - newRotation;
 		while(rotDifference > Math.PI)
@@ -61,25 +61,38 @@ public class Visitor implements Serializable {
 				positie.getY() + speed * Math.sin(rotation)
 				);
 		
-
-		if(hasCollision(visitors) || hasCollisionObject(buildings)) // collision with a riged building or a visitor, rotate
+		this.food = (int)(Math.random()*100);
+		this.drink = (int)(Math.random()*100);
+		this.pis = (int)(Math.random()*100);
+		
+		if(hasCollision(visitors) || hasCollisionObject(buildings)) // collision with a ridged building or a visitor, rotate
 		{
 			positie = oldPositie;
-			rotation += 0.2;
+			rotation += 0.5*Math.random();
 		}
 		if(currentpath != null){
-			if(hasCollision(currentpath.get(currentpoint))){
-				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);
+			DrawEngine object = collisionObject(buildings);
+			if(object != null){
+				if((currentpath.getObject1() == object && walkInversed) || (currentpath.getObject2() == object && !walkInversed)){ //end point reached, what to do?
+					if(object.type == SimulatorPane.Objects.STAGE){
+						if(((SimulatorStage) object).getPlayingact() == null){
+							walkNewRoute(walkingpaths, object);
 						}
+					}else if(object.type == SimulatorPane.Objects.DRINK){
+						drink += 50;
+						walkNewRoute(walkingpaths, object);
+					}else if(object.type == SimulatorPane.Objects.SNACKBAR){
+						food += 50;
+						walkNewRoute(walkingpaths, object);
+					}else if(object.type == SimulatorPane.Objects.RESTROOM){
+						pis = 100;
+						walkNewRoute(walkingpaths, object);
+					}else if(object.type == SimulatorPane.Objects.WAYPOINT){
+						walkNewRoute(walkingpaths, object);
 					}
 				}
+			}
+			if(positie.distance(currentpath.get(currentpoint)) < 11){ //collision with a path-point
 				if(walkInversed && currentpoint > 0){
 					currentpoint--;
 				}else if(currentpoint < currentpath.getPath().size()-1){
@@ -90,35 +103,33 @@ public class Visitor implements Serializable {
 		}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);
-				}
+				walkNewRoute(walkingpaths,object);
 			}
 		}
 	}
 	
-	void paint(Graphics2D g)
+	public void paint(Graphics2D g)
 	{
 		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) {
+	private boolean hasCollision(List<Visitor> visitors) { // check collision with other visitors
 		for(Visitor b : visitors)
 		{
-			if(b == this)
-				continue;
-			if(b.positie.distance(positie) < 11){
-				return true;
+
+			if(b != this && b.positie.distance(positie) < 11){
+				double rotdifference = Math.toDegrees(Math.abs(rotation-b.rotation));
+				if(!(rotdifference > 160 && rotdifference < 210)){
+					return true;
+				}
 			}
+			
 		}
 		return false;
 	}
-	public boolean hasCollisionObject(List<DrawEngine> objects){
+	private boolean hasCollisionObject(List<DrawEngine> objects){ // check collision with rigid objects
 		for(DrawEngine o:objects){
 			if(o.type != SimulatorPane.Objects.WAYPOINT && o.type != SimulatorPane.Objects.EXIT && o.type != SimulatorPane.Objects.ENTRANCE )
 				if (o.contains(positie))
@@ -126,26 +137,64 @@ public class Visitor implements Serializable {
 		}
 		return false;
 	}
-	public boolean hasCollision(Point p){
-		return positie.distance(p) < 11;
-	}
-	public DrawEngine collisionObject(List<DrawEngine> objects){
+	private DrawEngine collisionObject(List<DrawEngine> objects){
 		for(DrawEngine o:objects){
-			if (o.contains(positie))
+			if (o.containsWalkArea(positie) || o.contains(positie) )
 				return o;
 		}
 		return null;
 	}
-	public void walkRoute(WalkingPath p, DrawEngine object){
+	private void walkRoute(WalkingPath p, DrawEngine object){
 		if(p.getObject1() == object){
-			currentpoint = 0;
+			currentpoint = 1;
 			walkInversed = false;
 		}else{
-			currentpoint = p.getPath().size()-1;
+			currentpoint = p.getPath().size()-2;
 			walkInversed= true;
 		}
 		target = p.get(currentpoint);
 		currentpath = p;
 	}
+	private void walkNewRoute(WalkingPathArrayList walkingpaths, DrawEngine object){
+		WalkingPathArrayList connectedWalkingPaths = walkingpaths.getWalkingPadObject(object);
+		connectedWalkingPaths.removeType(object, SimulatorPane.Objects.ENTRANCE);
+		if(food > 25)
+			connectedWalkingPaths.removeType(object, SimulatorPane.Objects.SNACKBAR);
+		if(drink > 25)
+			connectedWalkingPaths.removeType(object, SimulatorPane.Objects.DRINK);
+		if(pis > 25)
+			connectedWalkingPaths.removeType(object, SimulatorPane.Objects.RESTROOM);
+		if(!connectedWalkingPaths.isEmpty()){
+			walkRoute(connectedWalkingPaths.get((int)(Math.random()*connectedWalkingPaths.size())), object);
+		}
+	}
+
+	public double getFood() {
+		return food;
+	}
+
+	public void setFood(double food) {
+		if(food >= 0 && food <= 100)
+			this.food = food;
+	}
+
+	public double getDrink() {
+		return drink;
+	}
+
+	public void setDrink(double drink) {
+		if(drink >= 0 && drink <= 100)
+			this.drink = drink;
+	}
+
+	public double getPis() {
+		return pis;
+	}
+
+	public void setPis(double pis) {
+		if(pis >= 0 && pis <= 100)
+			this.pis = pis;
+	}
+	
 }
 

+ 20 - 5
src/gui/simulator/WalkingPathArrayList.java

@@ -1,12 +1,12 @@
 package gui.simulator;
 
 import java.util.ArrayList;
+import java.util.Iterator;
 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>();
+	public WalkingPathArrayList getWalkingPadType(SimulatorPane.Objects type){
+		WalkingPathArrayList returnlist = new WalkingPathArrayList();
 		for(WalkingPath wp:this){
 			if(wp.getObject1().type == type || wp.getObject2().type == type){
 				returnlist.add(wp);
@@ -14,8 +14,8 @@ public class WalkingPathArrayList extends ArrayList<WalkingPath>{
 		}
 		return returnlist;
 	}
-	public List<WalkingPath> getWalkingPadObject(DrawEngine object){
-		List<WalkingPath> returnlist = new ArrayList<WalkingPath>();
+	public WalkingPathArrayList getWalkingPadObject(DrawEngine object){
+		WalkingPathArrayList returnlist = new WalkingPathArrayList();
 		for(WalkingPath wp:this){
 			if(wp.getObject1() == object|| wp.getObject2() == object){
 				returnlist.add(wp);
@@ -23,4 +23,19 @@ public class WalkingPathArrayList extends ArrayList<WalkingPath>{
 		}
 		return returnlist;
 	}
+	public void removeType(DrawEngine object, SimulatorPane.Objects type){
+		Iterator<WalkingPath> i = this.iterator();
+		while(i.hasNext()){
+			WalkingPath path = i.next();
+			if(path.getObject1() == object){
+				if(path.getObject2().type == type){
+					i.remove();
+				}
+			}else{
+				if(path.getObject1().type == type){
+					i.remove();
+				}
+			}
+		}
+	}
 }

+ 2 - 2
src/gui/simulator/facilities/RestRoom.java

@@ -15,11 +15,11 @@ public class RestRoom extends DrawEngine implements Serializable {
 
     //TODO change visibility
     public RestRoom(int x, int y, Terrain terrain) {
-        super(images, x, y, 1, 0, SimulatorPane.Objects.RESTROOM, terrain, new Rectangle2D.Double(-10, -10, 120, 120), true);
+        super(images, x, y, 1, 0, SimulatorPane.Objects.RESTROOM, terrain, new Rectangle2D.Double(-30, -30, 150, 150), true);
     }
 
     public RestRoom(int x, int y, double scale, double distance, Terrain terrain) {
-        super(images, x, y, scale, distance, SimulatorPane.Objects.RESTROOM, terrain, new Rectangle2D.Double(-10, -10, 120, 120), true);
+        super(images, x, y, scale, distance, SimulatorPane.Objects.RESTROOM, terrain, new Rectangle2D.Double(-30, -30, 150, 150), true);
     }
     
     public String getFacilityName(){

+ 2 - 2
src/gui/simulator/facilities/SnackBar.java

@@ -15,11 +15,11 @@ public class SnackBar extends DrawEngine implements Serializable{
 
     //TODO change visibility
     public SnackBar(int x, int y, Terrain terrain) {
-        super(images, x, y, 1, 0, SimulatorPane.Objects.SNACKBAR, terrain, new Rectangle2D.Double(-10, -10, 420, 420), true);
+        super(images, x, y, 1, 0, SimulatorPane.Objects.SNACKBAR, terrain, new Rectangle2D.Double(-30, -30, 450, 450), true);
     }
 
     public SnackBar(int x, int y, double scale, double distance, Terrain terrain) {
-        super(images, x, y, scale, distance, SimulatorPane.Objects.SNACKBAR, terrain, new Rectangle2D.Double(-10, -10, 420, 420), true);
+        super(images, x, y, scale, distance, SimulatorPane.Objects.SNACKBAR, terrain, new Rectangle2D.Double(-30, -30, 450, 450), true);
     }
     
     public String getFacilityName(){