Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. public class Cannonball
  2. {
  3. private double xPos = 0.0;
  4. private double yPos = 0.0;
  5. private double xVel = 0.0;
  6. private double yVel = 0.0;
  7.  
  8. public Cannonball(double xInitPos)
  9. {
  10. this.xPos = xInitPos;
  11. this.yPos = 0.0;
  12. }
  13.  
  14. public void move(double deltaSec)
  15. {
  16. xPos = xVel*deltaSec;
  17. yPos = yVel*deltaSec + 0.5*(-9.81)*(deltaSec)*(deltaSec);
  18. yVel = yVel + (-9.81)*(deltaSec);
  19. }
  20.  
  21. public Point getPosition()
  22. {
  23. int xPosition = (int) xPos;
  24. int yPosition = (int) yPos;
  25. Point pos = new Point(xPosition, yPosition);
  26. return pos;
  27. }
  28.  
  29. public ArrayList<Point> shoot(double alpha, double v, double deltaSec)
  30. {
  31. ArrayList<Point> posArray = new ArrayList<Point>();
  32. xVel = v * Math.cos(alpha);
  33. yVel = v * Math.sin(alpha);
  34. do
  35. {
  36. this.move(deltaSec);
  37. int xPosition = (int) xPos;
  38. int yPosition = (int) yPos;
  39. Point pos = new Point(xPosition, yPosition);
  40. posArray.add(pos);
  41. }
  42. while (yPos != 0);
  43. return posArray;
  44. }
  45. }
  46.  
  47. public class Point
  48. {
  49. public int x;
  50. public int y;
  51.  
  52. public Point()
  53. {
  54. x=0; y=0;
  55. }
  56.  
  57. public Point(int xx, int yy)
  58. {
  59. x=xx; y=yy;
  60. }
  61.  
  62. public int getX()
  63. {
  64. return x;
  65. }
  66.  
  67. public int getY()
  68. {
  69. return y;
  70. }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement