package player;

import engine.Game;
import engine.MouseInput;
import hud.RightClickMenu;
import hud.constructionmenu.ConstructionItem;
import interfaces.Directions;
import utils.Utils;

/*  ------------- Nihilne ------------
    * Created by Mitch Weaver - 2016 *
      ~~~~ All Rights Reserved ~~~~ */

public final class MouseMovement implements Directions {

	public static double tempX, tempY, angle;
	
	public static boolean PLACING_STRUCTURE;
	
	public final static void runMouseMovement() {
		if (!Player.collided && (Player.keepWalkingX || Player.keepWalkingY)) {
			
			// MOVE TOWARDS CLICK POINT
			angle = Math.atan2(MouseInput.adjustedClickPos.y - Player.center.y, MouseInput.adjustedClickPos.x - Player.center.x);
			Player.velX = (float)((Math.cos(angle) * Player.WALKING_SPEED) * Utils.sqrtOf2);
			Player.velY = (float)((Math.sin(angle)  * Player.WALKING_SPEED) * Utils.sqrtOf2);
			
			// FACING  /* if not auto-following do to a right-click attack, else it is calc'd in RightClickMenu.tick(); */
			if(!RightClickMenu.OVERRIDE_F){
				int temp = Utils.direction(MouseInput.adjustedClickPos.x, MouseInput.adjustedClickPos.y, Player.center.x, Player.center.y) + (Game.rotation - 1);
				if (temp > 8) temp -= 8;
				Player.facing = temp;
			}
			
			// STOP THE PLAYER WHEN INTERSECTS THE CLICK POINT
			if(Player.bounds.contains(MouseInput.adjustedClickPos)){
				if(PLACING_STRUCTURE){ ConstructionItem.placeStructure(); }
				/* note the refunding of items on key movement has been moved to MouseInput.tick() */
				PLACING_STRUCTURE = Player.keepWalkingX = Player.keepWalkingY = false;
			}
		}
	}

}