package gui.simulator; import gui.simulator.Terrain.Location; import java.awt.*; import java.awt.geom.AffineTransform; import java.awt.geom.Point2D; import java.awt.geom.Rectangle2D; /** * * Created by gjoosen on 07/03/15. * Edited by master D Mathijssen on 17-3-2015 and some other days */ public abstract class DrawEngine { private Images.ImageType image; private double x, y, rotation, scale; private double distanceToOtherObjects; public SimulatorPane.Objects type; private Terrain terrain; private boolean drawWalkArea; private Rectangle2D.Double walkArea; public DrawEngine(){ } public DrawEngine(Images.ImageType image, int x, int y, double scale, double distanceToOtherObjects, SimulatorPane.Objects objecttype, Terrain terrain, Rectangle2D.Double walkArea, boolean drawWalkArea){ this.image = image; this.type = objecttype; this.x = x; this.y = y; this.scale = scale; this.distanceToOtherObjects = distanceToOtherObjects; this.terrain = terrain; this.walkArea = walkArea; this.drawWalkArea = drawWalkArea; } public AffineTransform getAffineTransform(){ AffineTransform transform = new AffineTransform(); transform.translate(this.x, this.y); transform.scale(this.scale, this.scale); transform.rotate(Math.toRadians(this.rotation), Images.getImage(image).getWidth(null) /2 , Images.getImage(image).getHeight(null) / 2); return transform; } public void draw(Graphics2D g) { g.drawImage(Images.getImage(image), this.getAffineTransform(), null); if(this.drawWalkArea){ g.setColor(new Color(0, 255, 0, 100)); g.fill(getAffineTransform().createTransformedShape(this.walkArea)); } } public boolean contains(Point2D point){ Shape shape = new Rectangle2D.Double(-distanceToOtherObjects, -distanceToOtherObjects, Images.getImage(image).getWidth(null)+2*distanceToOtherObjects,Images.getImage(image).getHeight(null)+2*distanceToOtherObjects); return this.getAffineTransform().createTransformedShape(shape).contains(point); } public boolean containsWalkArea(Point2D point){ if(this.walkArea == null){ return false; } return this.getAffineTransform().createTransformedShape(this.walkArea).contains(point); } public Image getImage(){ return Images.getImage(image); } public Point2D.Double getCenter(){ Point2D.Double center = new Point2D.Double(x + Images.getImage(image).getWidth(null)*scale / 2, y + Images.getImage(image).getHeight(null)*scale/2); return center; } //getters and setters down here public double getX() { return x; } public double getY() { return y; } public void setX(double x){ this.x = x; } public void setY(double y){ this.y = y; } public void setRotation(double rotation) { this.rotation = rotation; } public double getScale() { return scale; } public void setScale(double scale) { this.scale = scale; } public int getWidth(){ return Images.getImage(image).getWidth(null); } public int getHeight(){ return Images.getImage(image).getHeight(null); } public double getRotation() { return rotation; } public double getDistanceToOtherObjects() { return distanceToOtherObjects; } public Rectangle2D.Double getRect(){ return new Rectangle2D.Double(-distanceToOtherObjects, - distanceToOtherObjects, Images.getImage(image).getWidth(null) + 2* distanceToOtherObjects, Images.getImage(image).getHeight(null) + 2*distanceToOtherObjects); } public void remove(){ this.terrain.getEntities().remove(this); this.terrain.removeWalkingPaths(this); } public abstract String getFacilityName(); public void changeLocation(Location loc){ switch(loc){ case NORTH: //Visitors spawn north case EAST: //Visitors spawn east case SOUTH: //Visitors spawn south case WEST: //Visitors spawn west default: break; } } }