From ad62094ee74ebe0cd26860b48b520e9e02eab20f Mon Sep 17 00:00:00 2001 From: Yorick Date: Wed, 8 Apr 2015 12:42:12 +0200 Subject: [PATCH] Working --- Applicatie/Action.java | 11 ++++++++++- Applicatie/Panel.java | 20 +++---------------- Applicatie/Visitor.java | 42 +++++++++++++++++++++++++++++----------- Applicatie/Waypoint.java | 1 + Objects/Path.java | 9 +++++++++ 5 files changed, 54 insertions(+), 29 deletions(-) diff --git a/Applicatie/Action.java b/Applicatie/Action.java index 089755a..a2e31a3 100644 --- a/Applicatie/Action.java +++ b/Applicatie/Action.java @@ -2,24 +2,33 @@ package Applicatie; import java.awt.geom.Point2D; +import Objects.DrawObject; + public class Action { private Point2D position; private int starttime; private int duration; + private DrawObject target; - public Action(Point2D position, int starttime, int duration) + public Action(Point2D position, int starttime, int duration, DrawObject tar) { this.position = position; this.starttime = starttime; this.duration = duration; + this.target = tar; } public Point2D getPosition() { return position; } + + public DrawObject getTargetObject() + { + return target; + } public int getStartTime() { diff --git a/Applicatie/Panel.java b/Applicatie/Panel.java index 2f606c0..9eb9885 100644 --- a/Applicatie/Panel.java +++ b/Applicatie/Panel.java @@ -23,6 +23,7 @@ import java.util.GregorianCalendar; import java.util.Iterator; import javax.imageio.ImageIO; +import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.Timer; @@ -169,7 +170,7 @@ public class Panel extends JPanel implements ActionListener return new Wall(null); case 4: return new Food(null); - case 6: + case 5: return new Waypoint(null); default: return null; @@ -191,21 +192,6 @@ public class Panel extends JPanel implements ActionListener return waypoints; } - public int getNextTarget() - { - int last = 0; - for (Waypoint w : waypoints) - { - System.out.println(waypoints); - if (w.getSelf() > last) - { - last = w.getSelf(); - } - } - System.out.println(last); - return last; - } - public void addVisitors() { visitors.add(new Visitor("visitor", new Point(100, 300), agenda, objects)); @@ -573,7 +559,7 @@ public class Panel extends JPanel implements ActionListener { return height; } - + @Override public void actionPerformed(ActionEvent e) { diff --git a/Applicatie/Visitor.java b/Applicatie/Visitor.java index c9b1fd8..ed635ae 100644 --- a/Applicatie/Visitor.java +++ b/Applicatie/Visitor.java @@ -2,7 +2,6 @@ package Applicatie; import java.awt.Graphics2D; import java.awt.Image; -import java.awt.Point; import java.awt.Rectangle; import java.awt.Shape; import java.awt.geom.AffineTransform; @@ -14,6 +13,7 @@ import java.util.Map; import Agenda.Agenda; import Agenda.Event; import Objects.DrawObject; +import Objects.Entrance; import Objects.Path; public class Visitor @@ -27,7 +27,7 @@ public class Visitor ArrayList actions; Agenda agenda; ArrayList objects; - char target; + int target; public Visitor(String filename, Point2D position, Agenda agenda, ArrayList objects) { @@ -40,7 +40,8 @@ public class Visitor this.agenda = agenda; this.objects = objects; fillActions(); - target = 'z'; + System.out.println(actions.size()); + target = 0; } public void draw(Graphics2D g2) @@ -60,24 +61,36 @@ public class Visitor return tx; } + public DrawObject getEntrance() + { + for(DrawObject o : objects) + { + if(o instanceof Entrance) + { + return o; + } + } + return null; + } + public void update(ArrayList objects, int currentTime, ArrayList visitors, ArrayList paths) { - Point2D target = new Point(500, 500); + DrawObject target = getEntrance(); for (Action a : actions) { if (currentTime >= a.getStartTime() && currentTime < a.getStoptime()) { - target = a.getPosition(); + target = a.getTargetObject(); } } - + moveToTarget(target, objects, visitors, paths); } - public void moveToTarget(Point2D target, ArrayList objects, ArrayList visitors, ArrayList paths) + public void moveToTarget(DrawObject target, ArrayList objects, ArrayList visitors, ArrayList paths) { - Point2D tar = target; + Point2D tar = target.getPosition(); boolean hasPathBelow = false; for (Path p : paths) { @@ -204,6 +217,9 @@ public class Visitor int dify = (int) (target2.getY() - position.getY()); int distance = (int) Math.sqrt((difx * difx) + (dify * dify)); + System.out.println(rotation); + System.out.println(newRot); + System.out.println("--------------"); if (rotation > newRot && distance > 10) { rotation -= 0.15; @@ -258,6 +274,7 @@ public class Visitor if (random < 30) { Point2D position = null; + DrawObject targetStage = null; for (Event e : agenda.getEvents()) { if (convertMinutesToHours(startTime) > e.getStart() && convertMinutesToHours(startTime) < e.getStop()) @@ -267,6 +284,7 @@ public class Visitor if (d.getFileName().equals(e.getStage().getName())) { position = d.getPosition(); + targetStage = d; } } } @@ -274,7 +292,7 @@ public class Visitor int randomtime = (int) (40 + (Math.random() * (60 - 40))); if (position != null) { - actions.add(new Action(position, startTime, randomtime)); + actions.add(new Action(position, startTime, randomtime, targetStage)); } startTime = startTime + randomtime; @@ -282,6 +300,7 @@ public class Visitor else if (random >= 30 && random < 35) { Point2D position = null; + DrawObject targetDraw = null; for (DrawObject d : objects) { if (d.getFileName().equals("entrance")) @@ -291,7 +310,7 @@ public class Visitor } if (position != null) { - actions.add(new Action(position, startTime, 35)); + actions.add(new Action(position, startTime, 35, targetDraw)); startTime = startTime + 35; } startTime = startTime + 35; @@ -300,6 +319,7 @@ public class Visitor else if (random > 35) { Point2D position = null; + DrawObject targetDrawobj = null; for (DrawObject d : objects) { if (d.getFileName().equals("wc")) @@ -309,7 +329,7 @@ public class Visitor } if (position != null) { - actions.add(new Action(position, startTime, 35)); + actions.add(new Action(position, startTime, 35, targetDrawobj)); } startTime = startTime + 35; diff --git a/Applicatie/Waypoint.java b/Applicatie/Waypoint.java index 7e00775..2ca3a17 100644 --- a/Applicatie/Waypoint.java +++ b/Applicatie/Waypoint.java @@ -11,6 +11,7 @@ public class Waypoint extends DrawObject public Waypoint(Point2D position) { super("waypoint", position); + self = 1; } @Override diff --git a/Objects/Path.java b/Objects/Path.java index 9968691..15b3de0 100644 --- a/Objects/Path.java +++ b/Objects/Path.java @@ -14,6 +14,8 @@ import java.util.ArrayList; import javax.imageio.ImageIO; +import Applicatie.Waypoint; + /** * Create's a path. * @@ -27,6 +29,7 @@ public class Path private ArrayList lines; private Point2D tempPoint; private BufferedImage pathBackground; + private ArrayList waypoints; /** * Constructor. @@ -35,6 +38,7 @@ public class Path { points = new ArrayList<>(); lines = new ArrayList<>(); + waypoints = new ArrayList(); try { pathBackground = ImageIO.read(new File("images/newPath.png")); @@ -141,6 +145,11 @@ public class Path } return lines; } + + public void addWaypoint(Waypoint w) + { + waypoints.add(w); + } /** * Add a point to the path.