Advertisement
progrmor

Untitled

May 11th, 2014
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. public class Ball {
  2.  
  3. private Vector2 velocity = new Vector2();
  4. private Vector2 position = new Vector2();
  5. private Vector2 movement = new Vector2();
  6. private Vector2 target = new Vector2();
  7. private Vector2 dir = new Vector2();
  8.  
  9. private float speed = 50.0f;
  10.  
  11. private float width;
  12. private float height;
  13.  
  14. public Ball(float x, float y, int width, int height)
  15. {
  16. this.width = 10;
  17. this.height = 10;
  18. position.set(x,y);
  19. velocity.set(0,0);
  20. movement.set(0, 0);
  21. target.set(x, y);
  22. }
  23.  
  24. public void update(float delta)
  25. {
  26. movement.set(velocity).scl(delta);
  27. if (position.dst2(target) > movement.len2()) {
  28. position.add(movement);
  29. } else {
  30. position.set(target);
  31. }
  32. }
  33.  
  34. public void onClick(float x, float y)
  35. {
  36. dir.set(target.set(x,y)).sub(position).nor();
  37. velocity.set(dir).scl(speed);
  38. }
  39.  
  40.  
  41.  
  42. public float getX() {
  43. return position.x;
  44. }
  45.  
  46. public float getY() {
  47. return position.y;
  48. }
  49.  
  50. public float getWidth() {
  51. return width;
  52. }
  53.  
  54. public float getHeight() {
  55. return height;
  56. }
  57.  
  58.  
  59.  
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement