Advertisement
Collzi

Ball.java

Oct 4th, 2013
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.70 KB | None | 0 0
  1. package com.collzi.pong.model;
  2.  
  3. import com.badlogic.gdx.Gdx;
  4. import com.badlogic.gdx.math.*;
  5.  
  6. public class Ball {
  7.    
  8.     static final float WIDTH = 14f;
  9.     static final float HEIGHT = 14f;
  10.    
  11.     int angleCheck;
  12.     float angle = 0;
  13.     float speed = 15f;
  14.     float stateTime = 0;
  15.    
  16.     Vector2 velocity = new Vector2();
  17.     Vector2 scale = new Vector2();
  18.     Vector2 position = new Vector2();
  19.     Rectangle bounds = new Rectangle();
  20.    
  21.     public Ball(Vector2 position) {
  22.         this.position = position;
  23.         angleCheck = MathUtils.random(1);
  24.         if (angleCheck == 0)
  25.             angle = -150;
  26.         else
  27.             angle = -30;
  28.        
  29.         this.bounds.width = WIDTH;
  30.         this.bounds.height = HEIGHT;
  31.        
  32.         this.scale.x = MathUtils.cosDeg(angle);
  33.         this.scale.y = MathUtils.sinDeg(angle);
  34.         this.velocity.x = speed * scale.x;
  35.         this.velocity.y = speed * scale.y;
  36.     }
  37.    
  38.     public float getStateTime() { return stateTime; }
  39.     public Vector2 getVelocity() { return velocity; }
  40.     public float getSpeed() { return speed; }
  41.     public Vector2 getPosition() { return position; }
  42.     public Rectangle getBounds() { return bounds; }
  43.     public float getAngle() { return angle; }
  44.    
  45.     public void setBounds(Rectangle bounds) { this.bounds = bounds; }
  46.     public void setStateTime(float stateTime) { this.stateTime = stateTime; }
  47.     public void setVelocity(Vector2 velocity) { this.velocity = velocity; }
  48.     public void setPosition(Vector2 position) { this.position = position; }
  49.     public void setAngle(float angle) { this.angle = angle; }
  50.     public void setSpeed(float speed) { this.speed = speed; }
  51.    
  52.     public void update(float delta) {
  53.         position.add(velocity.cpy().scl(Gdx.graphics.getDeltaTime() * speed));
  54.        
  55.         bounds.x = position.x;
  56.         bounds.y = position.y;
  57.        
  58.         stateTime += delta;
  59.     }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement