protected override void Update(GameTime gameTime) { // Get the current keyboard state. this.newKBState = Keyboard.GetState(); if (CheckKeys(Keys.Escape)) { Exit(); } if (!this.gameOver) { if (!waitPlayerAction) { foreach (GameUnit unit in unitList) { unit.Energy += unit.Speed; } } foreach (GameUnit unit in unitList) { if (unit is Enemy) { (unit as Enemy).StartBattleIfInRange(this.map); } if (unit.Health <= 0) { if (unit is IPlayer) { this.gameOver = true; InfoPanel.AddInfo("Game Over! You are dead"); } else { string item = (unit as Enemy).ItemToDrop(); Tools.PlaceObjectOnMap(item, this.map, unit.Position); this.map.Tiles[unit.Position.X, unit.Position.Y].Actor = null; unitsToRemoveList.Add(unit); InfoPanel.AddInfo(unit.Name + " is dead!"); } } } foreach (var unitForRemove in unitsToRemoveList) { unitList.Remove(unitForRemove); } // Sort units in list by their energy. unitList.Sort((x, y) => x.Energy.CompareTo(y.Energy)); foreach (GameUnit unit in unitList) { //unit.Energy += unit.Speed; if (unit.Energy >= MIN_TURN_COST) { if (unit is IPlayer) { waitPlayerAction = true; #region Keys Check // Horizonta/Vertical movement if (CheckKeys(Keys.Down, Keys.NumPad2)) { this.player.Move(CardinalDirection.South); this.player.Energy -= 100; this.player.UpdateMana(); this.player.DeactivateShield(); waitPlayerAction = false; } if (CheckKeys(Keys.Up, Keys.NumPad8)) { this.player.Move(CardinalDirection.North); this.player.Energy -= 100; this.player.UpdateMana(); this.player.DeactivateShield(); waitPlayerAction = false; } if (CheckKeys(Keys.Left, Keys.NumPad4)) { this.player.Move(CardinalDirection.West); this.player.Energy -= 100; this.player.UpdateMana(); this.player.DeactivateShield(); waitPlayerAction = false; } if (CheckKeys(Keys.Right, Keys.NumPad6)) { this.player.Move(CardinalDirection.East); this.player.Energy -= 100; this.player.UpdateMana(); this.player.DeactivateShield(); waitPlayerAction = false; } //Diagonal movement if (CheckKeys(Keys.NumPad7)) { this.player.Move(CardinalDirection.NorthWest); this.player.Energy -= 100; this.player.UpdateMana(); this.player.DeactivateShield(); waitPlayerAction = false; } if (CheckKeys(Keys.NumPad9)) { this.player.Move(CardinalDirection.NorthEast); this.player.Energy -= 100; this.player.UpdateMana(); this.player.DeactivateShield(); waitPlayerAction = false; } if (CheckKeys(Keys.NumPad1)) { this.player.Move(CardinalDirection.SouthWest); this.player.Energy -= 100; this.player.UpdateMana(); this.player.DeactivateShield(); waitPlayerAction = false; } if (CheckKeys(Keys.NumPad3)) { this.player.Move(CardinalDirection.SouthEast); this.player.Energy -= 100; this.player.UpdateMana(); this.player.DeactivateShield(); waitPlayerAction = false; } // Space -> Use/Equip if (CheckKeys(Keys.Space)) { if (this.map.Tiles[this.player.Position.X, this.player.Position.Y].Item is Drink) { this.player.UseItem(this.map.Tiles[this.player.Position.X, this.player.Position.Y].Item as IDrinkable); this.map.Tiles[this.player.Position.X, this.player.Position.Y].Item = null; } if (this.map.Tiles[this.player.Position.X, this.player.Position.Y].Item is Equip) { IEquipable itemToEquip = this.map.Tiles[this.player.Position.X, this.player.Position.Y].Item as IEquipable; IEquipable itemToDrop = (this.player as IPlayer).EquipedItems[itemToEquip.Slot]; this.player.EquipItem(itemToEquip); this.map.Tiles[this.player.Position.X, this.player.Position.Y].Item = itemToDrop; } } if (CheckKeys(Keys.H)) { (this.player as Player).Heal(); } if (CheckKeys(Keys.D)) { (this.player as Player).Shield(); } #endregion } else { //AI if (!waitPlayerAction) { unit.Move(Tools.RandomDirection()); unit.Energy -= 100; } } } } } // Set the old keyboard state this.oldKBState = this.newKBState; base.Update(gameTime); }