public void TakeDamage(int dmg) { int armorDmg = Math.Min(Armor, dmg); Armor -= armorDmg; int HPdmg = dmg - armorDmg; HP -= HPdmg; if (Owner?.Player?.Equipment[Equipments.Equipment.EquipmentSlot.Armor] != null) { Owner.Player.Equipment[Equipments.Equipment.EquipmentSlot.Armor].Equipment.ArmorHP -= dmg; if (Owner.Player.Equipment[Equipments.Equipment.EquipmentSlot.Armor].Equipment.ArmorHP <= 0) { Owner.Player.Equipment[Equipments.Equipment.EquipmentSlot.Armor].Equipment.Break(); } } if (HPdmg > 0) { Color effectColor; if (Owner.Player != null) { effectColor = Color.DarkRed; } else { effectColor = Color.White; } Effect effect = new Effect("-" + HPdmg.ToString(), effectColor); Owner.AddEffect(effect); } if (HP <= 0) { if (Owner.Player != null) { DeathScreen.Initialize(); GameManager.CurrentState = GameManager.GameState.Dead; } else { GameManager.PlayerObject.Fighter.XP += this.XP; //if (GameManager.Objects.Contains(this.Owner)) //{ // GameManager.Objects.Remove(Owner); //} Owner.dieOnEffectsEnd = true; } } }
public static string GetKeyboardInput() { string state = "none"; try { KeyboardState KeyboardState = Keyboard.GetState(); if (GameManager.CurrentState == Playing) { #region KBInputProcess if (KeyboardState.IsKeyDown(Keys.Left) && !PreviousKeyboardState.IsKeyDown(Keys.Left) && !mapOpen) { state = MoveInput(-1, 0); } if (KeyboardState.IsKeyDown(Keys.Right) && !PreviousKeyboardState.IsKeyDown(Keys.Right) && !mapOpen) { state = MoveInput(1, 0); //OnKeyboardPress.Invoke(1, 0); } if (KeyboardState.IsKeyDown(Keys.Up) && !PreviousKeyboardState.IsKeyDown(Keys.Up) && !mapOpen) { state = MoveInput(0, -1); } if (KeyboardState.IsKeyDown(Keys.Down) && !PreviousKeyboardState.IsKeyDown(Keys.Down) && !mapOpen) { state = MoveInput(0, 1); //OnKeyboardPress.Invoke(0, 1); } if (KeyboardState.IsKeyDown(Keys.D1) && !PreviousKeyboardState.IsKeyDown(Keys.D1)) { GameObject toUse; try { toUse = GameManager.PlayerObject.Player.Inventory[0]; } catch (ArgumentOutOfRangeException) { return("error"); } if (toUse != null) { toUse.Item.Use(); state = "move"; //Skips turn } } if (KeyboardState.IsKeyDown(Keys.D2) && !PreviousKeyboardState.IsKeyDown(Keys.D2)) { GameObject toUse; try { toUse = GameManager.PlayerObject.Player.Inventory[1]; } catch (ArgumentOutOfRangeException) { return("error"); } if (toUse != null) { toUse.Item.Use(); state = "move"; //Skips turn } } if (KeyboardState.IsKeyDown(Keys.D3) && !PreviousKeyboardState.IsKeyDown(Keys.D3)) { GameObject toUse; try { toUse = GameManager.PlayerObject.Player.Inventory[2]; } catch (ArgumentOutOfRangeException) { return("error"); } if (toUse != null) { toUse.Item.Use(); state = "move"; //Skips turn } } if (KeyboardState.IsKeyDown(Keys.D4) && !PreviousKeyboardState.IsKeyDown(Keys.D4)) { GameObject toUse; try { toUse = GameManager.PlayerObject.Player.Inventory[3]; } catch (ArgumentOutOfRangeException) { return("error"); } if (toUse != null) { toUse.Item.Use(); state = "move"; //Skips turn } } if (KeyboardState.IsKeyDown(Keys.F11) && !PreviousKeyboardState.IsKeyDown(Keys.F11)) { GameInstance.graphics.IsFullScreen = !GameInstance.graphics.IsFullScreen; GameInstance.graphics.ApplyChanges(); } if (KeyboardState.IsKeyDown(Keys.G) && !PreviousKeyboardState.IsKeyDown(Keys.G) && !mapOpen) { if (GameManager.PlayerObject.Player.CanPickUp) { foreach (GameObject gameObj in GameManager.Objects) { if (gameObj.Position.x == GameManager.PlayerObject.Position.x && gameObj.Position.y == GameManager.PlayerObject.Position.y && gameObj.Item != null) { gameObj.Item.PickUp(); PreviousKeyboardState = KeyboardState; return("pickup"); } } GameManager.LogWarning("No item to pick up here"); } else { GameManager.LogWarning("You have already lost the ability to pick up objects !"); } } if (KeyboardState.IsKeyDown(Keys.I) && !PreviousKeyboardState.IsKeyDown(Keys.I)) { GameManager.PlayerObject.Player.DisplayInventory(); } if (KeyboardState.IsKeyDown(Keys.Space) && !PreviousKeyboardState.IsKeyDown(Keys.Space)) { foreach (GameObject obj in GameManager.Objects) { if (obj.isStairs && obj.Position.x == GameManager.PlayerObject.Position.x && obj.Position.y == GameManager.PlayerObject.Position.y) { GameManager.NextFloor(); } } } if (KeyboardState.IsKeyDown(Keys.E) && !PreviousKeyboardState.IsKeyDown(Keys.E)) { GameManager.PlayerObject.Player.DisplayEquipment(); } if (KeyboardState.IsKeyDown(Keys.M) && !PreviousKeyboardState.IsKeyDown(Keys.M)) { if (GameManager.PlayerObject.Player.CanMap) { Game1.PlaySFX("SFX_Open_Map_01"); mapOpen = !mapOpen; } } if (KeyboardState.IsKeyDown(Keys.D) && !PreviousKeyboardState.IsKeyDown(Keys.D)) { DeathScreen.Initialize(); GameManager.CurrentState = Dead; } if (KeyboardState.IsKeyDown(Keys.F2) && !PreviousKeyboardState.IsKeyDown(Keys.F2)) { //GameManager.Objects.Add(MobFactory.CreateTower(GameManager.PlayerObject.Position.x, GameManager.PlayerObject.Position.y - 1)); } PreviousKeyboardState = KeyboardState; #endregion } else if (GameManager.CurrentState == GameOver) { if (KeyboardState.IsKeyDown(Keys.Space) && !PreviousKeyboardState.IsKeyDown(Keys.Space)) { GameManager.GoToMainMenu(); } } else { if (KeyboardState.IsKeyDown(Keys.F11) && !PreviousKeyboardState.IsKeyDown(Keys.F11)) { GameInstance.graphics.IsFullScreen = !GameInstance.graphics.IsFullScreen; GameInstance.graphics.ApplyChanges(); } } } catch (System.InvalidOperationException) { Console.Out.WriteLine("Keyboard overload"); state = "ERROR"; } return(state); }