Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.collzi.pong.model;
- import com.badlogic.gdx.Gdx;
- import com.badlogic.gdx.math.*;
- public class Ball {
- static final float WIDTH = 14f;
- static final float HEIGHT = 14f;
- int angleCheck;
- float angle = 0;
- float speed = 15f;
- float stateTime = 0;
- Vector2 velocity = new Vector2();
- Vector2 scale = new Vector2();
- Vector2 position = new Vector2();
- Rectangle bounds = new Rectangle();
- public Ball(Vector2 position) {
- this.position = position;
- angleCheck = MathUtils.random(1);
- if (angleCheck == 0)
- angle = -150;
- else
- angle = -30;
- this.bounds.width = WIDTH;
- this.bounds.height = HEIGHT;
- this.scale.x = MathUtils.cosDeg(angle);
- this.scale.y = MathUtils.sinDeg(angle);
- this.velocity.x = speed * scale.x;
- this.velocity.y = speed * scale.y;
- }
- public float getStateTime() { return stateTime; }
- public Vector2 getVelocity() { return velocity; }
- public float getSpeed() { return speed; }
- public Vector2 getPosition() { return position; }
- public Rectangle getBounds() { return bounds; }
- public float getAngle() { return angle; }
- public void setBounds(Rectangle bounds) { this.bounds = bounds; }
- public void setStateTime(float stateTime) { this.stateTime = stateTime; }
- public void setVelocity(Vector2 velocity) { this.velocity = velocity; }
- public void setPosition(Vector2 position) { this.position = position; }
- public void setAngle(float angle) { this.angle = angle; }
- public void setSpeed(float speed) { this.speed = speed; }
- public void update(float delta) {
- position.add(velocity.cpy().scl(Gdx.graphics.getDeltaTime() * speed));
- bounds.x = position.x;
- bounds.y = position.y;
- stateTime += delta;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement