Advertisement
Collzi

Player.java

Oct 4th, 2013
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.32 KB | None | 0 0
  1. package com.collzi.pong.model;
  2.  
  3. import com.badlogic.gdx.Gdx;
  4. import com.badlogic.gdx.math.Vector2;
  5. import com.badlogic.gdx.math.Rectangle;
  6.  
  7. public class Player {
  8.    
  9.     static final float WIDTH = 13f;
  10.     static final float HEIGHT = 80f;
  11.     static final float SPEED = 205f;
  12.     float stateTime = 0;
  13.    
  14.     Vector2 velocity = new Vector2();
  15.     Vector2 position = new Vector2();
  16.     Rectangle bounds = new Rectangle();
  17.        
  18.     public Player(Vector2 position) {
  19.         this.position = position;
  20.         this.bounds.width = WIDTH;
  21.         this.bounds.height = HEIGHT;
  22.     }
  23.    
  24.     public float getStateTime() { return stateTime; }
  25.     public Vector2 getVelocity() { return velocity; }
  26.     public Rectangle getBounds() { return bounds; }
  27.     public Vector2 getPosition() { return position; }
  28.     public float getWidth() { return bounds.width; }
  29.     public float getHeight() { return bounds.height; }
  30.  
  31.     public void setStateTime(float stateTime) { this.stateTime = stateTime; }
  32.     public void setVelocity(Vector2 velocity) { this.velocity = velocity; }
  33.     public void setPosition(Vector2 position) { this.position = position; }
  34.     public void setBounds(Rectangle bounds) { this.bounds = bounds; }
  35.     public void update(float delta) {
  36.         position.add(velocity.cpy().scl(Gdx.graphics.getDeltaTime() * SPEED));
  37.        
  38.         bounds.x = position.x;
  39.         bounds.y = position.y;
  40.        
  41.         stateTime += delta;
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement