Android Open Source - Tilt-snake Direction






From Project

Back to project page Tilt-snake.

License

The source code is released under:

Apache License

If you think the Android project Tilt-snake 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.awhittle.tiltsnake;
//from  w w  w .  j a va2s . c om
import android.hardware.SensorEvent;

public class Direction {
  
  public static int getDirection(SensorEvent event){
    int dir;
    if (Math.abs(event.values[0]) > Math.abs(event.values[1])){
      if (event.values[0]>0)
        dir = 4;   //Left
      else
        dir = 2;  //Right
    }
    else {
      if (event.values[1]>0)
        dir = 3;  //Bottom
      else
        dir = 1;  //Top
    }
    return dir;
  }

}




Java Source Code List

com.awhittle.tiltsnake.Direction.java
com.awhittle.tiltsnake.Egg.java
com.awhittle.tiltsnake.GameActivity.java
com.awhittle.tiltsnake.Head.java
com.awhittle.tiltsnake.MainActivity.java
com.awhittle.tiltsnake.Movement.java
com.awhittle.tiltsnake.MyGLRenderer.java
com.awhittle.tiltsnake.MyGLSurfaceView.java
com.awhittle.tiltsnake.Saving.java
com.awhittle.tiltsnake.ShapeTools.java
com.awhittle.tiltsnake.Square.java
com.awhittle.tiltsnake.Tail.java