Переглянути джерело

Visitor speed changed and scaling fixed

Supermaniac101 10 роки тому
батько
коміт
27f6091f3b

+ 101 - 0
src/gui/simulator/Draw.java

@@ -0,0 +1,101 @@
+package gui.simulator;
+
+import javax.imageio.ImageIO;
+
+import java.awt.*;
+import java.awt.geom.AffineTransform;
+import java.awt.geom.Point2D;
+import java.awt.geom.Rectangle2D;
+import java.io.IOException;
+
+/**
+ * Created by gjoosen on 07/03/15.
+ * Edited by master D Mathijssen on 17-3-2015 and some other days
+ */
+public abstract class Draw {
+
+    private Image image;
+    public double x, y, rotation, scale;
+    private double distanceToOtherObjects;
+
+    public Draw(String image, int x, int y, double scale, double distanceToOtherObjects){
+        try{
+            this.image = ImageIO.read(getClass().getResource(image));
+        }catch(IOException ex){
+            ex.printStackTrace();
+        }
+        this.x = x;
+        this.y = y;
+        this.scale = scale;
+        this.distanceToOtherObjects = distanceToOtherObjects;
+    }
+
+    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), this.image.getWidth(null) /2 , this.image.getHeight(null) / 2);
+        return transform;
+    }
+
+    public void draw(Graphics2D g){
+        g.drawImage(this.image, this.getAffineTransform(), null);
+    }
+
+    public boolean contains(Point2D point){
+        Shape shape = new Rectangle2D.Double(0, 0, image.getWidth(null), image.getHeight(null));
+        return this.getAffineTransform().createTransformedShape(shape).contains(point);
+    }
+    
+    public Image getImage(){
+    	return image;
+    }
+
+    //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 this.image.getWidth(null);
+    }
+
+    public int getHeight(){
+        return this.image.getHeight(null);
+    }
+    public double getRotation() {
+        return rotation;
+    }
+
+    public double getDistanceToOtherObjects() {
+        return distanceToOtherObjects;
+    }
+
+    public Rectangle2D.Double getRect(){
+        return new Rectangle2D.Double(-distanceToOtherObjects, - distanceToOtherObjects, image.getWidth(null)  + 2* distanceToOtherObjects, image.getHeight(null) + 2*distanceToOtherObjects);
+    }
+}

+ 8 - 2
src/gui/simulator/Terrain.java

@@ -242,8 +242,14 @@ public class Terrain extends JPanel {
                 	//if object selected, scale object
                     if(object.contains(clickPoint)){
 						double oldscale  = object.getScale();
-						object.setScale(object.getScale() * 1 + (e.getPreciseWheelRotation()/10.0));
-
+						if(oldscale < 0.3){
+							if((e.getPreciseWheelRotation()/10.0) > 0){
+								object.setScale(object.getScale() * 1 + (e.getPreciseWheelRotation()/10.0));
+							} 
+						} else {
+							object.setScale(object.getScale() * 1 + (e.getPreciseWheelRotation()/10.0));
+						}
+						
 						//intersect
 						for(DrawEngine draw: entities){
 							if(draw != object){

+ 7 - 1
src/gui/simulator/Visitor.java

@@ -23,7 +23,13 @@ public class Visitor {
 	public Visitor(Point2D positie) {
 		this.positie = positie;
 		this.rotation = 0;
-		this.speed = 1;
+		double number = Math.random()*2;
+		if(number < 1){
+			this.speed = 1;
+		} else {
+			this.speed = number;
+		}
+		
 		this.target = new Point2D.Double(0, 0);
 	}
 

+ 1 - 1
src/gui/simulator/WalkingPath.java

@@ -56,7 +56,7 @@ public class WalkingPath {
 		}
 	}
 	public void paint(Graphics2D g2){
-		g2.setStroke(new BasicStroke(20,BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
+		g2.setStroke(new BasicStroke(40,BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
 		for(int i = 1; i < getPath().size(); i++){
 			g2.setPaint(new TexturePaint(texture, new Rectangle(0,0,100,100)));
 			g2.drawLine((int)get(i-1).getX(),(int)get(i-1).getY(), (int)get(i).getX(),(int)get(i).getY());