WalkingPath.java 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. package gui.simulator;
  2. import gui.simulator.facilities.ImageType;
  3. import java.awt.BasicStroke;
  4. import java.awt.Graphics2D;
  5. import java.awt.Point;
  6. import java.awt.Rectangle;
  7. import java.awt.TexturePaint;
  8. import java.io.Serializable;
  9. import java.util.ArrayList;
  10. public class WalkingPath implements Serializable {
  11. private ArrayList<Point> path;
  12. private DrawEngine object1,object2;
  13. private ImageType texture;
  14. public WalkingPath(ImageType itype){
  15. path = new ArrayList<Point>();
  16. texture = itype;
  17. }
  18. public void addPoint(Point p){
  19. path.add(p);
  20. }
  21. public void removeLastPoint(){
  22. if(path.size() != 0){
  23. path.remove(path.size()-1);
  24. }
  25. }
  26. public Point get(int i){
  27. return path.get(i);
  28. }
  29. public ArrayList<Point> getPath() {
  30. return path;
  31. }
  32. public void setPath(ArrayList<Point> path) {
  33. this.path = path;
  34. }
  35. public DrawEngine getObject1() {
  36. return object1;
  37. }
  38. public void setObject1(DrawEngine object1) {
  39. this.object1 = object1;
  40. }
  41. public DrawEngine getObject2() {
  42. return object2;
  43. }
  44. public void setObject2(DrawEngine object2) {
  45. this.object2 = object2;
  46. }
  47. public void reCalculate(){
  48. if(object1 != null && object2 != null){
  49. path.get(0).setLocation(new Point((int)object1.getCenter().getX(), (int)object1.getCenter().getY()));
  50. path.get(path.size()-1).setLocation(new Point((int)object2.getCenter().getX(), (int)object2.getCenter().getY()));
  51. }
  52. }
  53. public void paint(Graphics2D g2){
  54. g2.setStroke(new BasicStroke(30,BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
  55. g2.setPaint(new TexturePaint(Images.getImage(texture), new Rectangle(0,0,100,100)));
  56. for(int i = 1; i < getPath().size(); i++){
  57. g2.drawLine((int)get(i-1).getX(),(int)get(i-1).getY(), (int)get(i).getX(),(int)get(i).getY());
  58. }
  59. }
  60. }