Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5d0ae9ca98 | ||
|
|
719d58aae9 | ||
|
|
4897a9440b | ||
|
|
2e947589be | ||
|
|
a6f32b5739 | ||
|
|
6178311c4b | ||
|
|
920fd8117e | ||
|
|
911714f9b5 | ||
|
|
254167ba15 | ||
|
|
b8a7d9c02d |
@@ -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
@@ -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;
|
||||
|
||||
+52
-23
@@ -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())
|
||||
if (finalTarget != target)
|
||||
{
|
||||
for (int i : e.getValue())
|
||||
for (Map.Entry<Integer, int[]> e : options.entrySet())
|
||||
{
|
||||
if (finalTarget != target)
|
||||
// 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,20 +389,35 @@ public class Visitor
|
||||
posEvents.add(e);
|
||||
}
|
||||
}
|
||||
|
||||
if (posEvents.size() != 0)
|
||||
int totalPopularity = 0;
|
||||
for (Event ev : posEvents)
|
||||
{
|
||||
int r = (int) Math.floor(Math.random() * posEvents.size());
|
||||
Event evs = posEvents.get(r);
|
||||
for (DrawObject d : objects)
|
||||
totalPopularity += ev.getExpectedPopularity();
|
||||
}
|
||||
|
||||
Random rand = new Random();
|
||||
int n = rand.nextInt(totalPopularity + 1);
|
||||
int currentPop = 0;
|
||||
if (posEvents != null)
|
||||
{
|
||||
for (Event evs : posEvents)
|
||||
{
|
||||
if (d.getFileName().equals("stage"))
|
||||
int before = currentPop;
|
||||
currentPop = currentPop + evs.getExpectedPopularity();
|
||||
if (before < n && currentPop >= n)
|
||||
{
|
||||
Stage s = (Stage) d;
|
||||
if (s.getStage().getName().equals(evs.getStage().getName()))
|
||||
for (DrawObject d : objects)
|
||||
{
|
||||
position = s.getPosition();
|
||||
targetStage = d;
|
||||
if (d.getFileName().equals("stage"))
|
||||
{
|
||||
Stage s = (Stage) d;
|
||||
if (s.getStage().getName().equals(evs.getStage().getName()))
|
||||
{
|
||||
position = s.getPosition();
|
||||
targetStage = d;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -402,13 +426,13 @@ public class Visitor
|
||||
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));
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user