Android Open Source - game-api-android Debug Engine






From Project

Back to project page game-api-android.

License

The source code is released under:

MIT License

If you think the Android project game-api-android 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 testGames.gameEngineTest;
//  www .ja  v  a  2 s  .c  o  m
import android.gameengine.icadroids.alarms.Alarm;
import android.gameengine.icadroids.alarms.IAlarm;
import android.gameengine.icadroids.engine.GameEngine;
import android.gameengine.icadroids.engine.GameFPSCounter;
import android.gameengine.icadroids.forms.GameForm;
import android.gameengine.icadroids.forms.IFormInput;
import android.gameengine.icadroids.input.TouchInput;
import android.gameengine.icadroids.objects.GameObject;
import android.gameengine.icadroids.objects.MoveableGameObject;
import android.gameengine.icadroids.sound.MusicPlayer;
import android.gameengine.icadroids.tiles.GameTiles;
import android.graphics.Rect;
import android.graphics.RectF;
import android.view.View;
import android.widget.Button;

/**
 * An engine that extends GameEngine that displays a debug menu for debugging
 * objects, alarms, sounds, tiles, life cycle and more.
 * 
 * @author Bas van der Zandt
 * 
 */
public abstract class DebugEngine extends GameEngine implements IFormInput,
    IAlarm {

  public debugObject DO = new debugObject();
  Alarm alm = new Alarm(12345, 10, this);
  GameForm gf;
  boolean paused = false;
  boolean useGameObjectDebug = false;
  Rect clickedPos = new Rect(0, 0, 0, 0);

  public DebugEngine() {
    addGameObject(DO, 0, 0);
  }

  public void formElementClicked(View touchedElement) {
    if (gf.getElementName(touchedElement).equals("opendebugmenu")) {
      gf.showView("debuglayout", this);
      gf.removeView("debugmenuopener");
    }

    if (gf.getElementName(touchedElement).equals("pauseButton")) {
      Button bt = (Button) touchedElement;
      if (!paused) {
        pause();
        bt.setText("Resume");
        paused = true;
      } else {
        resume();
        bt.setText("Pause");
        paused = false;
      }
    }
    if (gf.getElementName(touchedElement).equals("tilesButton")) {
  //    GameTiles.debugMode = !GameTiles.debugMode;
    }
    if (gf.getElementName(touchedElement).equals("soundButton")) {
      MusicPlayer.play("lucas", false);
    }
    if (gf.getElementName(touchedElement).equals("FPSButton")) {
      GameFPSCounter.USE_FPS_COUNTER = !GameFPSCounter.USE_FPS_COUNTER;
    }
    if (gf.getElementName(touchedElement).equals("objectsButton")) {
      DO.renderGameObjects = !DO.renderGameObjects;
    }
    if (gf.getElementName(touchedElement).equals("timersButton")) {
      DO.renderTimers = !DO.renderTimers;
    }
    if (gf.getElementName(touchedElement).equals("backButton")) {
      gf.removeView("debuglayout");
      gf.showView("debugmenuopener", this);
    }
    if (gf.getElementName(touchedElement).equals("buttonDebugGameObject")) {
      useGameObjectDebug = !useGameObjectDebug;
      Button btn = (Button) touchedElement;
      if (useGameObjectDebug) {
        btn.setText("Debug clicked GameObject is on");
      } else {
        btn.setText("Debug clicked GameObject is off");
      }
    }

  }

  @Override
  public void update() {
    super.update();
    if (useGameObjectDebug) {
      if (TouchInput.onPress) {
        clickedPos.set((int)TouchInput.xPos - 15,(int) TouchInput.yPos - 15,
            (int) TouchInput.xPos + 15,(int) TouchInput.xPos + 15);
        if (!findItemAt(clickedPos).isEmpty()) {
          GameObject GOjbect = findItemAt(clickedPos).get(0);
          DO.gob = (MoveableGameObject) GOjbect;
          DO.renderObjectInfo = true;
        }
      }
    } else {
      DO.gob = null;
      DO.renderObjectInfo = false;
    }
  }

  public void triggerAlarm(int alarmID) {
    if (alarmID == 12345) {
      gf = new GameForm("debugmenuopener", this, this);
    }

  }

}




Java Source Code List

android.gameengine.icadroids.alarms.Alarm.java
android.gameengine.icadroids.alarms.IAlarm.java
android.gameengine.icadroids.dashboard.DashboardImageView.java
android.gameengine.icadroids.dashboard.DashboardTextView.java
android.gameengine.icadroids.engine.GameEngine.java
android.gameengine.icadroids.engine.GameFPSCounter.java
android.gameengine.icadroids.engine.GameThread.java
android.gameengine.icadroids.engine.GameView.java
android.gameengine.icadroids.engine.Viewport.java
android.gameengine.icadroids.forms.GameForm.java
android.gameengine.icadroids.forms.IFormInput.java
android.gameengine.icadroids.forms.ViewCreator.java
android.gameengine.icadroids.forms.ViewRemover.java
android.gameengine.icadroids.input.MotionSensor.java
android.gameengine.icadroids.input.OnScreenButton.java
android.gameengine.icadroids.input.OnScreenButtons.java
android.gameengine.icadroids.input.TouchInput.java
android.gameengine.icadroids.objects.GameObject.java
android.gameengine.icadroids.objects.MoveableGameObject.java
android.gameengine.icadroids.objects.collisions.CollidingObject.java
android.gameengine.icadroids.objects.collisions.ICollision.java
android.gameengine.icadroids.objects.collisions.TileCollision.java
android.gameengine.icadroids.objects.graphics.AnimatedSprite.java
android.gameengine.icadroids.objects.graphics.Sprite.java
android.gameengine.icadroids.persistence.GamePersistence.java
android.gameengine.icadroids.sound.GameSound.java
android.gameengine.icadroids.sound.MusicPlayer.java
android.gameengine.icadroids.tiles.GameTiles.java
android.gameengine.icadroids.tiles.Tile.java
com.android.vissenspel.Monster.java
com.android.vissenspel.StrawberryControler.java
com.android.vissenspel.Strawberry.java
com.android.vissenspel.Vis.java
com.android.vissenspel.Vissenkom.java
game.MyAndroidGame.java
testGames.AndroidCraft_demo.java
testGames.FormTest.java
testGames.Player.java
testGames.TestGameBas.java
testGames.TestGameLex.java
testGames.TestGameRoel.java
testGames.gameEngineTest.DebugEngine.java
testGames.gameEngineTest.GameEngineTestGame.java
testGames.gameEngineTest.TestGameObject.java
testGames.gameEngineTest.debugObject.java
testGames.gameEngineTest.randomObject.java
testGames.testGameObjectBas.java
testGames.testGame.java