WalkingPath.java 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package gui.simulator;
  2. import java.awt.BasicStroke;
  3. import java.awt.Graphics2D;
  4. import java.awt.Point;
  5. import java.awt.Rectangle;
  6. import java.awt.TexturePaint;
  7. import java.awt.Window;
  8. import java.awt.image.BufferedImage;
  9. import java.io.IOException;
  10. import java.util.ArrayList;
  11. import javax.imageio.ImageIO;
  12. public class WalkingPath {
  13. private ArrayList<Point> path;
  14. private DrawEngine object1,object2;
  15. private BufferedImage texture;
  16. public WalkingPath(){
  17. path = new ArrayList<Point>();
  18. try {
  19. texture = ImageIO.read(Window.class.getResource("/ground_stone.jpg"));
  20. } catch (IOException e) {
  21. e.printStackTrace();
  22. }
  23. }
  24. public void addPoint(Point p){
  25. path.add(p);
  26. }
  27. public Point get(int i){
  28. return path.get(i);
  29. }
  30. public ArrayList<Point> getPath() {
  31. return path;
  32. }
  33. public void setPath(ArrayList<Point> path) {
  34. this.path = path;
  35. }
  36. public DrawEngine getObject1() {
  37. return object1;
  38. }
  39. public void setObject1(DrawEngine object1) {
  40. this.object1 = object1;
  41. }
  42. public DrawEngine getObject2() {
  43. return object2;
  44. }
  45. public void setObject2(DrawEngine object2) {
  46. this.object2 = object2;
  47. }
  48. public void reCalculate(){
  49. path.get(0).setLocation(new Point((int)object1.getX(), (int)object1.getY()));
  50. path.get(path.size()-1).setLocation(new Point((int)object2.getX(), (int)object2.getY()));
  51. }
  52. public void paint(Graphics2D g2){
  53. g2.setStroke(new BasicStroke(10));
  54. for(int i = 1; i < getPath().size(); i++){
  55. g2.setPaint(new TexturePaint(texture, new Rectangle(0,0,100,100)));
  56. g2.drawLine((int)get(i-1).getX(),(int)get(i-1).getY(), (int)get(i).getX(),(int)get(i).getY());
  57. }
  58. }
  59. }