فهرست منبع

Added type for drawengines, rounded walkingpaths, visitors can walk over paths

jancoow 10 سال پیش
والد
کامیت
04b725f677

+ 2 - 2
src/gui/simulator/AccessPoint.java

@@ -7,12 +7,12 @@ public class AccessPoint extends DrawEngine {
 	private Terrain terrain;
 
     public AccessPoint(Terrain terrain, int x, int y) {
-        super(imageLocation, x, y, 1, 0);
+        super(imageLocation, x, y, 1, 0, SimulatorPane.Objects.ENTRANCE);
         this.terrain = terrain;
     }
 
     public AccessPoint(Terrain terrain, int x, int y, double scale, double distance) {
-        super(imageLocation, x, y, scale, distance);
+        super(imageLocation, x, y, scale, distance, SimulatorPane.Objects.ENTRANCE);
         this.terrain = terrain;
     }
     

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

@@ -17,13 +17,15 @@ public abstract class DrawEngine {
     private Image image;
     private double x, y, rotation, scale;
     private double distanceToOtherObjects;
+    public SimulatorPane.Objects type;
 
-    public DrawEngine(String image, int x, int y, double scale, double distanceToOtherObjects){
+    public DrawEngine(String image, int x, int y, double scale, double distanceToOtherObjects, SimulatorPane.Objects objecttype){
         try{
             this.image = ImageIO.read(getClass().getResource(image));
         }catch(IOException ex){
             ex.printStackTrace();
         }
+        this.type = objecttype;
         this.x = x;
         this.y = y;
         this.scale = scale;

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

@@ -8,7 +8,7 @@ public class ExitPoint extends DrawEngine {
 
 
     public ExitPoint(Terrain terrain, int x, int y, double scale, double distance) {
-        super(imageLocation, x, y, scale, distance);
+        super(imageLocation, x, y, scale, distance, SimulatorPane.Objects.EXIT);
         this.terrain = terrain;
     }
     

+ 4 - 2
src/gui/simulator/SimulatorPane.java

@@ -20,7 +20,9 @@ public class SimulatorPane extends JPanel{
 	
 	//terrain type enums
 	public enum Terrains{BEACH, GRASS, URBAN, UNDEFINED};
-
+	//object type enums
+	public enum Objects{STAGE, DRINK, FOOD, RESTROOM, SUNGLAS, WAYPOINT, ENTRANCE, EXIT};
+	
 	public SimulatorPane(Agenda agenda, int length, int width, Terrains terrains){
         super.setLayout(new BorderLayout());
 		this.agenda = agenda;
@@ -35,7 +37,7 @@ public class SimulatorPane extends JPanel{
 				terrain.repaint();	
 			}
 		});
-        framestimer = new Timer(1000/10, new ActionListener() {
+        framestimer = new Timer(1000/100, new ActionListener() {
 			@Override
 			public void actionPerformed(ActionEvent arg0) {
 				terrain.calculate();

+ 17 - 14
src/gui/simulator/Terrain.java

@@ -62,9 +62,8 @@ public class Terrain extends JPanel {
     	this.terrain = terrain;
     	visitors = new ArrayList<Visitor>();
     	paths = new ArrayList<WalkingPath>();
-    	for(int i=0; i< 40; i++){
-        	visitors.add(new Visitor(new Point(100+(i*15),100)));	
-    	}
+
+
 
     	//initialize sidebar
     	sidebar = new Sidebar(sideBarWidth, 3000, this);
@@ -143,6 +142,10 @@ public class Terrain extends JPanel {
 	                    		currentpath.addPoint(new Point((int)drawObject.getX(), (int)drawObject.getY()));
 	                    		currentpath.setObject2(drawObject);
 	                    		paths.add(currentpath);
+	                        	for(int i=0; i< 200; i++){
+	                            	visitors.add(new Visitor(new Point(100+(i*15),100)));	
+	                            	visitors.get(i).walkRoute(paths.get(0));
+	                        	}
 	                    		pathgenerate = 0;
 	                    		return; 
 	                    	}else{
@@ -294,7 +297,15 @@ public class Terrain extends JPanel {
 				g2.drawLine(0, i*10, getFestivalWidth(), i*10);
 			};
 		}
-		
+		if(pathgenerate > 1){
+			g2.setStroke(new BasicStroke(10));
+			currentpath.paint(g2);
+			g2.drawLine((int)currentpath.get(currentpath.getPath().size()-1).getX(),(int)currentpath.get(currentpath.getPath().size()-1).getY(), (int)lastMovedMousePosition.getX(), (int)lastMovedMousePosition.getY());
+		}else{
+			for(WalkingPath path:paths){
+				path.paint(g2);
+			}
+		}
     	for(Visitor v:visitors){
     		v.paint(g2);
     	}
@@ -305,15 +316,7 @@ public class Terrain extends JPanel {
             }
         }
 		
-		if(pathgenerate > 1){
-			g2.setStroke(new BasicStroke(10));
-			currentpath.paint(g2);
-			g2.drawLine((int)currentpath.get(currentpath.getPath().size()-1).getX(),(int)currentpath.get(currentpath.getPath().size()-1).getY(), (int)lastMovedMousePosition.getX(), (int)lastMovedMousePosition.getY());
-		}else{
-			for(WalkingPath path:paths){
-				path.paint(g2);
-			}
-		}
+
 		
 		//draw collide boxes 
         if(this.selectedObject != null){
@@ -372,7 +375,7 @@ public class Terrain extends JPanel {
 	}
     public void calculate(){
     	for(Visitor v:visitors){
-    		v.update(visitors);
+    		v.update(visitors, entities);
     	}
     	for(WalkingPath p:paths){
     		p.reCalculate();

+ 30 - 9
src/gui/simulator/Visitor.java

@@ -2,9 +2,10 @@ package gui.simulator;
 
 import java.awt.Graphics2D;
 import java.awt.Image;
+import java.awt.Point;
 import java.awt.geom.AffineTransform;
 import java.awt.geom.Point2D;
-import java.util.ArrayList;
+import java.util.List;
 
 import javax.swing.ImageIcon;
 
@@ -14,11 +15,11 @@ public class Visitor {
 	double rotation;
 	double speed;
 	Point2D target;
+	WalkingPath currentpath;
+	int currentpoint;
 	
 	Image image = new ImageIcon("res/visitor.png").getImage();
 	
-
-
 	public Visitor(Point2D positie) {
 		this.positie = positie;
 		this.rotation = 0;
@@ -26,7 +27,7 @@ public class Visitor {
 		this.target = new Point2D.Double(0, 0);
 	}
 
-	void update(ArrayList<Visitor> visitors)
+	void update(List<Visitor> visitors, List<DrawEngine> buildings)
 	{
 		
 		Point2D difference = new Point2D.Double(
@@ -48,8 +49,6 @@ public class Visitor {
 		else if(rotDifference > 0)
 			rotation -= 0.1;
 		
-		
-		
 		Point2D oldPositie = positie;
 		
 		positie = new Point2D.Double(
@@ -58,12 +57,19 @@ public class Visitor {
 				);
 		
 
-		if(hasCollision(visitors))
+		if(hasCollision(visitors) || hasCollisionObject(buildings))
 		{
 			positie = oldPositie;
 			rotation += 0.2;
 		}
-		
+		if(currentpath != null){
+			if(hasCollision(currentpath.get(currentpoint))){
+				if(currentpoint < currentpath.getPath().size()-1){
+					currentpoint++;
+					target = currentpath.get(currentpoint);
+				}
+			}
+		}
 		
 	}
 	
@@ -77,7 +83,7 @@ public class Visitor {
 		
 	}
 
-	public boolean hasCollision(ArrayList<Visitor> visitors) {
+	public boolean hasCollision(List<Visitor> visitors) {
 		for(Visitor b : visitors)
 		{
 			if(b == this)
@@ -87,5 +93,20 @@ public class Visitor {
 		}
 		return false;
 	}
+	public boolean hasCollisionObject(List<DrawEngine> objects){
+		for(DrawEngine o:objects){
+			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);
+	}
 }
 

+ 5 - 3
src/gui/simulator/WalkingPath.java

@@ -50,11 +50,13 @@ public class WalkingPath {
 		this.object2 = object2;
 	}
 	public void reCalculate(){
-		path.get(0).setLocation(new Point((int)object1.getX(), (int)object1.getY()));
-		path.get(path.size()-1).setLocation(new Point((int)object2.getX(), (int)object2.getY()));
+		if(object1 != null && object2 != null){
+			path.get(0).setLocation(new Point((int)object1.getX(), (int)object1.getY()));
+			path.get(path.size()-1).setLocation(new Point((int)object2.getX(), (int)object2.getY()));
+		}
 	}
 	public void paint(Graphics2D g2){
-		g2.setStroke(new BasicStroke(10));
+		g2.setStroke(new BasicStroke(20,BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
 		for(int i = 1; i < getPath().size(); i++){
 			g2.setPaint(new TexturePaint(texture, new Rectangle(0,0,100,100)));
 			g2.drawLine((int)get(i-1).getX(),(int)get(i-1).getY(), (int)get(i).getX(),(int)get(i).getY());

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

@@ -1,6 +1,7 @@
 package gui.simulator.facilities;
 
 import gui.simulator.DrawEngine;
+import gui.simulator.SimulatorPane;
 
 public class RestRoom extends DrawEngine {
 
@@ -8,11 +9,11 @@ public class RestRoom extends DrawEngine {
 	private static String facilityName = "Plee";
 
     public RestRoom(int x, int y) {
-        super(imageLocation, x, y, 1, 0);
+        super(imageLocation, x, y, 1, 0, SimulatorPane.Objects.RESTROOM);
     }
 
     public RestRoom(int x, int y, double scale, double distance) {
-        super(imageLocation, x, y, scale, distance);
+        super(imageLocation, x, y, scale, distance, SimulatorPane.Objects.RESTROOM);
     }
     
     public String getFacilityName(){

+ 3 - 2
src/gui/simulator/facilities/Stage.java

@@ -1,6 +1,7 @@
 package gui.simulator.facilities;
 
 import gui.simulator.DrawEngine;
+import gui.simulator.SimulatorPane;
 
 public class Stage extends DrawEngine {
 
@@ -8,11 +9,11 @@ public class Stage extends DrawEngine {
 	private static String facilityName = "Stage";
 
     public Stage(int x, int y) {
-        super(imageLocation, x, y, 1, 0);
+        super(imageLocation, x, y, 1, 0,SimulatorPane.Objects.STAGE);
     }
 
     public Stage(int x, int y, double scale, double distance) {
-        super(imageLocation, x, y, scale, distance);
+        super(imageLocation, x, y, scale, distance,SimulatorPane.Objects.STAGE);
     }
     
     public String getFacilityName(){