protected override void Update(TimeSpan gameTime)
{
if (this.leftJoystick == null || this.rightJoystick == null)
{
return;
}
Input input = WaveServices.Input;
// Player Move
Vector2 moveDirection = this.leftJoystick.Direction;
#region Keyboard move
if (input.KeyboardState.IsConnected)
{
if (input.KeyboardState.IsKeyPressed(Keys.Up))
moveDirection += -Vector2.UnitY;
if (input.KeyboardState.IsKeyPressed(Keys.Down))
moveDirection += Vector2.UnitY;
if (input.KeyboardState.IsKeyPressed(Keys.Left))
moveDirection += -Vector2.UnitX;
if (input.KeyboardState.IsKeyPressed(Keys.Right))
moveDirection += Vector2.UnitX;
}
#endregion
if (!float.IsNaN(moveDirection.X) && !float.IsNaN(moveDirection.Y))
{
float x = this.transform.X + (moveDirection.X * velocity * 60 * (float)gameTime.TotalSeconds);
this.transform.X = MathHelper.Clamp(x, this.virtualScreenManager.LeftEdge + this.borderMargin, this.virtualScreenManager.RightEdge - borderMargin);
float y = this.transform.Y + (moveDirection.Y * velocity * 60 * (float)gameTime.TotalSeconds);
this.transform.Y = MathHelper.Clamp(y, this.virtualScreenManager.TopEdge + this.borderMargin, this.virtualScreenManager.BottomEdge - borderMargin);
float rotation = Vector2.Angle(moveDirection, this.textureDirection);
if (float.IsNaN(rotation))
{
this.transform.Rotation = 0;
}
else
{
this.transform.Rotation = rotation;
}
}
// Player shoot
this.time -= gameTime;
if (this.time <= TimeSpan.Zero)
{
Vector2 rightJoyDirection = this.rightJoystick.Direction;
#region Keyboard move
if (input.KeyboardState.IsConnected)
{
if (input.KeyboardState.IsKeyPressed(Keys.W))
rightJoyDirection += -Vector2.UnitY;
if (input.KeyboardState.IsKeyPressed(Keys.S))
rightJoyDirection += Vector2.UnitY;
if (input.KeyboardState.IsKeyPressed(Keys.A))
rightJoyDirection += -Vector2.UnitX;
if (input.KeyboardState.IsKeyPressed(Keys.D))
rightJoyDirection += Vector2.UnitX;
}
#endregion
Vector2 shootDirection = new Vector2((int)rightJoyDirection.X, (int)rightJoyDirection.Y);
// Create bullet
if (shootDirection != Vector2.Zero)
{
Vector2 ninjaPosition = new Vector2(this.transform.X, this.transform.Y);
this.bulletEmitter.Shoot(ninjaPosition, rightJoyDirection);
SoundsManager.Instance.PlaySound(SoundsManager.SOUNDS.Shoot);
}
this.time = this.shootCadence;
}
}