Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Cannonball
- {
- private double xPos = 0.0;
- private double yPos = 0.0;
- private double xVel = 0.0;
- private double yVel = 0.0;
- public Cannonball(double xInitPos)
- {
- this.xPos = xInitPos;
- this.yPos = 0.0;
- }
- public void move(double deltaSec)
- {
- xPos = xVel*deltaSec;
- yPos = yVel*deltaSec + 0.5*(-9.81)*(deltaSec)*(deltaSec);
- yVel = yVel + (-9.81)*(deltaSec);
- }
- public Point getPosition()
- {
- int xPosition = (int) xPos;
- int yPosition = (int) yPos;
- Point pos = new Point(xPosition, yPosition);
- return pos;
- }
- public ArrayList<Point> shoot(double alpha, double v, double deltaSec)
- {
- ArrayList<Point> posArray = new ArrayList<Point>();
- xVel = v * Math.cos(alpha);
- yVel = v * Math.sin(alpha);
- do
- {
- this.move(deltaSec);
- int xPosition = (int) xPos;
- int yPosition = (int) yPos;
- Point pos = new Point(xPosition, yPosition);
- posArray.add(pos);
- }
- while (yPos != 0);
- return posArray;
- }
- }
- public class Point
- {
- public int x;
- public int y;
- public Point()
- {
- x=0; y=0;
- }
- public Point(int xx, int yy)
- {
- x=xx; y=yy;
- }
- public int getX()
- {
- return x;
- }
- public int getY()
- {
- return y;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement