package revert.MainScene;

import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.awt.event.MouseWheelEvent;

import revert.Entities.Actor.Movement;
import revert.Entities.Player;
import revert.MainScene.notifications.PlayerAttackNotification;
import revert.MainScene.notifications.PlayerModeNotification;
import revert.MainScene.notifications.PlayerMovementNotification;

import com.kgp.core.GameController;
import com.kgp.core.GamePanel;
import com.kgp.core.GameState;
import com.kgp.util.Vector2;

/**
 * Main controller class for handling the game input that alters the player in the world
 * @author Nicholas Hydock
 *
 */
public class Controller extends GameController {

	Player player;
	Crosshair cross;
	
	GamePanel panel;
	World world;

	/**
	 * Creates a game controller that interacts directly with the player
	 * 
	 * @param p
	 * @param c
	 */
	public Controller(Player p, Crosshair c, GamePanel panel, World world) {
		this.player = p;
		this.cross = c;
		this.panel = panel;
		this.world = world;
	}

	public void mouseMoved(MouseEvent e) {
		int x = e.getX();
		int y = e.getY();
		
		Vector2 v = new Vector2(x, y);
		v.x -= panel.getWidth()/2f;
		v.x += player.getXPosn();
		v.y -= panel.getHeight()/2f;
		v.y += player.getYPosn() - player.getHeight()/2f;
		
		this.player.lookAt(v);
	}

	public void keyPressed(KeyEvent e) {
		int keyCode = e.getKeyCode();
		// game-play keys
		if (panel.getState() == GameState.Active) {
			PlayerMovementNotification note = null;
			// move the sprite and ribbons based on the arrow key pressed
			if (keyCode == KeyEvent.VK_LEFT || keyCode == KeyEvent.VK_A )
			{
				note = new PlayerMovementNotification(Movement.Left);
				setChanged();
			}
			else if (keyCode == KeyEvent.VK_RIGHT || keyCode == KeyEvent.VK_D )
			{
				note = new PlayerMovementNotification(Movement.Right);
				setChanged();
			}
			else if (keyCode == KeyEvent.VK_UP || keyCode == KeyEvent.VK_W || keyCode == KeyEvent.VK_SPACE)
			{
				note = new PlayerMovementNotification(true);
				setChanged();
			}
			
			this.notifyObservers(note);
		}
	}

	public void keyReleased(KeyEvent e) {
		int keyCode = e.getKeyCode();
		
		Object note = null;
		
		/*
		 * Set attack modes
		 */
		if (keyCode == KeyEvent.VK_SHIFT) {
			note = new PlayerModeNotification(true);
			setChanged();
		} 
		else if (keyCode == KeyEvent.VK_1) {
			note = new PlayerModeNotification(0);
			setChanged();
		} 
		else if (keyCode == KeyEvent.VK_2) {
			note = new PlayerModeNotification(1);
			setChanged();
		} 
		else if (keyCode == KeyEvent.VK_3) {
			note = new PlayerModeNotification(2);
			setChanged();
		}
		else if (keyCode == KeyEvent.VK_LEFT || keyCode == KeyEvent.VK_A || keyCode == KeyEvent.VK_RIGHT || keyCode == KeyEvent.VK_D  )
		{
			note = new PlayerMovementNotification(Movement.Still);
			setChanged();
			System.out.println("gah");
		}

		this.notifyObservers(note);
	}

	@Override
	public void mouseWheelMoved(MouseWheelEvent e) {
		//scroll through attack modes
		PlayerModeNotification note = null;
		if (e.getWheelRotation() < 0)
		{
			note = new PlayerModeNotification(false);
			setChanged();
		}
		else if (e.getWheelRotation() > 0)
		{
			note = new PlayerModeNotification(true);
			setChanged();
		}
		this.notifyObservers(note);

	}
	
	public void mouseReleased(MouseEvent e){
		if (e.getButton() == MouseEvent.BUTTON1)
		{
			//mouse clicked to fire a bullet
			this.setChanged();
			this.notifyObservers(new PlayerAttackNotification());
		}
	}
}

@@ -2051,16 +2051,172 @@
 );%0A%09%09%09%7D%0A
+%09%09%09else if (keyCode == KeyEvent.VK_S %7C%7C keyCode == KeyEvent.VK_DOWN)%0A%09%09%09%7B%0A%09%09%09%09note = new PlayerMovementNotification(Movement.Still);%0A%09%09%09%09setChanged();%0A%09%09%09%7D%0A
 %09%09%09%0A%09%09%09t
@@ -2783,32 +2783,37 @@
 tChanged();%0A%09%09%7D%0A
+%09%09/*%0A
 %09%09else if (keyCo
@@ -3038,16 +3038,21 @@
 h%22);%0A%09%09%7D
+%0A%09%09*/
 %0A%0A%09%09this

Revert controller scheme for movement