Android Open Source - SimpleGame Dynamic Object






From Project

Back to project page SimpleGame.

License

The source code is released under:

GNU General Public License

If you think the Android project SimpleGame 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 ru.rs.gameobjects;
//from   ww  w . ja  v  a2 s .  co m
import ru.rs.Updateable;
import ru.rs.interfaces.Game;
import ru.rs.objects.math.Vector;

public abstract class DynamicObject extends SimpleObject implements Updateable {
  private Vector velocity;
  private float speed;
  private Vector limit;

  public DynamicObject(Side side, Game game) {
    super(side, game);
    speed = 1.2f;
    if (Side.ENEMY.equals(side)) {
      velocity = new Vector(-1, 0);
      limit = new Vector(0, 0);
    } else if (Side.ALLY.equals(side)) {
      velocity = new Vector(1, 0);
      limit = new Vector(
          game.getGraphics().getWidth() - image.getWidth(), 0);
    }
    velocity.mul(speed);
  }

  public void update() {
    if (Math.abs(position.x - limit.x) > speed) {
      this.position.add(velocity);
    }
  }

}




Java Source Code List

ru.rs.Resources.java
ru.rs.SimpleGame.java
ru.rs.gameobjects.Castle.java
ru.rs.gameobjects.DynamicObject.java
ru.rs.gameobjects.GeneralGrid.java
ru.rs.gameobjects.Side.java
ru.rs.gameobjects.SimpleGameWorld.java
ru.rs.gameobjects.SimpleObject.java
ru.rs.gameobjects.Unit.java
ru.rs.screens.CollisionScreen.java
ru.rs.screens.LoadingScreen.java
ru.rs.screens.MenuScreen.java