Android Open Source - Tanks Game World






From Project

Back to project page Tanks.

License

The source code is released under:

MIT License

If you think the Android project Tanks 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 com.ThirtyNineEighty.Game.Worlds;
/* w w  w  .  j  a  v a2  s .c o  m*/
import android.opengl.Matrix;

import com.ThirtyNineEighty.Game.Collisions.CollisionManager;
import com.ThirtyNineEighty.Game.EngineObject;
import com.ThirtyNineEighty.Game.Gameplay.Characteristics.CharacteristicFactory;
import com.ThirtyNineEighty.Game.Gameplay.Tank;
import com.ThirtyNineEighty.Game.IEngineObject;
import com.ThirtyNineEighty.Game.Menu.GameMenu;
import com.ThirtyNineEighty.Helpers.Vector;
import com.ThirtyNineEighty.Helpers.Vector3;
import com.ThirtyNineEighty.Renderable.Renderable3D.I3DRenderable;
import com.ThirtyNineEighty.System.GameContext;
import com.ThirtyNineEighty.System.IContent;
import com.ThirtyNineEighty.System.ISubprogram;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

public class GameWorld
  implements IWorld
{
  private ArrayList<IEngineObject> objects;
  private IEngineObject player;
  private GameMenu menu;

  private ISubprogram otherTankSubprogram;
  private ISubprogram worldSubprogram;

  public final CollisionManager collisionManager;

  public GameWorld()
  {
    objects = new ArrayList<IEngineObject>();
    collisionManager = new CollisionManager(objects);
  }

  @Override
  public void initialize(Object args)
  {
    menu = new GameMenu();

    player = Tank.Create(CharacteristicFactory.TANK);
    player.onMoved(-20);

    final Tank otherTank = Tank.Create(CharacteristicFactory.TANK);

    EngineObject land = new EngineObject("land", "land", "land");
    land.onMoved(Vector3.zAxis, -0.8f);

    add(player);
    add(land);
    add(otherTank);

    IContent content = GameContext.getContent();

    content.setMenu(menu);
    content.bindProgram(worldSubprogram = new ISubprogram()
    {
      @Override
      public void update()
      {
        if (menu.getForwardState())
          collisionManager.move(player, 5f * GameContext.getDelta());

        Vector3 vector = Vector.getInstance(3);

        if (menu.getLeftState())
        {
          vector.setFrom(0, 0, 45 * GameContext.getDelta());
          collisionManager.rotate(player, vector);
        }

        if (menu.getRightState())
        {
          vector.setFrom(0, 0, -45 * GameContext.getDelta());
          collisionManager.rotate(player, vector);
        }

        Vector.release(vector);
      }
    });

    content.bindProgram(otherTankSubprogram = new ISubprogram()
    {
      @Override
      public void update()
      {
        collisionManager.move(otherTank, 5f * GameContext.getDelta());

        Vector3 vector = Vector.getInstance(3);
        vector.setFrom(0, 0, -45 * GameContext.getDelta());
        collisionManager.rotate(otherTank, vector);

        Vector.release(vector);
      }
    });
  }

  @Override
  public void uninitialize()
  {
    for(IEngineObject object : objects)
      object.onRemoved();

    objects.clear();

    IContent content = GameContext.getContent();
    content.unbindProgram(worldSubprogram);
    content.unbindProgram(otherTankSubprogram);
  }

  @Override
  public void setViewMatrix(float[] viewMatrix)
  {
    Vector3 center = player.getPosition();
    Vector3 eye = Vector.getInstance(3, player.getPosition());

    eye.addToX(0.0f);
    eye.addToY(14.0f);
    eye.addToZ(30);

    Matrix.setLookAtM(viewMatrix, 0, eye.getX(), eye.getY(), eye.getZ(), center.getX(), center.getY(), center.getZ(), 0.0f, 0.0f, 1.0f);

    Vector.release(eye);
  }

  @Override
  public void fillRenderable(List<I3DRenderable> renderables)
  {
    for(IEngineObject engineObject : objects)
      renderables.add(engineObject.getRenderable());
  }

  @Override
  public IEngineObject getPlayer() { return player; }

  @Override
  public Collection<IEngineObject> getObjects() { return objects; }

  @Override
  public void add(IEngineObject engineObject) { objects.add(engineObject); }

  @Override
  public void remove(IEngineObject engineObject)
  {
    objects.remove(engineObject);
    engineObject.onRemoved();
  }
}




Java Source Code List

com.ThirtyNineEighty.Game.EngineObject.java
com.ThirtyNineEighty.Game.IEngineObject.java
com.ThirtyNineEighty.Game.Collisions.Collidable.java
com.ThirtyNineEighty.Game.Collisions.Collision2D.java
com.ThirtyNineEighty.Game.Collisions.Collision3D.java
com.ThirtyNineEighty.Game.Collisions.CollisionManager.java
com.ThirtyNineEighty.Game.Collisions.Collision.java
com.ThirtyNineEighty.Game.Collisions.ICollidable.java
com.ThirtyNineEighty.Game.Gameplay.Bullet.java
com.ThirtyNineEighty.Game.Gameplay.GameObject.java
com.ThirtyNineEighty.Game.Gameplay.Tank.java
com.ThirtyNineEighty.Game.Gameplay.Characteristics.CharacteristicFactory.java
com.ThirtyNineEighty.Game.Gameplay.Characteristics.Characteristic.java
com.ThirtyNineEighty.Game.Gameplay.Characteristics.Upgrade.java
com.ThirtyNineEighty.Game.Menu.BaseMenu.java
com.ThirtyNineEighty.Game.Menu.GameMenu.java
com.ThirtyNineEighty.Game.Menu.IMenu.java
com.ThirtyNineEighty.Game.Menu.Controls.Button.java
com.ThirtyNineEighty.Game.Menu.Controls.IControl.java
com.ThirtyNineEighty.Game.Worlds.GameWorld.java
com.ThirtyNineEighty.Game.Worlds.IWorld.java
com.ThirtyNineEighty.Helpers.Plane.java
com.ThirtyNineEighty.Helpers.Vector2.java
com.ThirtyNineEighty.Helpers.Vector3.java
com.ThirtyNineEighty.Helpers.VectorUtils.java
com.ThirtyNineEighty.Helpers.Vector.java
com.ThirtyNineEighty.Renderable.Renderable.java
com.ThirtyNineEighty.Renderable.Shader2D.java
com.ThirtyNineEighty.Renderable.Shader3D.java
com.ThirtyNineEighty.Renderable.Shader.java
com.ThirtyNineEighty.Renderable.Renderable2D.I2DRenderable.java
com.ThirtyNineEighty.Renderable.Renderable2D.Label.java
com.ThirtyNineEighty.Renderable.Renderable2D.Sprite.java
com.ThirtyNineEighty.Renderable.Renderable3D.I3DRenderable.java
com.ThirtyNineEighty.Renderable.Renderable3D.Model3D.java
com.ThirtyNineEighty.System.ConfigChooser.java
com.ThirtyNineEighty.System.Content.java
com.ThirtyNineEighty.System.GameActivity.java
com.ThirtyNineEighty.System.GameContext.java
com.ThirtyNineEighty.System.IContent.java
com.ThirtyNineEighty.System.ISubprogram.java