|
@@ -1,10 +1,10 @@
|
|
|
package gui.simulator;
|
|
package gui.simulator;
|
|
|
|
|
|
|
|
-import gui.simulator.facilities.*;
|
|
|
|
|
|
|
+import gui.simulator.facilities.RestRoom;
|
|
|
|
|
+import gui.simulator.facilities.Stage;
|
|
|
|
|
|
|
|
import java.awt.BasicStroke;
|
|
import java.awt.BasicStroke;
|
|
|
import java.awt.Color;
|
|
import java.awt.Color;
|
|
|
-import java.awt.Font;
|
|
|
|
|
import java.awt.Graphics;
|
|
import java.awt.Graphics;
|
|
|
import java.awt.Graphics2D;
|
|
import java.awt.Graphics2D;
|
|
|
import java.awt.Point;
|
|
import java.awt.Point;
|
|
@@ -16,10 +16,16 @@ import java.awt.event.MouseEvent;
|
|
|
import java.awt.event.MouseMotionAdapter;
|
|
import java.awt.event.MouseMotionAdapter;
|
|
|
import java.awt.event.MouseWheelEvent;
|
|
import java.awt.event.MouseWheelEvent;
|
|
|
import java.awt.event.MouseWheelListener;
|
|
import java.awt.event.MouseWheelListener;
|
|
|
-import java.awt.geom.*;
|
|
|
|
|
|
|
+import java.awt.geom.AffineTransform;
|
|
|
|
|
+import java.awt.geom.Area;
|
|
|
|
|
+import java.awt.geom.NoninvertibleTransformException;
|
|
|
|
|
+import java.awt.geom.Point2D;
|
|
|
|
|
+import java.awt.geom.Rectangle2D;
|
|
|
import java.awt.image.BufferedImage;
|
|
import java.awt.image.BufferedImage;
|
|
|
import java.io.File;
|
|
import java.io.File;
|
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
|
|
|
+import java.nio.file.Path;
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.LinkedList;
|
|
import java.util.LinkedList;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
|
|
@@ -37,13 +43,20 @@ public class Terrain extends JPanel {
|
|
|
|
|
|
|
|
private int festivalheight, festivalwidth;
|
|
private int festivalheight, festivalwidth;
|
|
|
private int sideBarWidth = 200;
|
|
private int sideBarWidth = 200;
|
|
|
|
|
+
|
|
|
|
|
+ private int pathgenerate = 1;
|
|
|
|
|
+ private WalkingPath currentpath;
|
|
|
|
|
+
|
|
|
private SimulatorPane.Terrains terrain;
|
|
private SimulatorPane.Terrains terrain;
|
|
|
Point2D cameraPoint = new Point2D.Double(festivalwidth/2,festivalheight/2);
|
|
Point2D cameraPoint = new Point2D.Double(festivalwidth/2,festivalheight/2);
|
|
|
float cameraScale = 1;
|
|
float cameraScale = 1;
|
|
|
private boolean grid;
|
|
private boolean grid;
|
|
|
|
|
+ private ArrayList<Visitor> visitors;
|
|
|
|
|
+ private ArrayList<WalkingPath> paths;
|
|
|
|
|
|
|
|
Point2D lastClickPosition;
|
|
Point2D lastClickPosition;
|
|
|
Point lastMousePosition;
|
|
Point lastMousePosition;
|
|
|
|
|
+ Point2D lastMovedMousePosition;
|
|
|
|
|
|
|
|
public Terrain(int length, int width, SimulatorPane.Terrains terrain){
|
|
public Terrain(int length, int width, SimulatorPane.Terrains terrain){
|
|
|
//get values
|
|
//get values
|
|
@@ -51,8 +64,15 @@ public class Terrain extends JPanel {
|
|
|
setFestivalWidth(width);
|
|
setFestivalWidth(width);
|
|
|
grid = true;
|
|
grid = true;
|
|
|
this.terrain = terrain;
|
|
this.terrain = terrain;
|
|
|
|
|
+ visitors = new ArrayList<Visitor>();
|
|
|
|
|
+ paths = new ArrayList<WalkingPath>();
|
|
|
|
|
+ for(int i=0; i< 40; i++){
|
|
|
|
|
+ visitors.add(new Visitor(new Point(100+(i*15),100)));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
//initialize sidebar
|
|
//initialize sidebar
|
|
|
sidebar = new Sidebar(sideBarWidth, getFestivalHeight(), this);
|
|
sidebar = new Sidebar(sideBarWidth, getFestivalHeight(), this);
|
|
|
|
|
+
|
|
|
//set terrainbackground
|
|
//set terrainbackground
|
|
|
switch(terrain){
|
|
switch(terrain){
|
|
|
case BEACH:
|
|
case BEACH:
|
|
@@ -101,7 +121,6 @@ public class Terrain extends JPanel {
|
|
|
entities.add(dragObject);
|
|
entities.add(dragObject);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
private void listeners(){
|
|
private void listeners(){
|
|
|
addMouseListener(new MouseAdapter() {
|
|
addMouseListener(new MouseAdapter() {
|
|
|
@Override
|
|
@Override
|
|
@@ -115,11 +134,29 @@ public class Terrain extends JPanel {
|
|
|
if(e.getX() > sideBarWidth){
|
|
if(e.getX() > sideBarWidth){
|
|
|
for(Draw drawObject: entities){
|
|
for(Draw drawObject: entities){
|
|
|
if(drawObject.contains(clickPoint)){
|
|
if(drawObject.contains(clickPoint)){
|
|
|
- dragObject = drawObject;
|
|
|
|
|
- selectedObject = dragObject;
|
|
|
|
|
- oldPosition = new Point2D.Double(selectedObject.getX(), selectedObject.getY());
|
|
|
|
|
|
|
+ if(pathgenerate == 1){
|
|
|
|
|
+ currentpath = new WalkingPath();
|
|
|
|
|
+ currentpath.addPoint(new Point((int)drawObject.getX(), (int)drawObject.getY()));
|
|
|
|
|
+ currentpath.setObject1(drawObject);
|
|
|
|
|
+ pathgenerate = 2;
|
|
|
|
|
+ return;
|
|
|
|
|
+ }else if(pathgenerate > 1){
|
|
|
|
|
+ currentpath.addPoint(new Point((int)drawObject.getX(), (int)drawObject.getY()));
|
|
|
|
|
+ currentpath.setObject2(drawObject);
|
|
|
|
|
+ paths.add(currentpath);
|
|
|
|
|
+ pathgenerate = 0;
|
|
|
|
|
+ return;
|
|
|
|
|
+ }else{
|
|
|
|
|
+ dragObject = drawObject;
|
|
|
|
|
+ selectedObject = dragObject;
|
|
|
|
|
+ oldPosition = new Point2D.Double(selectedObject.getX(), selectedObject.getY());
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+ if(pathgenerate > 1){
|
|
|
|
|
+ currentpath.addPoint(new Point((int)getClickPoint(e.getPoint()).getX(), (int)getClickPoint(e.getPoint()).getY()));
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
repaint();
|
|
repaint();
|
|
|
}
|
|
}
|
|
@@ -145,6 +182,9 @@ public class Terrain extends JPanel {
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
addMouseMotionListener(new MouseMotionAdapter() {
|
|
addMouseMotionListener(new MouseMotionAdapter() {
|
|
|
|
|
+ public void mouseMoved(MouseEvent e){
|
|
|
|
|
+ lastMovedMousePosition = getClickPoint(e.getPoint());
|
|
|
|
|
+ }
|
|
|
@Override
|
|
@Override
|
|
|
public void mouseDragged(MouseEvent e) {
|
|
public void mouseDragged(MouseEvent e) {
|
|
|
Point2D clickPoint = getClickPoint(e.getPoint());
|
|
Point2D clickPoint = getClickPoint(e.getPoint());
|
|
@@ -222,10 +262,26 @@ public class Terrain extends JPanel {
|
|
|
};
|
|
};
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ for(Visitor v:visitors){
|
|
|
|
|
+ v.paint(g2);
|
|
|
|
|
+ }
|
|
|
for(Draw drawObject: entities){
|
|
for(Draw drawObject: entities){
|
|
|
drawObject.draw(g2);
|
|
drawObject.draw(g2);
|
|
|
|
|
+ if(pathgenerate > 0){
|
|
|
|
|
+ g2.fill(drawObject.getAffineTransform().createTransformedShape(new Rectangle((int)(drawObject.getX()-(drawObject.getWidth()/2)-10),(int)(drawObject.getY()-(drawObject.getHeight()/2)-10), 20, 20)));
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ if(pathgenerate > 1){
|
|
|
|
|
+ g2.setStroke(new BasicStroke(10));
|
|
|
|
|
+ currentpath.paint(g2);
|
|
|
|
|
+ g2.drawLine((int)currentpath.get(currentpath.getPath().size()-1).getX(),(int)currentpath.get(currentpath.getPath().size()-1).getY(), (int)lastMovedMousePosition.getX(), (int)lastMovedMousePosition.getY());
|
|
|
|
|
+ }else{
|
|
|
|
|
+ for(WalkingPath path:paths){
|
|
|
|
|
+ path.paint(g2);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
//draw collide boxes
|
|
//draw collide boxes
|
|
|
if(this.selectedObject != null){
|
|
if(this.selectedObject != null){
|
|
|
Shape shape = this.selectedObject.getRect();
|
|
Shape shape = this.selectedObject.getRect();
|
|
@@ -281,15 +337,20 @@ public class Terrain extends JPanel {
|
|
|
tx.scale(cameraScale, cameraScale);
|
|
tx.scale(cameraScale, cameraScale);
|
|
|
return tx;
|
|
return tx;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+ public void calculate(){
|
|
|
|
|
+ for(Visitor v:visitors){
|
|
|
|
|
+ v.update(visitors);
|
|
|
|
|
+ }
|
|
|
|
|
+ for(WalkingPath p:paths){
|
|
|
|
|
+ p.reCalculate();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
public void setFestivalHeight(int height){
|
|
public void setFestivalHeight(int height){
|
|
|
this.festivalheight = height;
|
|
this.festivalheight = height;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
public void setFestivalWidth(int width){
|
|
public void setFestivalWidth(int width){
|
|
|
this.festivalwidth = width;
|
|
this.festivalwidth = width;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
public int getFestivalHeight(){
|
|
public int getFestivalHeight(){
|
|
|
return festivalheight;
|
|
return festivalheight;
|
|
|
}
|
|
}
|