Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class GameObject {
- public final Vector2 position;
- public final Rectangle bounds;
- public GameObject (float x, float y, float width, float height) {
- this.position = new Vector2(x, y);
- this.bounds = new Rectangle(x - width / 2, y - height / 2, width, height);
- }
- public class DynamicGameObject extends GameObject {
- protected static Vector2 velocity;
- public final Vector2 accel;
- public DynamicGameObject (float x, float y, float width, float height) {
- super(x, y, width, height);
- setVelocity(new Vector2());
- accel = new Vector2();
- }
- public Vector2 getVelocity() {
- return velocity;
- }
- public void setVelocity(Vector2 velocity) {
- DynamicGameObject.velocity = velocity;
- }
- }
- public Ruben (float x, float y) {
- super(x, y, RUBEN_WIDTH, RUBEN_HEIGHT);
- state = RUBEN_STATE_IDLE;
- stateTime = 0;
- grounded = true;
- facingRight = true;
- }
- public void update (float deltaTime) {
- //getVelocity().add(World.gravity.x * deltaTime, World.gravity.y * deltaTime);
- position.add(velocity.x * deltaTime, velocity.y * deltaTime);
- bounds.x = position.x - bounds.width / 2;
- bounds.y = position.y - bounds.height / 2;
- if (position.x < 0) position.x = World.WORLD_WIDTH;
- if (position.x > World.WORLD_WIDTH) position.x = 0;
- stateTime += deltaTime;
- }
- private void updateRuben (float deltaTime, float accelX) {
- if (ruben.getState() != Ruben.RUBEN_STATE_IDLE && ruben.position.y <= 0.5f) ruben.hitPlatform();
- if (ruben.getState() != Ruben.RUBEN_STATE_IDLE) ruben.getVelocity().x = -accelX / 10 * Ruben.RUBEN_MOVE_VELOCITY;
- // clamp the velocity to the maximum, x-axis only
- if (Math.abs(ruben.getVelocity().x) > Ruben.RUBEN_MAX_VELOCITY) {
- ruben.getVelocity().x = Math.signum(ruben.getVelocity().x) * Ruben.RUBEN_MAX_VELOCITY;
- }
- // clamp the velocity to 0 if it's < 1, and set the state to standing
- if (Math.abs(ruben.getVelocity().x) < 1) {
- ruben.getVelocity().x = 0;
- if (Ruben.isGrounded()) {
- Ruben.setState(Ruben.RUBEN_STATE_IDLE);
- }
- }
- ruben.getVelocity().scl(deltaTime);
- ruben.update(deltaTime);
- heightSoFar = Math.max(ruben.position.y, heightSoFar);
- }
- (GestureDetector gd = new GestureDetector(new GestureHandler(this));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement