laatste update
This commit is contained in:
@@ -44,7 +44,7 @@ public class DrawObject implements Serializable{
|
||||
public void draw(Graphics2D g)
|
||||
{
|
||||
AffineTransform tx = getTransform();
|
||||
Image image = new ImageIcon(filename).getImage();
|
||||
Image image = Images.getImage(filename);
|
||||
g.drawImage(image, tx, null);
|
||||
if(selected) {
|
||||
// g.rotate(Math.toRadians(rotation), image.getWidth(null)/2, image.getHeight(null)/2);
|
||||
@@ -100,7 +100,7 @@ public class DrawObject implements Serializable{
|
||||
|
||||
public boolean contains(Point2D clickPoint) {
|
||||
Shape shape;
|
||||
Image image = new ImageIcon(filename).getImage();
|
||||
Image image = Images.getImage(filename);
|
||||
if(rektAngle == null) {
|
||||
shape = new Rectangle2D.Double(0,0,image.getWidth(null), image.getHeight(null));
|
||||
return getTransform().createTransformedShape(shape).contains(clickPoint);
|
||||
@@ -186,7 +186,7 @@ public class DrawObject implements Serializable{
|
||||
}
|
||||
|
||||
public Image getImage() {
|
||||
Image image = new ImageIcon(filename).getImage();
|
||||
Image image = Images.getImage(filename);
|
||||
return image;
|
||||
}
|
||||
|
||||
@@ -215,13 +215,13 @@ public class DrawObject implements Serializable{
|
||||
}
|
||||
|
||||
public int getEndX(){
|
||||
Image image = new ImageIcon(filename).getImage();
|
||||
Image image = Images.getImage(filename);
|
||||
//return (int) (position.getX() + (image.getWidth(null) * scale));
|
||||
return (int) (position.getX() + image.getWidth(null));
|
||||
}
|
||||
|
||||
public int getEndY(){
|
||||
Image image = new ImageIcon(filename).getImage();
|
||||
Image image = Images.getImage(filename);
|
||||
//return (int) (position.getY() + (image.getHeight(null) * scale));
|
||||
return (int) (position.getY() + image.getHeight(null));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
package Applicatie;
|
||||
|
||||
import java.awt.Image;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.swing.ImageIcon;
|
||||
|
||||
public class Images{
|
||||
|
||||
private static Map<String, Image> images;
|
||||
|
||||
public Images() {
|
||||
|
||||
images = new HashMap<String, Image>();
|
||||
|
||||
images.put("entrance", loadImage("images/entrance.png"));
|
||||
images.put("wc", loadImage("images/wc.png"));
|
||||
images.put("path", loadImage("images/path.jpg"));
|
||||
images.put("stage", loadImage("images/stage4.png"));
|
||||
images.put("wall", loadImage("images/wall.png"));
|
||||
images.put("stage1", loadImage("images/stage3.png"));
|
||||
|
||||
}
|
||||
|
||||
public static Image loadImage(String path) {
|
||||
return new ImageIcon(path).getImage();
|
||||
}
|
||||
|
||||
public static Image getImage(String getter) {
|
||||
return images.get(getter);
|
||||
}
|
||||
}
|
||||
@@ -67,6 +67,7 @@ public class Panel extends JPanel implements ActionListener {
|
||||
|
||||
Panel(PropertiesPanel pp) {
|
||||
this.pp = pp;
|
||||
new Images();
|
||||
pp.setPanel(this);
|
||||
try {
|
||||
background = ImageIO.read(new File("images/grass.jpg"));
|
||||
@@ -183,7 +184,7 @@ public class Panel extends JPanel implements ActionListener {
|
||||
if ( tick >= 10){
|
||||
tick = 0;
|
||||
currentTime++;
|
||||
System.out.println(currentTime);
|
||||
//System.out.println(currentTime);
|
||||
}
|
||||
|
||||
for (Visitor v: visitors){
|
||||
|
||||
@@ -98,6 +98,7 @@ public class Visitor {
|
||||
|
||||
while (startTime < stopTime) {
|
||||
int random = (int) Math.floor(Math.random() * 51);
|
||||
System.out.println(random);
|
||||
if (random < 30) {
|
||||
Point2D position = null;
|
||||
for (Event e : agenda.getEvents()) {
|
||||
@@ -119,7 +120,7 @@ public class Visitor {
|
||||
} else if (random >= 30 && random < 35) {
|
||||
Point2D position = null;
|
||||
for (DrawObject d : objects) {
|
||||
if (d.getFileName().equals("images/entrance.png")) {
|
||||
if (d.getFileName().equals("entrance")) {
|
||||
position = d.getPosition();
|
||||
}
|
||||
}
|
||||
@@ -132,7 +133,7 @@ public class Visitor {
|
||||
} else if (random > 35) {
|
||||
Point2D position = null;
|
||||
for (DrawObject d : objects) {
|
||||
if (d.getFileName().equals("images/wc.png")) {
|
||||
if (d.getFileName().equals("wc")) {
|
||||
position = d.getPosition();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,96 @@
|
||||
package Listeners;
|
||||
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.geom.Point2D;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import Applicatie.DrawObject;
|
||||
import Applicatie.Panel;
|
||||
import Objects.Podium;
|
||||
|
||||
public class Mouse extends MouseAdapter {
|
||||
|
||||
private Panel panel;
|
||||
private DrawObject selectedObject;
|
||||
|
||||
public Mouse(Panel panel) {
|
||||
this.panel = panel;
|
||||
selectedObject = null;
|
||||
}
|
||||
|
||||
public void mousePressed(MouseEvent e) {
|
||||
Point2D clickPoint = panel.getClickPoint(e.getPoint());
|
||||
panel.setLastClickPosition(clickPoint);
|
||||
panel.setLastMousePosition(e.getPoint());
|
||||
if (e.getY() < 150) {
|
||||
// if(e.getX() < 51) //51 = width podium image
|
||||
// panel.setDragObject(new Podium(clickPoint));
|
||||
// else
|
||||
// panel.setDragObject(new Toilet(clickPoint));
|
||||
int i = 0;
|
||||
int last = 0;
|
||||
for (BufferedImage image : panel.getPanelInfo()) {
|
||||
if (e.getX() >= panel.getScrollfactor()
|
||||
&& e.getX() < last + image.getWidth()
|
||||
+ panel.getScrollfactor()) {
|
||||
DrawObject tempDrawObj = panel.createNewDrawObject(i);
|
||||
tempDrawObj.setPosition(clickPoint);
|
||||
panel.setDragObject(tempDrawObj);
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
last += image.getWidth();
|
||||
|
||||
}
|
||||
if (panel.getDragObject() != null) {
|
||||
panel.add(panel.getDragObject());
|
||||
}
|
||||
} else {
|
||||
for (DrawObject o : panel.getObjects()) {
|
||||
if (o.contains(clickPoint)) {
|
||||
if (o == selectedObject) {
|
||||
boolean upperLeft = o.containsCorner(clickPoint, 0);
|
||||
boolean upperRight = o.containsCorner(clickPoint, 1);
|
||||
boolean bottomLeft = o.containsCorner(clickPoint, 2);
|
||||
boolean bottomRight = o.containsCorner(clickPoint, 3);
|
||||
boolean rotate = o.containsCorner(clickPoint, 4);
|
||||
if (upperLeft) {
|
||||
panel.setClickedOption("upperLeft");
|
||||
} else if (upperRight) {
|
||||
panel.setClickedOption("upperRight");
|
||||
} else if (bottomLeft) {
|
||||
panel.setClickedOption("bottomLeft");
|
||||
} else if (bottomRight) {
|
||||
panel.setClickedOption("bottomRight");
|
||||
} else if (rotate) {
|
||||
panel.setClickedOption("rotate");
|
||||
} else {
|
||||
panel.setClickedOption("drag");
|
||||
}
|
||||
}
|
||||
if (selectedObject != null)
|
||||
selectedObject.setSelected(false);
|
||||
panel.setDragObject(o);
|
||||
o.setSelected(true);
|
||||
selectedObject = o;
|
||||
panel.setDragObject(o);
|
||||
panel.getPP().setSelected(o);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (panel.getDragObject() == null && selectedObject != null) {
|
||||
selectedObject.setSelected(false);
|
||||
selectedObject = null;
|
||||
}
|
||||
panel.repaint();
|
||||
}
|
||||
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
panel.setDragObject(null);
|
||||
panel.setClickedOption("drag");
|
||||
panel.repaint();
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,7 @@ import Applicatie.DrawObject;
|
||||
public class Entrance extends DrawObject {
|
||||
|
||||
public Entrance(Point2D position) {
|
||||
super("images/entrance.png", position);
|
||||
super("entrance", position);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ import Applicatie.DrawObject;
|
||||
public class Path extends DrawObject {
|
||||
|
||||
public Path(Point2D position) {
|
||||
super("images/path.jpg", position);
|
||||
super("path", position);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ import Applicatie.DrawObject;
|
||||
public class Podium extends DrawObject {
|
||||
|
||||
public Podium(Point2D position) {
|
||||
super("images/stage4.png", position);
|
||||
super("stage", position);
|
||||
}
|
||||
|
||||
}
|
||||
+1
-1
@@ -7,7 +7,7 @@ import Applicatie.DrawObject;
|
||||
public class Stage extends DrawObject {
|
||||
|
||||
public Stage(Point2D position) {
|
||||
super("images/stage3.png", position);
|
||||
super("stage1", position);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ import Applicatie.DrawObject;
|
||||
public class Toilet extends DrawObject {
|
||||
|
||||
public Toilet(Point2D position) {
|
||||
super("images/wc.png", position);
|
||||
super("wc", position);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ import Applicatie.DrawObject;
|
||||
public class Wall extends DrawObject {
|
||||
|
||||
public Wall(Point2D position) {
|
||||
super("images/wall.png", position);
|
||||
super("wall", position);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user