10 Commits
Author SHA1 Message Date
Yorick 5d0ae9ca98 final commit 2015-04-09 09:29:13 +02:00
Yorick 719d58aae9 done 2015-04-09 01:55:12 +02:00
Yorick 4897a9440b ohgodwhy 2015-04-09 01:30:38 +02:00
Yorick 2e947589be merge 2015-04-09 00:56:42 +02:00
Remco a6f32b5739 Editing disabled while running simulator 2015-04-09 00:51:18 +02:00
Yorick 6178311c4b Merge remote-tracking branch 'origin/kenneth' into develop 2015-04-09 00:35:30 +02:00
Yorick 920fd8117e KUT 2015-04-09 00:33:18 +02:00
guusvdongen 911714f9b5 Update Visitor.java 2015-04-08 21:15:45 +02:00
unknown 254167ba15 print out line op 2015-04-08 17:40:22 +02:00
unknown b8a7d9c02d change 2015-04-08 17:24:29 +02:00
4 changed files with 71 additions and 26 deletions
+2
View File
@@ -52,6 +52,7 @@ public class ControlPanel extends JPanel
public void actionPerformed(ActionEvent e)
{
p.getT().start();
p.setPlay(true);
runningLabel.setText("Simulation Started");
}
});
@@ -64,6 +65,7 @@ public class ControlPanel extends JPanel
public void actionPerformed(ActionEvent e)
{
p.getT().stop();
p.setPlay(false);
runningLabel.setText("Simulation Stopped");
}
});
+12 -1
View File
@@ -63,6 +63,7 @@ public class Panel extends JPanel implements ActionListener
private Path currentPath;
private static int width = 1920;
private static int height = 1080;
private boolean play = false;
Point2D cameraPoint = new Point2D.Double(getWidth() / 2, getHeight() / 2);
float cameraScale = 1;
@@ -148,7 +149,7 @@ public class Panel extends JPanel implements ActionListener
addMouseWheelListener(new MouseWheel(this));
addFocusListener(new WindowFocusListener(this));
t = new Timer(1000 / 50, this);
t = new Timer(1000/60, this);
}
public int getPanelInfoLength()
@@ -667,6 +668,16 @@ public class Panel extends JPanel implements ActionListener
this.t = t;
}
public void setPlay(boolean play)
{
this.play = play;
}
public boolean getPlay()
{
return play;
}
public void newWorld(int width, int height, int terrainIndex)
{
this.width = width;
+46 -17
View File
@@ -11,6 +11,7 @@ import java.util.ArrayList;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import Agenda.Agenda;
import Agenda.Event;
@@ -86,11 +87,13 @@ public class Visitor
public void update(ArrayList<DrawObject> objects, int currentTime, ArrayList<Visitor> visitors, ArrayList<Path> paths, Panel panel)
{
DrawObject target = getEntrance();
for (Action a : actions)
{
if (currentTime >= a.getStartTime() && currentTime < a.getStoptime())
{
this.finalTarget = a.getWaypoint().getSelf();
}
}
@@ -100,9 +103,7 @@ public class Visitor
public void move(DrawObject tar, Panel panel)
{
System.out.println("CurrentTarget: " + target);
System.out.println("FinalTarget: " + finalTarget);
Point2D targetPoint = panel.getWaypoint(target).getAccuratePoint();
Point2D targetPoint = panel.getWaypoint(target).getPosition();
double newRot = Math.atan2(targetPoint.getY() - position.getY(), targetPoint.getX() - position.getX());
@@ -139,6 +140,7 @@ public class Visitor
if (hasCollisionDO(object))
{
possible = false;
}
}
@@ -147,20 +149,25 @@ public class Visitor
position = oldPosition;
rotation += 0.2;
}
if (checkIfOnWaypoint(panel))
{
HashMap<Integer, int[]> options = new HashMap<Integer, int[]>();
for (Waypoint w : panel.getWaypoints())
{
options.put(w.getSelf(), w.getOptions());
}
for (Map.Entry<Integer, int[]> e : options.entrySet())
{
for (int i : e.getValue())
{
if (finalTarget != target)
{
for (Map.Entry<Integer, int[]> e : options.entrySet())
{
// System.out.println("KEY: " + e.getKey());
for (int i : e.getValue())
{
// System.out.println("VAL: " + i);
if (finalTarget == i && e.getKey() == target)
{
target = finalTarget;
@@ -172,6 +179,7 @@ public class Visitor
break;
}
}
}
}
}
@@ -245,6 +253,7 @@ public class Visitor
if (hasCollision(object) && object != this)
{
possible = false;
}
}
@@ -368,7 +377,7 @@ public class Visitor
while (startTime < stopTime)
{
int random = (int) Math.floor(Math.random() * 51);
if (random < 40)
if (random < 30)
{
Point2D position = null;
DrawObject targetStage = null;
@@ -380,11 +389,23 @@ public class Visitor
posEvents.add(e);
}
}
int totalPopularity = 0;
for (Event ev : posEvents)
{
totalPopularity += ev.getExpectedPopularity();
}
if (posEvents.size() != 0)
Random rand = new Random();
int n = rand.nextInt(totalPopularity + 1);
int currentPop = 0;
if (posEvents != null)
{
for (Event evs : posEvents)
{
int before = currentPop;
currentPop = currentPop + evs.getExpectedPopularity();
if (before < n && currentPop >= n)
{
int r = (int) Math.floor(Math.random() * posEvents.size());
Event evs = posEvents.get(r);
for (DrawObject d : objects)
{
if (d.getFileName().equals("stage"))
@@ -396,19 +417,22 @@ public class Visitor
targetStage = d;
}
}
}
}
}
}
int randomtime = (int) (40 + (Math.random() * (60 - 40)));
if (position != null)
{
Waypoint w = getClosestWaypoint(position);
Waypoint w = getClosedWaypoint(position);
actions.add(new Action(position, startTime, randomtime, targetStage, w));
}
startTime = startTime + randomtime;
}
else if (random >= 40 && random < 45)
else if (random >= 30 && random < 40)
{
Point2D position = null;
DrawObject targetStage = null;
@@ -426,15 +450,16 @@ public class Visitor
int r = (int) Math.floor(Math.random() * foodPlaces.size());
position = foodPlaces.get(r).getPosition();
targetStage = foodPlaces.get(r);
Waypoint w = getClosestWaypoint(position);
Waypoint w = getClosedWaypoint(position);
actions.add(new Action(position, startTime, 35, targetStage, w));
startTime = startTime + 20;
}
startTime = startTime + 35;
}
else if (random > 45)
else if (random >= 40)
{
Point2D position = null;
DrawObject targetStage = null;
ArrayList<DrawObject> toilets = new ArrayList<DrawObject>();
@@ -445,13 +470,15 @@ public class Visitor
toilets.add(d);
}
}
if (toilets.size() != 0)
{
int r = (int) Math.floor(Math.random() * toilets.size());
position = toilets.get(r).getPosition();
targetStage = toilets.get(r);
Waypoint w = getClosestWaypoint(position);
Waypoint w = getClosedWaypoint(position);
actions.add(new Action(position, startTime, 35, targetStage, w));
startTime = startTime + 20;
}
startTime = startTime + 35;
@@ -460,7 +487,7 @@ public class Visitor
}
}
public Waypoint getClosestWaypoint(Point2D point)
public Waypoint getClosedWaypoint(Point2D point)
{
Waypoint waypoint = null;
int distance = 10000;
@@ -468,6 +495,7 @@ public class Visitor
{
if (w.getPosition().distance(point) < distance)
{
waypoint = w;
distance = (int) w.getPosition().distance(point);
}
@@ -477,6 +505,7 @@ public class Visitor
public boolean hasCollisionDO(DrawObject object)
{
Image image = Images.getImage(filename);
Image image2 = Images.getImage(object.getFileName());
Rectangle recta = new Rectangle((int) position.getX(), (int) position.getY(), image.getWidth(null), image.getHeight(null));
+4 -1
View File
@@ -34,6 +34,8 @@ public class Mouse extends MouseAdapter
panel.setLastClickPosition(clickPoint);
panel.setLastMousePosition(e.getPoint());
if(!panel.getPlay())
{
if (!panel.getClickedOption().equals("Path"))
{
if (e.getY() < 150)
@@ -150,13 +152,14 @@ public class Mouse extends MouseAdapter
panel.getCurrentPath().addPoint(new Point2D.Double(clickPoint.getX(), clickPoint.getY()));
}
}
panel.repaint();
}
public void mouseReleased(MouseEvent e)
{
if (panel.getDragObject() != null)
if (panel.getDragObject() != null && !panel.getPlay())
{
if (panel.getDragObject().getRectangleColor() != Color.RED)
{