Android Open Source - TreeFrogEngine Test Controller






From Project

Back to project page TreeFrogEngine.

License

The source code is released under:

MIT License

If you think the Android project TreeFrogEngine 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.discretesoftworks.TestGame;
//  w  ww  .  j a v  a  2 s  . c om
import tv.ouya.console.api.OuyaController;
import android.graphics.PointF;

import com.discretesoftworks.OUYAframework.OuyaGameController;
import com.discretesoftworks.framework.View;

public class TestController extends OuyaGameController{

  private View view;
  
  public static int playerNum = 0;
  
  public TestController(){
    view = new View(0,-5.5f,5.5f,0f,0f,0f);
  }
  
  public void init(){
    
    for (int i = 0; i < 4; i++)
      if (OuyaController.getControllerByPlayer(i) != null){
        playerNum = i;
        System.out.println("Using controller "+i+" (0-3)");
        break;
      }
    
    new Player(0, 2f, 0f, 1f, 1f);
    new Floor(0, 0f, 0f, 1, 1);
    new Floor(-1f, 0f, 0f, 1, 1);
    new Floor(1f, 0f, 0f, 1, 1);
    new Floor(-2f, 0f, 0f, 1, 1);
    new Floor(2f, 0f, 0f, 1, 1);
    new Floor(-3f, 1f, 0f, 1, 1);
    new Floor(3f, 1f, 0f, 1, 1);
    new Pointer(0,0,0);
    super.init();
  }
  
  @Override
  public View getView() {
    return view;
  }
  
  private void grabControllerInfo(OuyaController c){
    
    if (c == null)
      return;
    
    if (!OuyaGameController.stickInDeadzone(c, 2)){
      PointF point = OuyaGameController.getStickValues(c, 2);
      view.changeX(point.x/8f);
      view.changeCenterX(point.x/8f);
      view.changeY(-point.y/8f);
      view.changeCenterY(-point.y/8f);
    }
    
    float rTrigger = c.getAxisValue(OuyaController.AXIS_R2);
    float lTrigger = c.getAxisValue(OuyaController.AXIS_L2);
    
    if (lTrigger > .3f && view.getZ() < 20f){
      view.changeY(-.15f * lTrigger);
      view.changeZ( .20f * lTrigger);
    }
    else if (rTrigger > .3f && view.getZ() > 2f){
      view.changeY( .15f * rTrigger);
      view.changeZ(-.20f * rTrigger);
    }
  }

  @Override
  public void update(float deltaTime) {
    for (int i = 0; i < 4; i++)
      if (OuyaController.getControllerByPlayer(i) != null){
        if (OuyaController.getControllerByPlayer(i).getButton(OuyaController.BUTTON_U)){
          if (playerNum != i)
            System.out.println("New controller: "+i);
          playerNum = i;
        }
      }
    grabControllerInfo(OuyaController.getControllerByPlayer(playerNum));
    //view.update(deltaTime);
    super.update(deltaTime);
  }

  @Override
  public void paint() {
  }
}




Java Source Code List

com.discretesoftworks.OUYAframework.OuyaGameController.java
com.discretesoftworks.OUYAframework.OuyaGame.java
com.discretesoftworks.TestGame.Floor.java
com.discretesoftworks.TestGame.Player.java
com.discretesoftworks.TestGame.Pointer.java
com.discretesoftworks.TestGame.TestController.java
com.discretesoftworks.TestGame.TestGame.java
com.discretesoftworks.framework.AndroidGame.java
com.discretesoftworks.framework.Assets.java
com.discretesoftworks.framework.Directional.java
com.discretesoftworks.framework.GameController.java
com.discretesoftworks.framework.GameFont.java
com.discretesoftworks.framework.GameObject.java
com.discretesoftworks.framework.GameRenderer.java
com.discretesoftworks.framework.GriddedObject.java
com.discretesoftworks.framework.ModelLoader.java
com.discretesoftworks.framework.MovingObject.java
com.discretesoftworks.framework.MyGLRenderer.java
com.discretesoftworks.framework.MyGLSurfaceView.java
com.discretesoftworks.framework.NumericalMatrix.java
com.discretesoftworks.framework.Pair.java
com.discretesoftworks.framework.Path.java
com.discretesoftworks.framework.Pool.java
com.discretesoftworks.framework.RaggedDictionary.java
com.discretesoftworks.framework.RenderModel.java
com.discretesoftworks.framework.Sprite.java
com.discretesoftworks.framework.Terrain.java
com.discretesoftworks.framework.TextDisplay.java
com.discretesoftworks.framework.TextHolder.java
com.discretesoftworks.framework.View.java
com.discretesoftworks.networking.NetworkGameController.java
com.discretesoftworks.networking.Writer.java