|
|
@@ -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);
|
|
|
+ }
|
|
|
}
|
|
|
|