Skip to content

Instantly share code, notes, and snippets.

@Fogest
Created June 10, 2013 22:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Fogest/36aba3e1a7fc30984e4e to your computer and use it in GitHub Desktop.
Save Fogest/36aba3e1a7fc30984e4e to your computer and use it in GitHub Desktop.
package main;
import java.awt.geom.Point2D;
public class GameLogic {
private double time, deltaTime, endTime, x, y, speed, angle, ay, ax, vx, vy;
public GameLogic(double speed, double angle, double accerlationX, double startHeight) {
this.time = 0.0;
this.deltaTime = 0.0001;
this.endTime = 10.0;
this.x = 1.0;
this.y = startHeight;
this.speed = speed;
this.ay = -9.8;
this.angle = angle;
this.ax = accerlationX;
this.vx = this.speed*Math.cos(this.angle*(Math.PI/180.0));
this.vy = this.speed*Math.sin(this.angle*(Math.PI/180.0));
}
public Point2D getPoint() {
time += this.deltaTime;
this.x += this.vx*this.deltaTime;
this.y += this.vy*this.deltaTime;
this.vx += this.ax*this.deltaTime;
this.vy += this.ay*this.deltaTime;
Point2D p = new Point2D.Double(x,y);
return p;
}
public static void main(String[] args) {
GameLogic logic = new GameLogic(60.0, 45.0, 0.0, 10);
while(true)
System.out.println(logic.getPoint().getX() + " " + logic.getPoint().getY());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment