ShootingLine.java 976 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package model.objects;
  2. import java.awt.Graphics2D;
  3. import java.awt.Shape;
  4. import java.awt.geom.Path2D;
  5. public class ShootingLine {
  6. private Path2D.Double line;
  7. private int startx,starty, length;
  8. public ShootingLine(int startx, int starty){
  9. line = new Path2D.Double();
  10. this.startx = startx;
  11. this.starty = starty;
  12. }
  13. public void setLength(int length){
  14. line = new Path2D.Double();
  15. line.moveTo(startx, starty);
  16. int tempy = starty;
  17. for(int i = 0; i < length; i++){
  18. line.curveTo(startx + 10, tempy- 10, startx - 10, tempy - 20, startx, tempy-30);
  19. tempy -= 30;
  20. }
  21. this.length = length;
  22. }
  23. public void paint(Graphics2D g2d)
  24. {
  25. g2d.draw(line);
  26. g2d.drawLine(startx, getMaxHeight(), startx+8, getMaxHeight()+15);
  27. g2d.drawLine(startx, getMaxHeight(), startx-8, getMaxHeight()+15);
  28. }
  29. public int getLength(){
  30. return length;
  31. }
  32. public Path2D getLine(){
  33. return line;
  34. }
  35. public int getMaxHeight(){
  36. return starty - length * 30;
  37. }
  38. }