private bool HandleInput()
{
bool sendNewState = false;
if (!(Bricklayer.Client.Interface.MainWindow.ScreenManager.Current as Bricklayer.Client.Interface.GameScreen).ChatBox.TextBox.Focused && !Game.IsMouseOnControl)
{
//Change smilies
if (Game.Input.WasKeyPressed(Keys.Q))
{
Smiley = SmileyType.SmileyList[((Smiley.ID == 0 ? SmileyType.SmileyList.Count : Smiley.ID) - 1) % SmileyType.SmileyList.Count];
Game.NetManager.Send(new PlayerSmileyMessage(this, Smiley));
}
else if (Game.Input.WasKeyPressed(Keys.E))
{
Smiley = SmileyType.SmileyList[(Smiley.ID + 1) % SmileyType.SmileyList.Count];
Game.NetManager.Send(new PlayerSmileyMessage(this, Smiley));
}
if (Game.Input.WasKeyPressed(Keys.G))
{
PlayerMode oldMode = Mode;
if (Mode == PlayerMode.God)
Mode = PlayerMode.Normal;
else if (Mode == PlayerMode.Normal)
Mode = PlayerMode.God;
if (oldMode != Mode)
Game.NetManager.Send(new PlayerModeMessage(this));
}
}
if (Mode == PlayerMode.Normal)
{
//If player enters chat box, stop moving!
if (Game.CurrentGameState == GameState.Game && ((Bricklayer.Client.Interface.MainWindow.ScreenManager.Current as Bricklayer.Client.Interface.GameScreen).ChatBox.TextBox.Focused || Game.IsMouseOnControl))
{
if (SimulationState.Movement != Vector2.Zero)
{
SimulationState.Movement = Vector2.Zero;
return true;
}
if (IsJumping)
{
IsJumping = false;
return true;
}
return false;
}
//Reset
SimulationState.Movement = Vector2.Zero;
//If jump key pressed/released or release/pressed, send message that the velocity has changed
//If the key is down, make sure we are jumping
if (GravityDirection == GravityDirection.Default || GravityDirection == GravityDirection.Down || GravityDirection == GravityDirection.Up)
IsJumping = Game.Input.AnyKeysDown(JumpKeys);
else if (GravityDirection == GravityDirection.Left) //Different keys for different gravity arrows
IsJumping = Game.Input.IsKeyDown(Keys.D) || Game.Input.IsKeyDown(Keys.Space) || Game.Input.IsKeyDown(Keys.Right);
else if (GravityDirection == GravityDirection.Right)
IsJumping = Game.Input.IsKeyDown(Keys.A) || Game.Input.IsKeyDown(Keys.Space) || Game.Input.IsKeyDown(Keys.Left);
//Move right
if (Game.Input.AnyKeysDown(RightKeys))
{
SimulationState.Movement = new Vector2(1, 0);
if (Game.Input.WasAllKeysUp(RightKeys))
sendNewState = true;
}
if (Game.Input.AnyKeysPressed(RightKeys))
{
SimulationState.Movement = new Vector2(0, SimulationState.Movement.Y);
sendNewState = true;
}
//Move left
if (Game.Input.AnyKeysDown(LeftKeys))
{
SimulationState.Movement = new Vector2(-1, 0);
if (Game.Input.WasAllKeysUp(LeftKeys)) sendNewState = true;
}
if (Game.Input.AnyKeysPressed(LeftKeys))
{
SimulationState.Movement = new Vector2(0, SimulationState.Movement.Y);
sendNewState = true;
}
if (GravityDirection == GravityDirection.Left || GravityDirection == GravityDirection.Right)
{
//Move up
if (Game.Input.AnyKeysDown(JumpKeys))
{
SimulationState.Movement = new Vector2(0, -1);
if (Game.Input.WasAllKeysUp(JumpKeys)) sendNewState = true;
}
if (Game.Input.AnyKeysPressed(JumpKeys))
{
SimulationState.Movement = new Vector2(SimulationState.Movement.X, 0);
sendNewState = true;
}
//Move Down
if (Game.Input.AnyKeysDown(DownKeys))
{
SimulationState.Movement = new Vector2(0, 1);
if (Game.Input.WasAllKeysUp(DownKeys)) sendNewState = true;
}
if (Game.Input.AnyKeysPressed(DownKeys))
{
SimulationState.Movement = new Vector2(SimulationState.Movement.X, 0);
sendNewState = true;
}
}
//Fixes a bug caused by quickly switching directions
if ((Game.Input.WasKeyDown(Keys.Left) && Game.Input.WasKeyDown(Keys.Right)) ||
(Game.Input.WasKeyDown(Keys.A) && Game.Input.WasKeyDown(Keys.D)))
{
SimulationState.Movement = new Vector2(1, 0);
sendNewState = true;
}
}
else if (Mode == PlayerMode.God) //Godmode flying
{
//If player enters chat box, stop moving!
if (Game.CurrentGameState == GameState.Game && ((Bricklayer.Client.Interface.MainWindow.ScreenManager.Current as Bricklayer.Client.Interface.GameScreen).ChatBox.TextBox.Focused || Game.IsMouseOnControl))
{
if (SimulationState.Movement != Vector2.Zero)
{
SimulationState.Movement = Vector2.Zero;
return true;
}
return false;
}
SimulationState.Movement = Vector2.Zero;
//Move left
if (Game.Input.AnyKeysDown(LeftKeys))
{
SimulationState.Movement = new Vector2(-1, SimulationState.Movement.Y);
if (Game.Input.WasAllKeysUp(LeftKeys)) sendNewState = true;
}
if (Game.Input.AnyKeysPressed(LeftKeys))
{
SimulationState.Movement = new Vector2(0, SimulationState.Movement.Y);
sendNewState = true;
}
//Move right
if (Game.Input.AnyKeysDown(RightKeys))
{
SimulationState.Movement = new Vector2(1, SimulationState.Movement.Y);
if (Game.Input.WasAllKeysUp(RightKeys)) sendNewState = true;
}
if (Game.Input.AnyKeysPressed(RightKeys))
{
SimulationState.Movement = new Vector2(0, SimulationState.Movement.Y);
sendNewState = true;
}
//Move Up
if (Game.Input.AnyKeysDown(JumpKeys))
{
SimulationState.Movement = new Vector2(SimulationState.Movement.X, -1);
if (Game.Input.WasAllKeysUp(JumpKeys)) sendNewState = true;
}
if (Game.Input.AnyKeysPressed(JumpKeys))
{
SimulationState.Movement = new Vector2(SimulationState.Movement.X, 0);
sendNewState = true;
}
//Move Down
if (Game.Input.AnyKeysDown(DownKeys))
{
SimulationState.Movement = new Vector2(SimulationState.Movement.X, 1);
if (Game.Input.WasAllKeysUp(DownKeys)) sendNewState = true;
}
if (Game.Input.AnyKeysPressed(DownKeys))
{
SimulationState.Movement = new Vector2(SimulationState.Movement.X, 0);
sendNewState = true;
}
}
return sendNewState;
}