Android Open Source - TreeFrogEngine Player






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;
/*from w w  w. j a  v a  2 s  .c  o  m*/
import java.util.Random;

import tv.ouya.console.api.OuyaController;

import com.discretesoftworks.OUYAframework.OuyaGameController;
import com.discretesoftworks.framework.Assets;
import com.discretesoftworks.framework.GameRenderer;
import com.discretesoftworks.framework.MovingObject;

public class Player extends MovingObject{

  private boolean left, right, jump;
  
  private boolean click;
  
  private float acceleration, maxSpeed;
  
  private int pNum;
  
  private Random rand;
  
  public Player(float x, float y, float z, float width, float height) {
    super(x, y, z, width, height, null);
    getModel(0).setSprite(Assets.sprPointer);
    left = false;
    right = false;
    jump = false;
    pNum = TestController.playerNum;
    
    rand = new Random();
    
    click = false;
    
    acceleration = 0.005f;
    maxSpeed = .06f;
  }

  private void grabControllerInfo(OuyaController c){
    
    if (c == null)
      return;
    
    right = false;
    left = false;
    jump = false;
    
    if (c.getButton(OuyaController.BUTTON_O))
      jump = true;
    
    if (c.getButton(OuyaController.BUTTON_Y)){
      if (!click){
        click = true;
        System.out.println(GameRenderer.s_instance.renderObjects.getCompiledData().size());
      }
    } else
      click = false;
    
    if (c.getButton(OuyaController.BUTTON_A)){
      new Floor((rand.nextFloat()*6)-3f, (rand.nextFloat())-0.5f, 0f, 1, 1);
    }
    
    if (!OuyaGameController.stickInDeadzone(c, 1)){
      float xMag = OuyaGameController.getStickValues(c, 1).x;
      if (xMag > 0f)
        right = true;
      else if (xMag < 0f)
        left = true;
    }
  }
  
  @Override
  public void update(float deltaTime) {
    pNum = TestController.playerNum;
    grabControllerInfo(OuyaController.getControllerByPlayer(pNum));
    
    if (left)
      changedx(-acceleration);
    else if (right)
      changedx(acceleration);
    else{
      if (getdx() > 0)
        changedx(-acceleration);
      else if (getdx() < 0)
        changedx(acceleration);
      if (Math.abs(getdx()) < acceleration)
        setdx(0);
    }
    if (getdx() > maxSpeed)
      setdx(maxSpeed);
    else if (getdx() < -maxSpeed)
      setdx(-maxSpeed);
    
    float gravity = -.005f;
    
    if (placeFree(getX(), getY() + gravity)){
      changedy(gravity);
    } else if (jump) {
      setdy(.1f);
    }
    
    moveCheckCollisions(deltaTime);
    
    super.update(deltaTime);
  }
}




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