This commit is contained in:
Yorick
2015-04-08 12:42:12 +02:00
parent 701f2aed4b
commit ad62094ee7
5 changed files with 54 additions and 29 deletions
+10 -1
View File
@@ -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()
{
+3 -17
View File
@@ -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)
{
+31 -11
View File
@@ -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<Action> actions;
Agenda agenda;
ArrayList<DrawObject> objects;
char target;
int target;
public Visitor(String filename, Point2D position, Agenda agenda, ArrayList<DrawObject> 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<DrawObject> objects, int currentTime, ArrayList<Visitor> visitors, ArrayList<Path> 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<DrawObject> objects, ArrayList<Visitor> visitors, ArrayList<Path> paths)
public void moveToTarget(DrawObject target, ArrayList<DrawObject> objects, ArrayList<Visitor> visitors, ArrayList<Path> 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;
+1
View File
@@ -11,6 +11,7 @@ public class Waypoint extends DrawObject
public Waypoint(Point2D position)
{
super("waypoint", position);
self = 1;
}
@Override
+9
View File
@@ -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<Shape> lines;
private Point2D tempPoint;
private BufferedImage pathBackground;
private ArrayList<Waypoint> waypoints;
/**
* Constructor.
@@ -35,6 +38,7 @@ public class Path
{
points = new ArrayList<>();
lines = new ArrayList<>();
waypoints = new ArrayList<Waypoint>();
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.