Ver Fonte

drawpath and start walkers

jancoow há 10 anos atrás
pai
commit
75fa8bd542
3 ficheiros alterados com 69 adições e 4 exclusões
  1. BIN
      res/visitor.png
  2. 4 4
      src/gui/simulator/Visitor.java
  3. 65 0
      src/gui/simulator/WalkingPath.java

BIN
res/visitor.png


+ 4 - 4
src/gui/simulator/Visitor.java

@@ -15,7 +15,7 @@ public class Visitor {
 	double speed;
 	Point2D target;
 	
-	Image image = new ImageIcon("visitor.png").getImage();
+	Image image = new ImageIcon("res/visitor.png").getImage();
 	
 
 
@@ -70,8 +70,8 @@ public class Visitor {
 	void paint(Graphics2D g)
 	{
 		AffineTransform tx = new AffineTransform();
-		tx.translate(positie.getX()-32, positie.getY()-32);
-		tx.rotate(rotation, 32, 32);
+		tx.translate(positie.getX()-8, positie.getY()-11);
+		tx.rotate(rotation, 4, 6);
 		
 		g.drawImage(image, tx ,null);
 		
@@ -82,7 +82,7 @@ public class Visitor {
 		{
 			if(b == this)
 				continue;
-			if(b.positie.distance(positie) < 64)
+			if(b.positie.distance(positie) < 11)
 				return true;
 		}
 		return false;

+ 65 - 0
src/gui/simulator/WalkingPath.java

@@ -0,0 +1,65 @@
+package gui.simulator;
+
+import java.awt.BasicStroke;
+import java.awt.Graphics2D;
+import java.awt.Point;
+import java.awt.Rectangle;
+import java.awt.TexturePaint;
+import java.awt.Window;
+import java.awt.image.BufferedImage;
+import java.io.IOException;
+import java.util.ArrayList;
+
+import javax.imageio.ImageIO;
+
+public class WalkingPath {
+	private ArrayList<Point> path;
+	private Draw object1,object2;
+	private BufferedImage texture;
+	
+	public WalkingPath(){
+		path = new ArrayList<Point>();
+		try {
+			texture = ImageIO.read(Window.class.getResource("/ground_stone.jpg"));
+		} catch (IOException e) {
+			e.printStackTrace();
+		}
+	}
+	public void addPoint(Point p){
+		path.add(p);
+	}
+	public Point get(int i){
+		return path.get(i);
+	}
+	public ArrayList<Point> getPath() {
+		return path;
+	}
+	public void setPath(ArrayList<Point> path) {
+		this.path = path;
+	}
+	public Draw getObject1() {
+		return object1;
+	}
+	public void setObject1(Draw object1) {
+		this.object1 = object1;
+	}
+	public Draw getObject2() {
+		return object2;
+	}
+	public void setObject2(Draw object2) {
+		this.object2 = object2;
+	}
+	public void reCalculate(){
+		path.get(0).setLocation(new Point((int)object1.getX(), (int)object1.getY()));
+		path.get(path.size()-1).setLocation(new Point((int)object2.getX(), (int)object2.getY()));
+	}
+	public void paint(Graphics2D g2){
+		g2.setStroke(new BasicStroke(10));
+		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());
+		}
+	}
+	
+	
+}