Android Open Source - Tanks Content






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.System;
//from  w w  w . ja v a 2  s.  com
import java.util.ArrayList;

import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;

import com.ThirtyNineEighty.Game.Menu.IMenu;
import com.ThirtyNineEighty.Game.Worlds.GameWorld;
import com.ThirtyNineEighty.Game.Worlds.IWorld;
import com.ThirtyNineEighty.Renderable.Renderable;
import com.ThirtyNineEighty.Renderable.Renderable2D.I2DRenderable;
import com.ThirtyNineEighty.Renderable.Renderable3D.I3DRenderable;
import com.ThirtyNineEighty.Renderable.Shader;

import android.opengl.GLES20;
import android.opengl.GLSurfaceView;
import android.opengl.Matrix;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;

public class Content
  implements IContent,
             GLSurfaceView.Renderer,
             View.OnTouchListener
{
  private boolean initialized = false;

  private float[] viewMatrix;
  private float[] projectionMatrix;
  private float[] projectionViewMatrix;
  private float[] lightPosition;

  private float[] orthoMatrix;

  private IWorld world;
  private IMenu menu;
  private ArrayList<ISubprogram> subprograms;

  private ArrayList<I3DRenderable> renderable3DObjects;
  private ArrayList<I2DRenderable> renderable2DObjects;

  public Content()
  {
    lightPosition = new float[] { 0.0f, 0.0f, 12.0f };

    viewMatrix = new float[16];
    projectionMatrix = new float[16];
    projectionViewMatrix = new float[16];

    orthoMatrix = new float[16];

    subprograms = new ArrayList<ISubprogram>();
    renderable3DObjects = new ArrayList<I3DRenderable>();
    renderable2DObjects = new ArrayList<I2DRenderable>();
  }

  //region IContent

  @Override
  public void setWorld(IWorld value) { setWorld(value, null); }

  @Override
  public void setWorld(IWorld value, Object args)
  {
    if (world != null)
      world.uninitialize();

    world = value;
    world.initialize(args);
  }

  @Override
  public IWorld getWorld() { return world; }

  @Override
  public void setMenu(IMenu value) { setMenu(value, null); }

  @Override
  public void setMenu(IMenu value, Object args)
  {
    if (menu != null)
      menu.uninitialize();

    menu = value;
    menu.initialize(args);
  }

  @Override
  public IMenu getMenu() { return menu; }

  @Override
  public void bindProgram(ISubprogram subprogram) { subprograms.add(subprogram); }

  @Override
  public void unbindProgram(ISubprogram subprogram) { subprograms.add(subprogram); }

  //endregion

  @Override
  public boolean onTouch(View v, MotionEvent event)
  {
    return initialized && menu.processEvent(event);
  }

  public void onUpdate()
  {
    if (!initialized)
      return;

    for (ISubprogram subprogram : subprograms)
      subprogram.update();
  }

  //region Renderer

  @Override
  public void onDrawFrame(GL10 gl)
  {
    if (!initialized)
      return;

    GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);

    renderable3DObjects.clear();

    if (world != null)
      world.fillRenderable(renderable3DObjects);

    if (renderable3DObjects.size() != 0)
    {
      world.setViewMatrix(viewMatrix);
      Matrix.perspectiveM(projectionMatrix, 0, 60.0f, GameContext.getAspect(), 0.1f, 50.0f);
      Matrix.multiplyMM(projectionViewMatrix, 0, projectionMatrix, 0, viewMatrix, 0);

      Shader.setShader3D();

      for (I3DRenderable renderable : renderable3DObjects)
        renderable.draw(projectionViewMatrix, lightPosition);
    }

    renderable2DObjects.clear();

    if (menu != null)
      menu.fillRenderable(renderable2DObjects);

    if (renderable2DObjects.size() != 0)
    {
      Matrix.setIdentityM(orthoMatrix, 0);
      Matrix.orthoM(orthoMatrix, 0, GameContext.Left, GameContext.Right, GameContext.Bottom, GameContext.Top, -1, 1);

      Shader.setShader2D();

      for (I2DRenderable renderable : renderable2DObjects)
        renderable.draw(orthoMatrix);
    }

    int error = GLES20.glGetError();
    if (error != GLES20.GL_NO_ERROR)
      Log.e("Error", "OpenGL error. Code: " + Integer.toString(error));
  }
  
  @Override
  public void onSurfaceChanged(GL10 gl, int width, int height)
  {
    GameContext.setWidth(width);
    GameContext.setHeight(height);

    GLES20.glEnable(GLES20.GL_CULL_FACE);
    GLES20.glEnable(GLES20.GL_DEPTH_TEST);
    GLES20.glEnable(GLES20.GL_BLEND);
    GLES20.glDepthFunc(GLES20.GL_LEQUAL);
    GLES20.glBlendFunc(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE_MINUS_SRC_ALPHA);
    GLES20.glViewport(0, 0, width, height);

    Shader.initShader3D();
    Shader.initShader2D();

    Renderable.clearCache();

    setWorld(new GameWorld());

    initialized = true;

    int error = GLES20.glGetError();
    if (error != GLES20.GL_NO_ERROR)
      Log.e("Error", "OpenGL error. Code: " + Integer.toString(error));
  }

  @Override
  public void onSurfaceCreated(GL10 gl, EGLConfig config)
  {

  }

  //endregion
}




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