code_junkie

Collisions between game objects and the floor with regards to gravity?

Nov 13th, 2011
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. private long previousTime = System.currentTimeMillis();
  2. private long currentTime = previousTime;
  3.  
  4. public void updateGame()
  5. {
  6. currentTime = System.currentTimeMillis();
  7. float elapsedSeconds = (currentTime - previousTime) / 1000f;
  8.  
  9. foreach(GameObject gameObject in gameObjects)
  10. {
  11. // Apply gravity to velocity vector
  12. gameObject.velocity.y += (gravityConstant * elapsedSeconds);
  13.  
  14. // Move objects x/y position based off it's velocity vector
  15. gameObject.position.x += (gameObject.velocity.x * elapsedSeconds);
  16. gameObject.position.y += (gameObject.velocity.y * elapsedSeconds);
  17.  
  18. }
  19.  
  20. checkCollisions();
  21.  
  22. previousTime = currentTime;
  23. }
Add Comment
Please, Sign In to add comment