package u;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.math.Vector3;

public class UsefulMethods {

	public UsefulMethods() {
	}

	public static Vector2 GetDirection(Vector2 startPoint, Vector2 endPoint) {
		Vector2 sp = new Vector2(startPoint);// for some reason if i didn't initialize these, it was altering the values I passed into here! :O
		Vector2 ep = new Vector2(endPoint);
		return ep.sub(sp).nor();
	}

	public static float GetDistance(Vector2 startPoint, Vector2 endPoint) {
		return Vector2.dst(startPoint.x, startPoint.y, endPoint.x, endPoint.y);
	}

	public static boolean IsMouseInsideRectangle(Rectangle r, OrthographicCamera camera) {
		Vector3 touchPos = new Vector3(Gdx.input.getX(), Gdx.input.getY(), 0);
		camera.unproject(touchPos);

		if (r.contains(touchPos.x, touchPos.y))
			return true;
		else
			return false;
	}

	public static int MoveCameraAroundRandomly(OrthographicCamera camera) {
		MoveCameraAroundRandomly(camera, 4, 5);
		return 0;
	}

	public static void MoveCameraAroundRandomly(OrthographicCamera camera, int minJitter, int maxJitter) {
		int randomDir = MathUtils.random(0, 4);// 0-8, should yield 4 directions... It doesn't seem to.... :O
		int _minJitter = minJitter;
		int _maxJitter = maxJitter;
		if (randomDir == 0)
			camera.position.x += MathUtils.random(_minJitter, _maxJitter);
		else if (randomDir == 1)
			camera.position.x -= MathUtils.random(_minJitter, _maxJitter);
		else if (randomDir == 2)
			camera.position.y += MathUtils.random(_minJitter, _maxJitter);
		else if (randomDir == 3)
			camera.position.y -= MathUtils.random(_minJitter, _maxJitter);
		else if (randomDir == 4) {
			camera.position.x += MathUtils.random(_minJitter, _maxJitter);
			camera.position.y += MathUtils.random(_minJitter, _maxJitter);
		} else {// this is 6 directional options? Man, what kind of camera random mover are you? haha
			camera.position.x += MathUtils.random(_minJitter, _maxJitter);
			camera.position.y -= MathUtils.random(_minJitter, _maxJitter);
		}
	}

}
