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