Android Open Source - DeathRally Vector2 D






From Project

Back to project page DeathRally.

License

The source code is released under:

GNU General Public License

If you think the Android project DeathRally listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package project.gamedev.deathrally.game.model;
/*  w  w w .  ja v a2s. co m*/
/**
 * This represents a two dimensional vector
 * @author Mike Phoohad
 *
 */
public class Vector2D {
  private float x;
  private float y;
  
  public Vector2D(float x,float y){
    this.setX(x);
    this.setY(y);
  }
  
  public float getX() {
    return x;
  }
  
  public void setX(float x) {
    this.x = x;
  }
  
  public float getY() {
    return y;
  }
  
  public void setY(float y) {
    this.y = y;
  }
  
  /**
   * Add a vector this vector
   * @param a Vector2D
   */
  public void add(Vector2D v2d){
    this.setX(this.getX()+v2d.getX());
    this.setY(this.getY()+v2d.getY());
  }
  
  /**
   * Subtract a vector from this vector
   * @param a Vector2D
   */
  public void subtract(Vector2D v2d){
    this.x=this.getX()-v2d.getX();
    this.y=this.getY()-v2d.getY();
  }
  
  @Override
  public int hashCode() {
    final int prime = 31;
    int result = 1;
    result = prime * result + Float.floatToIntBits(x);
    result = prime * result + Float.floatToIntBits(y);
    
    return result;
  }
  @Override
  public boolean equals(Object obj) {
    if (this == obj)
      return true;
    if (obj == null)
      return false;
    if (getClass() != obj.getClass())
      return false;
    Vector2D other = (Vector2D) obj;
    if (Float.floatToIntBits(x) != Float.floatToIntBits(other.getX()))
      return false;
    if (Float.floatToIntBits(y) != Float.floatToIntBits(other.getY()))
      return false;
    
    return true;
  }

  public Vector2D(Vector2D v2d){
    this(v2d.getX(),v2d.getY());
  }
}




Java Source Code List

project.gamedev.deathrally.MainActivity.java
project.gamedev.deathrally.game.DeathRallyGame.java
project.gamedev.deathrally.game.GameLoop.java
project.gamedev.deathrally.game.GameModel.java
project.gamedev.deathrally.game.MainGamePanel.java
project.gamedev.deathrally.game.constants.LevelName.java
project.gamedev.deathrally.game.controls.Joystick.java
project.gamedev.deathrally.game.graphics.Circle.java
project.gamedev.deathrally.game.graphics.Mesh.java
project.gamedev.deathrally.game.graphics.Rectangle.java
project.gamedev.deathrally.game.graphics.Triangle.java
project.gamedev.deathrally.game.model.CollisionEvent.java
project.gamedev.deathrally.game.model.Direction.java
project.gamedev.deathrally.game.model.Entity.java
project.gamedev.deathrally.game.model.GameAction.java
project.gamedev.deathrally.game.model.Hitbox.java
project.gamedev.deathrally.game.model.Level.java
project.gamedev.deathrally.game.model.MovableEntity.java
project.gamedev.deathrally.game.model.Player.java
project.gamedev.deathrally.game.model.Players.java
project.gamedev.deathrally.game.model.Position.java
project.gamedev.deathrally.game.model.Vector2D.java
project.gamedev.deathrally.game.model.VehicleName.java
project.gamedev.deathrally.game.model.VehicleType.java
project.gamedev.deathrally.game.model.Vehicle.java
project.gamedev.deathrally.game.view.GameRenderer.java
project.gamedev.deathrally.game.view.JoystickView.java
project.gamedev.deathrally.game.view.VisualEntity.java
project.gamedev.deathrally.game.view.VisualVehicle.java