15 Commits
Author SHA1 Message Date
Wesley 4c11d4ad2f fixed stuff
lol
2015-04-08 21:25:08 +02:00
Wesley 77dae9741e added addPeoplePanel 2015-04-08 21:07:59 +02:00
xrgman 7c28dd3a16 spawn
hoi
2015-04-08 14:03:58 +02:00
xrgman 98af73b15e fixed stuff 2015-04-07 17:07:32 +02:00
xrgman 5ec737e707 Added images 2015-04-07 16:08:05 +02:00
xrgman 65f428c572 New terrain 2015-04-07 14:56:59 +02:00
xrgman b2b2388f6f zooi 2015-04-07 11:58:36 +02:00
Wesley a45d37a4d5 Added path's
works but allot is edited
2015-04-02 23:31:48 +02:00
Wesley 040859ac2a Fixed overlapping and locked rotating rektangle.
Keep the rectangle its good enoguh.
2015-03-31 17:07:26 +02:00
xrgman 10951fe225 fixed overlapping objects
banaan
2015-03-18 12:51:30 +01:00
xrgman 34bc4526fc Added red rectangle when over another object
fancy pansy
2015-03-17 16:59:43 +01:00
xrgman f1e6abae76 added deleting object
🎯
2015-03-17 11:00:46 +01:00
xrgman c3ca87ad8f Added resizing and scrolling
Still buggs while dragging scaled.
2015-03-16 19:36:03 +01:00
xrgman dccdccb573 update
try
2015-03-15 11:42:01 +01:00
Wesley ae35416cf9 Added border when selected 2015-03-12 22:10:15 +01:00
25 changed files with 716 additions and 207 deletions
+2 -2
View File
@@ -55,11 +55,11 @@ public class Event implements Serializable {
}
public int getStart(){
return (startHour * 100) + startMinute;
return (startHour * 60) + startMinute;
}
public int getStop(){
return (stopHour * 100) + stopMinute;
return (stopHour * 60) + stopMinute;
}
public int getStopHour(){
+41
View File
@@ -0,0 +1,41 @@
package Agenda;
import java.io.Serializable;
public class Stage implements Serializable {
private static final long serialVersionUID = 1;
private String name;
private String description;
public Stage(String name, String description)
{
this.name = name;
this.description = description;
}
public String getName()
{
return this.name;
}
public String getDescription()
{
return this.description;
}
public void setDescription(String description)
{
this.description = description;
}
public void setName(String name)
{
this.name = name;
}
public String toString()
{
return name;
}
}
+1 -2
View File
@@ -46,9 +46,8 @@ public class Action
{
return duration;
}
public Waypoint getWaypoint(){
return waypoint;
}
}
+100
View File
@@ -0,0 +1,100 @@
package Applicatie;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class AddPeoplePanel extends JFrame {
public AddPeoplePanel(Panel topPanel) {
super("Adding people");
setDefaultCloseOperation(HIDE_ON_CLOSE);
setResizable(false);
JPanel mainPanel = new JPanel(new BorderLayout());
JLabel label;
JButton button;
//Top:
JPanel panel = new JPanel();
label = new JLabel("Enter the amount of people you want to add: ");
panel.add(label);
mainPanel.add(panel,BorderLayout.NORTH);
//Center:
panel = new JPanel();
JTextField amountOfPeopleField = new JTextField("0");
amountOfPeopleField.setPreferredSize(new Dimension(100,20));
amountOfPeopleField.addKeyListener(new KeyListener() {
@Override
public void keyTyped(KeyEvent e) {
}
@Override
public void keyReleased(KeyEvent e) {
try {
amountOfPeopleField.setBackground(Color.WHITE);
int amountOfPeople = Integer.parseInt(amountOfPeopleField.getText());
amountOfPeopleField.setText(amountOfPeople + "");
}
catch(NumberFormatException nf) {
amountOfPeopleField.setBackground(Color.RED);
}
}
@Override
public void keyPressed(KeyEvent e) {
}
});
label = new JLabel("people ");
panel.add(amountOfPeopleField);
panel.add(label);
mainPanel.add(panel,BorderLayout.CENTER);
//Bottom:
panel = new JPanel();
button = new JButton("Cancel");
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
AddPeoplePanel.this.dispose();
}
});
panel.add(button);
button = new JButton("Apply");
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if(amountOfPeopleField.getBackground() != Color.RED) {
topPanel.addVisitors(Integer.parseInt(amountOfPeopleField.getText()));
AddPeoplePanel.this.dispose();
}
else
JOptionPane.showMessageDialog(topPanel, "Only numbers are accepted");
}
});
panel.add(button);
mainPanel.add(panel,BorderLayout.SOUTH);
add(mainPanel);
//Finishing off
pack();
setSize(290,150);
setLocationRelativeTo(null);
setVisible(true);
}
}
+7 -3
View File
@@ -19,13 +19,16 @@ public class ControlPanel extends JPanel
private static final long serialVersionUID = 6805244250902524351L;
private Panel p;
private int people;
JLabel timeLabel;
JLabel peopleLabel;
public ControlPanel()
{
super();
BoxLayout box = new BoxLayout(this, BoxLayout.X_AXIS);
setLayout(box);
people = 0;
setPreferredSize(new Dimension(0,50));
setBorder(BorderFactory.createLineBorder(new Color(180, 180, 180)));
@@ -105,7 +108,7 @@ public class ControlPanel extends JPanel
peoplePanel.setMaximumSize(new Dimension(285,50));
add(peoplePanel);
{
JLabel peopleLabel = new JLabel("0/0 People");
peopleLabel = new JLabel(people + " People");
peopleLabel.setFont(new Font("Segoe UI", Font.PLAIN, 20));
peoplePanel.add(peopleLabel);
@@ -115,7 +118,7 @@ public class ControlPanel extends JPanel
peopleButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{
p.addVisitors();
new AddPeoplePanel(p);
}
});
peoplePanel.add(peopleButton);
@@ -147,6 +150,7 @@ public class ControlPanel extends JPanel
public void setPeople(int people)
{
this.people = people;
peopleLabel.setText(people + " People");
}
}
+268
View File
@@ -0,0 +1,268 @@
package Applicatie;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Shape;
import java.awt.geom.AffineTransform;
import java.awt.geom.Ellipse2D;
import java.awt.geom.NoninvertibleTransformException;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import javax.swing.ImageIcon;
public abstract class DrawObject
{
Point2D position;
double rotation;
double scale;
private Image image;
protected boolean selected;
private Rectangle2D rektAngle;
private Rectangle2D upperLeftCorner;
private Rectangle2D upperRightCorner;
private Rectangle2D bottomLeftCorner;
private Rectangle2D bottomRightCorner;
private Ellipse2D rotateDot;
static final int UPPERLEFT = 0;
static final int UPPERRIGHT = 1;
static final int BOTTOMLEFT = 2;
static final int BOTTOMRIGHT = 3;
private Color rectangleColor;
public DrawObject(String filename, Point2D position)
{
image = new ImageIcon(filename).getImage();
scale = 1;
rotation = 0;
this.position = position;
rectangleColor = Color.BLACK;
}
public abstract String getName();
public void draw(Graphics2D g)
{
AffineTransform tx = getTransform();
g.drawImage(image, tx, null);
if (selected)
{
// g.rotate(Math.toRadians(rotation), image.getWidth(null)/2,
// image.getHeight(null)/2);
AffineTransform rotate = AffineTransform.getRotateInstance(Math.toRadians(rotation), position.getX() + image.getWidth(null) / 2, position.getY() + image.getHeight(null) / 2);
//g.transform(rotate);
g.setColor(rectangleColor);
g.setStroke(new BasicStroke(7));
rektAngle = new Rectangle2D.Double((int) position.getX(), (int) position.getY(), image.getWidth(null), image.getHeight(null));
tx = getTransformRectangle();
rektAngle.setFrame(tx.createTransformedShape(rektAngle).getBounds());
g.draw(rektAngle);
g.setColor(Color.YELLOW);
upperLeftCorner = new Rectangle2D.Double(rektAngle.getX() - 7, rektAngle.getY() - 7, 15, 15);
upperRightCorner = new Rectangle2D.Double(rektAngle.getX() + rektAngle.getWidth() - 8, rektAngle.getY() - 7, 15, 15);
bottomLeftCorner = new Rectangle2D.Double(rektAngle.getX() - 7, rektAngle.getY() + rektAngle.getHeight() - 8, 15, 15);
bottomRightCorner = new Rectangle2D.Double(rektAngle.getX() + rektAngle.getWidth() - 8, rektAngle.getY() + rektAngle.getHeight() - 8, 15, 15);
g.fill(upperLeftCorner); // upperleft
g.fill(upperRightCorner); // upperright
g.fill(bottomLeftCorner); // bottomleft
g.fill(bottomRightCorner); // bottomright
g.setColor(Color.RED);
rotateDot = new Ellipse2D.Double((rektAngle.getX() + (rektAngle.getWidth() / 2)) - 8, rektAngle.getY() - 8, 15, 15);
g.fill(rotateDot);
}
}
protected AffineTransform getTransform()
{
AffineTransform tx = new AffineTransform();
tx.scale(scale, scale);
tx.translate(position.getX(), position.getY());
tx.rotate(Math.toRadians(rotation), image.getWidth(null) / 2, image.getHeight(null) / 2);
return tx;
}
protected AffineTransform getTransformSelection()
{
AffineTransform tx = new AffineTransform();
tx.scale(scale, scale);
tx.translate(position.getX(), position.getY());
return tx;
}
/**
* Special transformation for the selection rectangle, because the
* translation of the image one places the rectangle translated from the
* image.
*
* @return affineTransform
*/
private AffineTransform getTransformRectangle()
{
AffineTransform tx = new AffineTransform();
tx.scale(scale, scale);
return tx;
}
public boolean contains(Point2D clickPoint)
{
Shape shape;
if (rektAngle == null)
{
shape = new Rectangle2D.Double(0, 0, image.getWidth(null), image.getHeight(null));
return getTransform().createTransformedShape(shape).contains(clickPoint);
}
else
{
shape = new Rectangle2D.Double(-9, -9, image.getWidth(null) + 13, image.getHeight(null) + 13);
return getTransformSelection().createTransformedShape(shape).contains(clickPoint);
}
}
public Point2D getObjectPoint(Point2D point)
{
try
{
return getTransform().inverseTransform(point, null);
}
catch (NoninvertibleTransformException e)
{
e.printStackTrace();
}
return null;
}
/**
* Checking collision.
* @param object. the drawObject to check collision with.
* @return if there is a collision.
*/
public boolean collision(DrawObject object)
{
Shape ownShape = getRectangle();
Rectangle2D otherRectangle = object.getTransform().createTransformedShape(object.getImageRectangle()).getBounds2D();
if(ownShape.intersects(otherRectangle))
return true;
else
return false;
}
/**
* This method checks if the place thats clicked is inside one of the
* corners.
*
* @param point
* @param corner
* @return if the clicked point is inside one of the corners
*/
public boolean containsCorner(Point2D point, int corner)
{
Rectangle2D chosenCorner = null;
switch (corner)
{
case 0:
chosenCorner = upperLeftCorner;
break;
case 1:
chosenCorner = upperRightCorner;
break;
case 2:
chosenCorner = bottomLeftCorner;
break;
case 3:
chosenCorner = bottomRightCorner;
break;
case 4:
if (point.getX() > rotateDot.getX() && point.getX() < rotateDot.getX() + rotateDot.getWidth() && point.getY() > rotateDot.getY() && point.getY() < rotateDot.getY() + rotateDot.getHeight())
return true;
else
return false;
}
if (point.getX() > chosenCorner.getX() && point.getX() < chosenCorner.getX() + chosenCorner.getWidth() && point.getY() > chosenCorner.getY() && point.getY() < chosenCorner.getY() + chosenCorner.getHeight())
return true;
else
return false;
}
public void setSelected(boolean b)
{
selected = b;
}
public Point2D getPosition()
{
return position;
}
public void setPosition(Point2D position)
{
this.position = position;
}
public double getRotation()
{
return rotation;
}
public void setRotation(double rotation)
{
this.rotation = rotation;
}
public double getScale()
{
return scale;
}
public void setScale(double scale)
{
this.scale = scale;
}
public Image getImage()
{
return image;
}
public void setImage(Image image)
{
this.image = image;
}
public boolean isSelected()
{
return selected;
}
public Rectangle2D getRectangle()
{
return rektAngle;
}
public void setRectangle(Rectangle2D rectangle)
{
rektAngle = rectangle;
}
public Color getRectangleColor()
{
return rectangleColor;
}
public void setRectangleColor(Color rectangleColor)
{
this.rectangleColor = rectangleColor;
}
public Rectangle2D getImageRectangle() {
return new Rectangle2D.Double(0,0, image.getWidth(null), image.getHeight(null));
}
}
-1
View File
@@ -2,7 +2,6 @@ package Applicatie;
public class Main
{
public static void main(String[] args)
{
new Window();
+17 -14
View File
@@ -229,7 +229,16 @@ public class Panel extends JPanel implements ActionListener
return waypoints;
}
public void addVisitors()
public void addVisitors(ArrayList<DrawObject> entrances)
{
DrawObject entrance = entrances.get((int) Math.floor(Math.random()*entrances.size()));
Point point = new Point((int)entrance.getPosition().getX(),(int)entrance.getPosition().getY());
visitors.add(new Visitor("visitor",point, agenda, objects, waypoints, date));
}
public void addVisitors(int count)
{
ArrayList<DrawObject> entrances = new ArrayList<>();
for(DrawObject object : objects) {
@@ -238,21 +247,14 @@ public class Panel extends JPanel implements ActionListener
}
}
if(!entrances.isEmpty()) {
DrawObject entrance = entrances.get((int) Math.floor(Math.random()*entrances.size()));
Point point = new Point((int)entrance.getPosition().getX(),(int)entrance.getPosition().getY());
visitors.add(new Visitor("visitor",point, agenda, objects, waypoints, date));
for (int i = 0; i < count; i++)
{
addVisitors(entrances);
}
}
else {
else
JOptionPane.showMessageDialog(this, "You don't have an entrance");
}
}
public void addVisitors(int count)
{
for (int i = 0; i < count; i++)
{
addVisitors();
}
cp.setPeople(visitors.size());
}
public void paintComponent(Graphics g)
@@ -669,6 +671,7 @@ public class Panel extends JPanel implements ActionListener
this.height = height;
paths.clear();
objects.clear();
visitors.clear();
cameraScale = 1;
switch (terrainIndex)
{
+25 -13
View File
@@ -1,11 +1,11 @@
package Applicatie;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
@@ -21,20 +21,21 @@ public class PathPopup extends JFrame
public PathPopup(Path p, Panel panel)
{
super("Artist editscreen!");
super("");
setDefaultCloseOperation(HIDE_ON_CLOSE);
JPanel content = new JPanel(new BorderLayout());
JPanel content = new JPanel();
content.setLayout(new BoxLayout(content, BoxLayout.Y_AXIS));
JPanel south = new JPanel(new FlowLayout());
JPanel center = new JPanel(new GridLayout(5, 2));
content.add(south, BorderLayout.SOUTH);
content.add(center, BorderLayout.CENTER);
JPanel center = new JPanel();
JPanel panel1 = new JPanel();
JLabel name = new JLabel("Path");
JLabel name = new JLabel("Add WayPoint");
name.setFont(new Font("Dialog", Font.BOLD, 20));
panel1.add(name);
center.add(panel1);
content.add(panel1);
content.add(center);
content.add(south);
JTextField tf = new JTextField(5);
JTextField tf = new JTextField(10);
center.add(tf);
JButton edit = new JButton("Done");
@@ -47,11 +48,22 @@ public class PathPopup extends JFrame
dispose();
}
});
JButton cancel = new JButton("Cancel");
cancel.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
{
dispose();
}
});
south.add(edit);
south.add(cancel);
setContentPane(content);
setVisible(true);
setSize(500, 320);
setSize(200, 150);
}
}
+212 -165
View File
@@ -19,7 +19,8 @@ import Objects.Entrance;
import Objects.Path;
import Objects.Stage;
public class Visitor {
public class Visitor
{
Point2D position;
double rotation;
@@ -29,14 +30,15 @@ public class Visitor {
ArrayList<Action> actions;
Agenda agenda;
ArrayList<DrawObject> objects;
ArrayList<Waypoint> waypoints;
GregorianCalendar date;
int target;
int finalTarget;
public Visitor(String filename, Point2D position, Agenda agenda,
ArrayList<DrawObject> objects, ArrayList<Waypoint> waypoints,
GregorianCalendar date) {
public Visitor(String filename, Point2D position, Agenda agenda, ArrayList<DrawObject> objects, ArrayList<Waypoint> waypoints, GregorianCalendar date)
{
this.position = position;
this.filename = filename;
this.rotation = 0;
@@ -48,21 +50,19 @@ public class Visitor {
this.agenda = agenda;
this.objects = objects;
fillActions();
System.out.println(actions.size());
for (Action a : actions){
System.out.println("" + a.getStartTime());
}
target = 1;
finalTarget = 4;
finalTarget = 0;
}
public void draw(Graphics2D g2) {
public void draw(Graphics2D g2)
{
AffineTransform tx = getTransform();
Image image = Images.getImage(filename);
g2.drawImage(image, tx, null);
}
private AffineTransform getTransform() {
private AffineTransform getTransform()
{
Image image = Images.getImage(filename);
AffineTransform tx = new AffineTransform();
tx.scale(scale, scale);
@@ -71,43 +71,51 @@ public class Visitor {
return tx;
}
public DrawObject getEntrance() {
for (DrawObject o : objects) {
if (o instanceof Entrance) {
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, Panel panel) {
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()) {
finalTarget = a.getWaypoint().getSelf();
for (Action a : actions)
{
if (currentTime >= a.getStartTime() && currentTime < a.getStoptime())
{
this.finalTarget = a.getWaypoint().getSelf();
}
}
System.out.println(actions.size());
// moveToTarget(target, objects, visitors, paths);
move(target, panel);
}
public void move(DrawObject tar, Panel panel) {
public void move(DrawObject tar, Panel panel)
{
Point2D targetPoint = panel.getWaypoint(target).getPosition();
double newRot = Math.atan2(targetPoint.getY() - position.getY(),
targetPoint.getX() - position.getX());
double newRot = Math.atan2(targetPoint.getY() - position.getY(), targetPoint.getX() - position.getX());
int difx = (int) (targetPoint.getX() - position.getX());
int dify = (int) (targetPoint.getY() - position.getY());
int distance = (int) Math.sqrt((difx * difx) + (dify * dify));
if (rotation > newRot && distance > 10) {
if (rotation > newRot && distance > 10)
{
rotation -= 0.15;
} else if (rotation < newRot && distance > 10) {
}
else if (rotation < newRot && distance > 10)
{
rotation += 0.15;
}
@@ -117,85 +125,101 @@ public class Visitor {
float directionX = (float) Math.cos(rotation);
float directionY = (float) Math.sin(rotation);
if (distance > 10) {
position = new Point2D.Double(
(position.getX() + directionX * speed),
(position.getY() + directionY * speed));
if (distance > 10)
{
position = new Point2D.Double((position.getX() + directionX * speed), (position.getY() + directionY * speed));
}
boolean possible = true;
for (DrawObject object : objects) {
if (object instanceof Entrance || object instanceof Waypoint) {
for (DrawObject object : objects)
{
if (object instanceof Entrance || object instanceof Waypoint)
{
continue;
}
if (hasCollisionDO(object)) {
if (hasCollisionDO(object))
{
possible = false;
}
}
if (possible == false) {
if (possible == false)
{
position = oldPosition;
rotation += 0.2;
}
if (checkIfOnWaypoint(panel)) {
// for(int i : panel.getWaypoint(target).getOptions())
// {
// if(i == finalTarget)
// {
// target = finalTarget;
// }
// }
// ArrayList<int[]> options = new ArrayList<int[]>();
if (checkIfOnWaypoint(panel))
{
HashMap<Integer, int[]> options = new HashMap<Integer, int[]>();
for (Waypoint w : panel.getWaypoints()) {
for (Waypoint w : panel.getWaypoints())
{
options.put(w.getSelf(), w.getOptions());
}
for (Map.Entry<Integer, int[]> e : options.entrySet()) {
System.out.println(e.getKey());
System.out.println("=====================");
for (int i : e.getValue()) {
System.out.println(i);
for (Map.Entry<Integer, int[]> e : options.entrySet())
{
for (int i : e.getValue())
{
if (finalTarget != target)
{
if (finalTarget == i && e.getKey() == target)
{
target = finalTarget;
break;
}
else if (finalTarget == i)
{
target = e.getKey();
break;
}
}
}
System.out.println("----------");
}
}
}
public boolean checkIfOnWaypoint(Panel panel) {
if (panel.getWaypoint(target).contains(position)) {
public boolean checkIfOnWaypoint(Panel panel)
{
if (panel.getWaypoint(target).contains(position))
{
return true;
}
return false;
}
public void moveToTarget(DrawObject 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.getPosition();
boolean hasPathBelow = false;
for (Path p : paths) {
if (p.containsPoint(position)) {
for (Path p : paths)
{
if (p.containsPoint(position))
{
hasPathBelow = true;
break;
}
Shape containsShape = p.containsPointShape(position);
if (containsShape != null) {
tar = new Point2D.Double(
containsShape.getBounds().getCenterX(), containsShape
.getBounds().getCenterY());
if (containsShape != null)
{
tar = new Point2D.Double(containsShape.getBounds().getCenterX(), containsShape.getBounds().getCenterY());
}
}
if (hasPathBelow) {
double newRot = Math.atan2(tar.getY() - position.getY(), tar.getX()
- position.getX());
if (hasPathBelow)
{
double newRot = Math.atan2(tar.getY() - position.getY(), tar.getX() - position.getX());
int difx = (int) (tar.getX() - position.getX());
int dify = (int) (tar.getY() - position.getY());
int distance = (int) Math.sqrt((difx * difx) + (dify * dify));
if (rotation > newRot && distance > 10) {
if (rotation > newRot && distance > 10)
{
rotation -= 0.15;
} else if (rotation < newRot && distance > 10) {
}
else if (rotation < newRot && distance > 10)
{
rotation += 0.15;
}
@@ -205,30 +229,40 @@ public class Visitor {
float directionX = (float) Math.cos(rotation);
float directionY = (float) Math.sin(rotation);
if (distance > 10) {
position = new Point2D.Double((position.getX() + directionX
* speed), (position.getY() + directionY * speed));
if (distance > 10)
{
position = new Point2D.Double((position.getX() + directionX * speed), (position.getY() + directionY * speed));
}
boolean possible = true;
for (DrawObject object : objects) {
if (hasCollisionDO(object)) {
for (DrawObject object : objects)
{
if (hasCollisionDO(object))
{
possible = false;
}
}
for (Visitor object : visitors) {
if (hasCollision(object) && object != this) {
for (Visitor object : visitors)
{
if (hasCollision(object) && object != this)
{
possible = false;
}
}
if (possible == false) {
if (possible == false)
{
position = oldPosition;
rotation += 0.2;
}
} else {
}
else
{
HashMap<Double, Shape> values = new HashMap<Double, Shape>();
for (Path p : paths) {
for (Shape s : p.getPath()) {
for (Path p : paths)
{
for (Shape s : p.getPath())
{
Rectangle b = s.getBounds();
double maxx = b.getMaxX();
double minx = b.getMinX();
@@ -242,14 +276,16 @@ public class Visitor {
points[3] = new Point2D.Double(maxx, maxy);
Double lastdistance = null;
for (Point2D.Double point : points) {
double distance = Point2D.distance(point.getX(),
point.getY(), position.getX(), position.getY());
if (lastdistance == null) {
for (Point2D.Double point : points)
{
double distance = Point2D.distance(point.getX(), point.getY(), position.getX(), position.getY());
if (lastdistance == null)
{
lastdistance = distance;
continue;
}
if (distance < lastdistance) {
if (distance < lastdistance)
{
lastdistance = distance;
}
}
@@ -259,31 +295,35 @@ public class Visitor {
}
Double lastdistance = null;
Shape lastShape = null;
for (Map.Entry<Double, Shape> e : values.entrySet()) {
for (Map.Entry<Double, Shape> e : values.entrySet())
{
double distance = e.getKey();
if (lastdistance == null) {
if (lastdistance == null)
{
lastdistance = distance;
continue;
}
if (distance < lastdistance) {
if (distance < lastdistance)
{
lastdistance = distance;
}
}
lastShape = values.get(lastdistance);
Point2D.Double target2 = new Point2D.Double(lastShape.getBounds()
.getCenterX(), lastShape.getBounds().getCenterY());
Point2D.Double target2 = new Point2D.Double(lastShape.getBounds().getCenterX(), lastShape.getBounds().getCenterY());
double newRot = Math.atan2(target2.getY() - position.getY(),
target2.getX() - position.getX());
double newRot = Math.atan2(target2.getY() - position.getY(), target2.getX() - position.getX());
int difx = (int) (target2.getX() - position.getX());
int dify = (int) (target2.getY() - position.getY());
int distance = (int) Math.sqrt((difx * difx) + (dify * dify));
if (rotation > newRot && distance > 10) {
if (rotation > newRot && distance > 10)
{
rotation -= 0.15;
} else if (rotation < newRot && distance > 10) {
}
else if (rotation < newRot && distance > 10)
{
rotation += 0.15;
}
@@ -293,118 +333,127 @@ public class Visitor {
float directionX = (float) Math.cos(rotation);
float directionY = (float) Math.sin(rotation);
if (distance > 10) {
position = new Point2D.Double((position.getX() + directionX
* speed), (position.getY() + directionY * speed));
if (distance > 10)
{
position = new Point2D.Double((position.getX() + directionX * speed), (position.getY() + directionY * speed));
}
boolean possible = true;
for (DrawObject object : objects) {
if (hasCollisionDO(object)) {
for (DrawObject object : objects)
{
if (hasCollisionDO(object))
{
possible = false;
}
}
for (Visitor object : visitors) {
if (hasCollision(object) && object != this) {
for (Visitor object : visitors)
{
if (hasCollision(object) && object != this)
{
possible = false;
}
}
if (possible == false) {
if (possible == false)
{
position = oldPosition;
rotation += 0.2;
}
}
}
public void fillActions() {
@SuppressWarnings("static-access")
public void fillActions()
{
int startTime = 540;
int stopTime = 1260;
while (startTime < stopTime) {
while (startTime < stopTime)
{
int random = (int) Math.floor(Math.random() * 51);
if (random < 30) {
if (random < 40)
{
Point2D position = null;
DrawObject targetStage = null;
ArrayList<Event> posEvents = new ArrayList<Event>();
for (Event e : agenda.getEvents()) {
if (startTime >= e.getStart() && startTime < e.getStop()) {
for (Event e : agenda.getEvents())
{
if (startTime >= e.getStart() && startTime < e.getStop())
{
posEvents.add(e);
}
}
int totalPopularity = 0;
for (Event ev : posEvents){
totalPopularity += ev.getExpectedPopularity();
}
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){
for (DrawObject d : objects) {
if (d.getFileName().equals("stage")) {
Stage s = (Stage) d;
if (s.getStage().getName()
.equals(evs.getStage().getName())) {
position = s.getPosition();
targetStage = d;
}
}
if (posEvents.size() != 0)
{
int r = (int) Math.floor(Math.random() * posEvents.size());
Event evs = posEvents.get(r);
for (DrawObject d : objects)
{
if (d.getFileName().equals("stage"))
{
Stage s = (Stage) d;
if (s.getStage().getName().equals(evs.getStage().getName()))
{
position = s.getPosition();
targetStage = d;
}
}
}
}
int randomtime = (int) (40 + (Math.random() * (60 - 40)));
if (position != null) {
Waypoint w = getClosedWaypoint(position);
actions.add(new Action(position, startTime, randomtime,
targetStage, w));
if (position != null)
{
Waypoint w = getClosestWaypoint(position);
actions.add(new Action(position, startTime, randomtime, targetStage, w));
}
startTime = startTime + randomtime;
} else if (random >= 30 && random < 40) {
}
else if (random >= 40 && random < 45)
{
Point2D position = null;
DrawObject targetStage = null;
ArrayList<DrawObject> foodPlaces = new ArrayList<DrawObject>();
for (DrawObject d : objects) {
if (d.getFileName().equals("food")) {
for (DrawObject d : objects)
{
if (d.getFileName().equals("food"))
{
foodPlaces.add(d);
}
}
if (foodPlaces.size() != 0) {
if (foodPlaces.size() != 0)
{
int r = (int) Math.floor(Math.random() * foodPlaces.size());
position = foodPlaces.get(r).getPosition();
targetStage = foodPlaces.get(r);
Waypoint w = getClosedWaypoint(position);
actions.add(new Action(position, startTime, 35,
targetStage, w));
Waypoint w = getClosestWaypoint(position);
actions.add(new Action(position, startTime, 35, targetStage, w));
startTime = startTime + 20;
}
startTime = startTime + 35;
} else if (random >= 40) {
}
else if (random > 45)
{
Point2D position = null;
DrawObject targetStage = null;
ArrayList<DrawObject> toilets = new ArrayList<DrawObject>();
for (DrawObject d : objects) {
if (d.getFileName().equals("wc")) {
for (DrawObject d : objects)
{
if (d.getFileName().equals("wc"))
{
toilets.add(d);
}
}
if (toilets.size() != 0) {
if (toilets.size() != 0)
{
int r = (int) Math.floor(Math.random() * toilets.size());
position = toilets.get(r).getPosition();
targetStage = toilets.get(r);
Waypoint w = getClosedWaypoint(position);
actions.add(new Action(position, startTime, 35,
targetStage, w));
Waypoint w = getClosestWaypoint(position);
actions.add(new Action(position, startTime, 35, targetStage, w));
startTime = startTime + 20;
}
startTime = startTime + 35;
@@ -413,11 +462,14 @@ public class Visitor {
}
}
public Waypoint getClosedWaypoint(Point2D point) {
public Waypoint getClosestWaypoint(Point2D point)
{
Waypoint waypoint = null;
int distance = 10000;
for (Waypoint w : waypoints) {
if (w.getPosition().distance(point) < distance) {
for (Waypoint w : waypoints)
{
if (w.getPosition().distance(point) < distance)
{
waypoint = w;
distance = (int) w.getPosition().distance(point);
}
@@ -425,15 +477,12 @@ public class Visitor {
return waypoint;
}
public boolean hasCollisionDO(DrawObject object) {
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));
Rectangle rectb = new Rectangle((int) object.getPosition().getX(),
(int) object.getPosition().getY(), image2.getWidth(null),
image2.getHeight(null));
Rectangle recta = new Rectangle((int) position.getX(), (int) position.getY(), image.getWidth(null), image.getHeight(null));
Rectangle rectb = new Rectangle((int) object.getPosition().getX(), (int) object.getPosition().getY(), image2.getWidth(null), image2.getHeight(null));
Area a = new Area(recta);
Area b = new Area(rectb);
@@ -442,26 +491,23 @@ public class Visitor {
transA.rotate(rotation, position.getX(), position.getY());
AffineTransform transB = new AffineTransform();
transB.rotate(Math.toRadians(object.getRotation()), object
.getPosition().getX(), object.getPosition().getY());
transB.rotate(Math.toRadians(object.getRotation()), object.getPosition().getX(), object.getPosition().getY());
Area aa = a.createTransformedArea(transA);
Area bb = b.createTransformedArea(transB);
if (bb.intersects(aa.getBounds2D())) {
if (bb.intersects(aa.getBounds2D()))
{
return true;
}
return false;
}
public boolean hasCollision(Visitor v) {
public boolean hasCollision(Visitor v)
{
Image image = Images.getImage(filename);
Rectangle a = new Rectangle((int) position.getX(),
(int) position.getY(), image.getWidth(null),
image.getHeight(null));
Rectangle b = new Rectangle((int) v.position.getX(),
(int) v.position.getY(), image.getWidth(null),
image.getHeight(null));
Rectangle a = new Rectangle((int) position.getX(), (int) position.getY(), image.getWidth(null), image.getHeight(null));
Rectangle b = new Rectangle((int) v.position.getX(), (int) v.position.getY(), image.getWidth(null), image.getHeight(null));
Area aa = new Area(a);
Area bb = new Area(b);
@@ -475,9 +521,10 @@ public class Visitor {
Area ra = aa.createTransformedArea(af);
Area rb = bb.createTransformedArea(bf);
if (ra.intersects(rb.getBounds2D())) {
if (ra.intersects(rb.getBounds2D()))
{
return true;
}
return false;
}
}
}
+27 -2
View File
@@ -60,7 +60,7 @@ public class WaypointPopup extends JFrame {
panel1.add(name);
row1.add(panel1);
JTextField tf = new JTextField(10);
JTextField tf = new JTextField(wp.getSelf() + "", 10);
row2.add(tf);
JPanel panel2 = new JPanel();
@@ -73,7 +73,21 @@ public class WaypointPopup extends JFrame {
empty2.add(Box.createRigidArea(new Dimension(0, 5)));
row2.add(empty2);
JTextField tx = new JTextField(8);
String optionss = "";
if(wp.getOptions() != null)
{
if(wp.getOptions().length != 0)
{
int[] optionsa = wp.getOptions();
optionss += optionsa[0];
for(int i = 1; i < optionsa.length; i++)
{
optionss += "-" + optionsa[i];
}
}
}
JTextField tx = new JTextField("" + optionss, 8);
row2.add(tx);
JPanel help = new JPanel();
@@ -104,6 +118,17 @@ public class WaypointPopup extends JFrame {
});
south.add(edit);
JButton cancel = new JButton("Cancel");
cancel.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
{
dispose();
}
});
south.add(cancel);
setContentPane(content);
setVisible(true);
setSize(300,250);
+1 -5
View File
@@ -4,19 +4,15 @@ import java.awt.Color;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import javax.swing.SwingUtilities;
import Applicatie.Panel;
import Applicatie.PathPopup;
import Applicatie.Waypoint;
import Applicatie.WaypointPopup;
import Objects.DrawObject;
import Objects.Path;
import Objects.Entrance;
public class Mouse extends MouseAdapter
{
@@ -130,7 +126,7 @@ public class Mouse extends MouseAdapter
{
if (SwingUtilities.isRightMouseButton(e))
{
new PathPopup(clickedPath, panel);
//new PathPopup(clickedPath, panel);
}
}
else
+13
View File
@@ -0,0 +1,13 @@
package Objects;
import java.awt.geom.Point2D;
import Applicatie.DrawObject;
public class Podium extends DrawObject {
public Podium(Point2D position) {
super("images/stage3.png", position);
}
}
+2
View File
@@ -0,0 +1,2 @@
# FestivalPlanner
Festival Planner
Binary file not shown.
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 494 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 5.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 37 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 46 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB