Android Open Source - TreeFrogEngine Directional






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.framework;
//w  w  w. java  2 s . c  o m
import java.util.ArrayList;

// Holds calculations that may be used by any class.
public abstract class Directional {

  // Gets the x-length of a total length in a given direction.
  public static float lengthDirX(float dir, float dist){
    return (float) Math.sin(Math.toRadians(-dir))*dist;
  }
  
  // Gets the y-length of a total length in a given direction.
  public static float lengthDirY(float dir, float dist){
    return (float) Math.cos(Math.toRadians(-dir))*dist;
  }
  
  // Gets the distance between two points.
  public static float pointDistance(float x1, float y1, float x2, float y2){
    float dx = x2-x1;
    float dy = y2-y1;
    return (float)Math.sqrt(dx*dx + dy*dy);
  }
  
  // Get the direction (in degrees) between two points.
  public static float pointDirection(float x1, float y1, float x2, float y2){
    float axisX = x2-x1;
    float axisY = y2-y1;
    float dir = (float) Math.toDegrees( Math.atan2(-axisX, axisY) );
    return dir;
  }
  
  // Checks collisions between object a and the list of objects b
  // Returns what object a collided with, null if there is no collision
  public static GriddedObject checkAllCollisions(GriddedObject a, ArrayList<GriddedObject> b){
    for (int i = 0; i < b.size(); i++)
      if (checkCollision(a,b.get(i)))
        return b.get(i);
    return null;
  }
  
  // Checks for a collision between object a and object b
  // Returns whether or not there was a collision
  public static boolean checkCollision(GriddedObject a, GriddedObject b){
    int xdist = Math.abs((int)(b.getX() - a.getX()));
    int ydist = Math.abs((int)(b.getY() - a.getY()));
    if ((xdist < a.getWidth()/2+b.getWidth()/2) && (ydist < a.getLength()/2+b.getLength()/2))
      return true;
    return false;
  }
  
}




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