Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Ball {
- private Vector2 velocity = new Vector2();
- private Vector2 position = new Vector2();
- private Vector2 movement = new Vector2();
- private Vector2 target = new Vector2();
- private Vector2 dir = new Vector2();
- private float speed = 50.0f;
- private float width;
- private float height;
- public Ball(float x, float y, int width, int height)
- {
- this.width = 10;
- this.height = 10;
- position.set(x,y);
- velocity.set(0,0);
- movement.set(0, 0);
- target.set(x, y);
- }
- public void update(float delta)
- {
- movement.set(velocity).scl(delta);
- if (position.dst2(target) > movement.len2()) {
- position.add(movement);
- } else {
- position.set(target);
- }
- }
- public void onClick(float x, float y)
- {
- dir.set(target.set(x,y)).sub(position).nor();
- velocity.set(dir).scl(speed);
- }
- public float getX() {
- return position.x;
- }
- public float getY() {
- return position.y;
- }
- public float getWidth() {
- return width;
- }
- public float getHeight() {
- return height;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement