|
@@ -2,43 +2,34 @@ package gui.simulator;
|
|
|
|
|
|
|
|
import gui.simulator.facilities.ImageType;
|
|
import gui.simulator.facilities.ImageType;
|
|
|
import gui.simulator.facilities.SimulatorStage;
|
|
import gui.simulator.facilities.SimulatorStage;
|
|
|
|
|
+
|
|
|
import java.awt.Graphics2D;
|
|
import java.awt.Graphics2D;
|
|
|
import java.awt.geom.AffineTransform;
|
|
import java.awt.geom.AffineTransform;
|
|
|
import java.awt.geom.Point2D;
|
|
import java.awt.geom.Point2D;
|
|
|
-import java.io.Serializable;
|
|
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
|
|
|
-public class Visitor implements Serializable {
|
|
|
|
|
|
|
+public class Visitor {
|
|
|
private Point2D positie, target;
|
|
private Point2D positie, target;
|
|
|
private double rotation, speed;
|
|
private double rotation, speed;
|
|
|
private WalkingPath currentpath;
|
|
private WalkingPath currentpath;
|
|
|
private int currentpoint, collisioncount;
|
|
private int currentpoint, collisioncount;
|
|
|
private boolean walkInversed;
|
|
private boolean walkInversed;
|
|
|
- private double food, drink, pis;
|
|
|
|
|
- ImageType image = ImageType.Visitor;
|
|
|
|
|
|
|
+ private double food, drink, pee;
|
|
|
|
|
|
|
|
public Visitor(Point2D positie, Point2D starttarget) {
|
|
public Visitor(Point2D positie, Point2D starttarget) {
|
|
|
this.positie = positie;
|
|
this.positie = positie;
|
|
|
this.rotation = 0;
|
|
this.rotation = 0;
|
|
|
- double number = Math.random()*2;
|
|
|
|
|
- if(number < 1){
|
|
|
|
|
- this.speed = 1;
|
|
|
|
|
- } else {
|
|
|
|
|
- this.speed = number;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ this.speed = 1 + Math.random();
|
|
|
this.target = starttarget;
|
|
this.target = starttarget;
|
|
|
this.food = (int)(Math.random()*100);
|
|
this.food = (int)(Math.random()*100);
|
|
|
this.drink = (int)(Math.random()*100);
|
|
this.drink = (int)(Math.random()*100);
|
|
|
- this.pis = (int)(Math.random()*100);
|
|
|
|
|
|
|
+ this.pee = (int)(Math.random()*100);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void update(List<Visitor> visitors, List<DrawEngine> buildings, WalkingPathArrayList walkingpaths)
|
|
void update(List<Visitor> visitors, List<DrawEngine> buildings, WalkingPathArrayList walkingpaths)
|
|
|
{
|
|
{
|
|
|
- Point2D difference = new Point2D.Double(
|
|
|
|
|
- target.getX() - positie.getX(),
|
|
|
|
|
- target.getY() - positie.getY()
|
|
|
|
|
- );
|
|
|
|
|
|
|
+ Point2D difference = new Point2D.Double( target.getX() - positie.getX(), target.getY() - positie.getY() );
|
|
|
rotation %= 360;
|
|
rotation %= 360;
|
|
|
double newRotation = Math.atan2(difference.getY(), difference.getX());
|
|
double newRotation = Math.atan2(difference.getY(), difference.getX());
|
|
|
double rotDifference = rotation - newRotation;
|
|
double rotDifference = rotation - newRotation;
|
|
@@ -46,24 +37,20 @@ public class Visitor implements Serializable {
|
|
|
rotDifference -= 2 * Math.PI;
|
|
rotDifference -= 2 * Math.PI;
|
|
|
while(rotDifference < -Math.PI)
|
|
while(rotDifference < -Math.PI)
|
|
|
rotDifference += 2 * Math.PI;
|
|
rotDifference += 2 * Math.PI;
|
|
|
-
|
|
|
|
|
if(Math.abs(rotDifference) < 0.1)
|
|
if(Math.abs(rotDifference) < 0.1)
|
|
|
rotation = newRotation;
|
|
rotation = newRotation;
|
|
|
else if(rotDifference < 0)
|
|
else if(rotDifference < 0)
|
|
|
rotation += 0.1;
|
|
rotation += 0.1;
|
|
|
else if(rotDifference > 0)
|
|
else if(rotDifference > 0)
|
|
|
rotation -= 0.1;
|
|
rotation -= 0.1;
|
|
|
|
|
+
|
|
|
|
|
+ Point2D oldPositie = positie;
|
|
|
|
|
+ positie = new Point2D.Double( positie.getX() + speed * Math.cos(rotation), positie.getY() + speed * Math.sin(rotation));
|
|
|
|
|
+ setFood(getFood()-Math.random()*0.05);
|
|
|
|
|
+ setDrink(getDrink()-Math.random()*0.05);
|
|
|
|
|
+ setPee(getPee()-Math.random()*0.05);
|
|
|
|
|
|
|
|
- Point2D oldPositie = positie;
|
|
|
|
|
-
|
|
|
|
|
- positie = new Point2D.Double(
|
|
|
|
|
- positie.getX() + speed * Math.cos(rotation),
|
|
|
|
|
- positie.getY() + speed * Math.sin(rotation)
|
|
|
|
|
- );
|
|
|
|
|
- DrawEngine object = collisionObject(buildings);
|
|
|
|
|
- this.food = (int)(Math.random()*100);
|
|
|
|
|
- this.drink = (int)(Math.random()*100);
|
|
|
|
|
- this.pis = (int)(Math.random()*100);
|
|
|
|
|
|
|
+ DrawEngine object = collisionObject(buildings);
|
|
|
if((hasCollision(visitors) && (collisioncount < 60 ) || hasCollisionObject(buildings) )) // collision with a ridged building or a visitor, rotate
|
|
if((hasCollision(visitors) && (collisioncount < 60 ) || hasCollisionObject(buildings) )) // collision with a ridged building or a visitor, rotate
|
|
|
{
|
|
{
|
|
|
positie = oldPositie;
|
|
positie = oldPositie;
|
|
@@ -72,31 +59,30 @@ public class Visitor implements Serializable {
|
|
|
if(currentpath != null){
|
|
if(currentpath != null){
|
|
|
if(object != null){
|
|
if(object != null){
|
|
|
if((currentpath.getObject1() == object && walkInversed) || (currentpath.getObject2() == object && !walkInversed)){ //end point reached, what to do?
|
|
if((currentpath.getObject1() == object && walkInversed) || (currentpath.getObject2() == object && !walkInversed)){ //end point reached, what to do?
|
|
|
- if(object.type == SimulatorPane.Objects.STAGE){
|
|
|
|
|
|
|
+ if(object.type == SimulatorPane.Objects.STAGE){ //stay at stage when a act is playing
|
|
|
setCollisionCount(0);
|
|
setCollisionCount(0);
|
|
|
if(((SimulatorStage) object).getPlayingact() == null){
|
|
if(((SimulatorStage) object).getPlayingact() == null){
|
|
|
walkNewRoute(walkingpaths, object);
|
|
walkNewRoute(walkingpaths, object);
|
|
|
}
|
|
}
|
|
|
- }else if(object.type == SimulatorPane.Objects.DRINK){
|
|
|
|
|
- drink += 50;
|
|
|
|
|
|
|
+ }else if(object.type == SimulatorPane.Objects.DRINK){ //buy a drink
|
|
|
|
|
+ setDrink(getDrink() + 50);
|
|
|
walkNewRoute(walkingpaths, object);
|
|
walkNewRoute(walkingpaths, object);
|
|
|
- }else if(object.type == SimulatorPane.Objects.SNACKBAR){
|
|
|
|
|
- food += 50;
|
|
|
|
|
|
|
+ }else if(object.type == SimulatorPane.Objects.SNACKBAR){ //buy some food
|
|
|
|
|
+ setFood(getFood() + 50);
|
|
|
walkNewRoute(walkingpaths, object);
|
|
walkNewRoute(walkingpaths, object);
|
|
|
- }else if(object.type == SimulatorPane.Objects.RESTROOM){
|
|
|
|
|
- pis = 100;
|
|
|
|
|
|
|
+ }else if(object.type == SimulatorPane.Objects.RESTROOM){ //toilet
|
|
|
|
|
+ setPee(100);
|
|
|
walkNewRoute(walkingpaths, object);
|
|
walkNewRoute(walkingpaths, object);
|
|
|
- }else if(object.type == SimulatorPane.Objects.WAYPOINT){
|
|
|
|
|
|
|
+ }else if(object.type == SimulatorPane.Objects.WAYPOINT){ //waypoint, choose a new route
|
|
|
walkNewRoute(walkingpaths, object);
|
|
walkNewRoute(walkingpaths, object);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
if(positie.distance(currentpath.get(currentpoint)) < 11){ //collision with a path-point
|
|
if(positie.distance(currentpath.get(currentpoint)) < 11){ //collision with a path-point
|
|
|
- if(walkInversed && currentpoint > 0){
|
|
|
|
|
|
|
+ if(walkInversed && currentpoint > 0)
|
|
|
currentpoint--;
|
|
currentpoint--;
|
|
|
- }else if(currentpoint < currentpath.getPath().size()-1){
|
|
|
|
|
|
|
+ else if(currentpoint < currentpath.getPath().size()-1)
|
|
|
currentpoint++;
|
|
currentpoint++;
|
|
|
- }
|
|
|
|
|
target = currentpath.get(currentpoint);
|
|
target = currentpath.get(currentpoint);
|
|
|
}
|
|
}
|
|
|
}else{ //entrance
|
|
}else{ //entrance
|
|
@@ -111,22 +97,20 @@ public class Visitor implements Serializable {
|
|
|
AffineTransform tx = new AffineTransform();
|
|
AffineTransform tx = new AffineTransform();
|
|
|
tx.translate(positie.getX()-8, positie.getY()-11);
|
|
tx.translate(positie.getX()-8, positie.getY()-11);
|
|
|
tx.rotate(rotation, 4, 6);
|
|
tx.rotate(rotation, 4, 6);
|
|
|
- g.drawImage(Images.getImage(image), tx ,null);
|
|
|
|
|
|
|
+ g.drawImage(Images.getImage(ImageType.Visitor), tx ,null);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
private boolean hasCollision(List<Visitor> visitors) { // check collision with other visitors
|
|
private boolean hasCollision(List<Visitor> visitors) { // check collision with other visitors
|
|
|
for(Visitor b : visitors)
|
|
for(Visitor b : visitors)
|
|
|
{
|
|
{
|
|
|
-
|
|
|
|
|
if(b != this && b.positie.distance(positie) < 11){
|
|
if(b != this && b.positie.distance(positie) < 11){
|
|
|
setCollisionCount(collisioncount + 1);
|
|
setCollisionCount(collisioncount + 1);
|
|
|
return true;
|
|
return true;
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
setCollisionCount(collisioncount - 5);
|
|
setCollisionCount(collisioncount - 5);
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
private boolean hasCollisionObject(List<DrawEngine> objects){ // check collision with rigid objects
|
|
private boolean hasCollisionObject(List<DrawEngine> objects){ // check collision with rigid objects
|
|
|
for(DrawEngine o:objects){
|
|
for(DrawEngine o:objects){
|
|
|
if(o.type != SimulatorPane.Objects.WAYPOINT && o.type != SimulatorPane.Objects.EXIT && o.type != SimulatorPane.Objects.ENTRANCE )
|
|
if(o.type != SimulatorPane.Objects.WAYPOINT && o.type != SimulatorPane.Objects.EXIT && o.type != SimulatorPane.Objects.ENTRANCE )
|
|
@@ -135,7 +119,7 @@ public class Visitor implements Serializable {
|
|
|
}
|
|
}
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
- private DrawEngine collisionObject(List<DrawEngine> objects){
|
|
|
|
|
|
|
+ private DrawEngine collisionObject(List<DrawEngine> objects){ //give the collision object
|
|
|
for(DrawEngine o:objects){
|
|
for(DrawEngine o:objects){
|
|
|
if (o.containsWalkArea(positie) || o.contains(positie) )
|
|
if (o.containsWalkArea(positie) || o.contains(positie) )
|
|
|
return o;
|
|
return o;
|
|
@@ -156,12 +140,9 @@ public class Visitor implements Serializable {
|
|
|
private void walkNewRoute(WalkingPathArrayList walkingpaths, DrawEngine object){
|
|
private void walkNewRoute(WalkingPathArrayList walkingpaths, DrawEngine object){
|
|
|
WalkingPathArrayList connectedWalkingPaths = walkingpaths.getWalkingPadObject(object);
|
|
WalkingPathArrayList connectedWalkingPaths = walkingpaths.getWalkingPadObject(object);
|
|
|
connectedWalkingPaths.removeType(object, SimulatorPane.Objects.ENTRANCE);
|
|
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(food > 25) connectedWalkingPaths.removeType(object, SimulatorPane.Objects.SNACKBAR);
|
|
|
|
|
+ if(drink > 25) connectedWalkingPaths.removeType(object, SimulatorPane.Objects.DRINK);
|
|
|
|
|
+ if(pee > 25) connectedWalkingPaths.removeType(object, SimulatorPane.Objects.RESTROOM);
|
|
|
if(!connectedWalkingPaths.isEmpty()){
|
|
if(!connectedWalkingPaths.isEmpty()){
|
|
|
walkRoute(connectedWalkingPaths.get((int)(Math.random()*connectedWalkingPaths.size())), object);
|
|
walkRoute(connectedWalkingPaths.get((int)(Math.random()*connectedWalkingPaths.size())), object);
|
|
|
}
|
|
}
|
|
@@ -170,34 +151,27 @@ public class Visitor implements Serializable {
|
|
|
public double getFood() {
|
|
public double getFood() {
|
|
|
return food;
|
|
return food;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
public void setFood(double food) {
|
|
public void setFood(double food) {
|
|
|
if(food >= 0 && food <= 100)
|
|
if(food >= 0 && food <= 100)
|
|
|
this.food = food;
|
|
this.food = food;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
public double getDrink() {
|
|
public double getDrink() {
|
|
|
return drink;
|
|
return drink;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
public void setDrink(double drink) {
|
|
public void setDrink(double drink) {
|
|
|
if(drink >= 0 && drink <= 100)
|
|
if(drink >= 0 && drink <= 100)
|
|
|
this.drink = drink;
|
|
this.drink = drink;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- public double getPis() {
|
|
|
|
|
- return pis;
|
|
|
|
|
|
|
+ public double getPee() {
|
|
|
|
|
+ return pee;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- public void setPis(double pis) {
|
|
|
|
|
- if(pis >= 0 && pis <= 100)
|
|
|
|
|
- this.pis = pis;
|
|
|
|
|
|
|
+ public void setPee(double pee) {
|
|
|
|
|
+ if(pee >= 0 && pee <= 100)
|
|
|
|
|
+ this.pee = pee;
|
|
|
}
|
|
}
|
|
|
private void setCollisionCount(int c){
|
|
private void setCollisionCount(int c){
|
|
|
if(c >= 0 && c < 200){
|
|
if(c >= 0 && c < 200){
|
|
|
collisioncount = c;
|
|
collisioncount = c;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
|
|
+}
|