/// <summary> /// Update IO class /// </summary> /// <param name="gameTime">GameTime</param> public void Update(GameTime gameTime) { keyStateNow = Keyboard.GetState(); mouseStateNow = Mouse.GetState(); //position of mouse with scale int stateX = (int)((float)mouseStateNow.X / Game.ScaleWindow); int stateY = (int)((float)mouseStateNow.Y / Game.ScaleWindow); // ===== Keyboard Update ===== if (keyStateNow.IsKeyDown(Keys.Escape)) game.Exit(); else if (keyStateNow.IsKeyDown(Keys.F4) && keyStateLast.IsKeyUp(Keys.F4)) game.ChangeFullScreen(); else if (keyStateNow.IsKeyDown(Keys.H) && keyStateLast.IsKeyUp(Keys.H)) map.hero.ApplyPotion(TileType.HealthPotion); else if (keyStateNow.IsKeyDown(Keys.M) && keyStateLast.IsKeyUp(Keys.M)) map.hero.ApplyPotion(TileType.ManaPotion); else if (keyStateNow.IsKeyDown(Keys.F2) && keyStateLast.IsKeyUp(Keys.F2)) game.DoubleScreen(); else if (keyStateNow.IsKeyDown(Keys.Space) && keyStateLast.IsKeyUp(Keys.Space)) referee.AddMagicToHeroSlot(); #region NumberKeyboard else if (keyStateNow.IsKeyDown(Keys.D1) && keyStateLast.IsKeyUp(Keys.D1)) { int index = 0; if (map.hero.Magics[index] != MagicType.Empty && map.hero.ManaCurrent >= map.hero.CostMagic(map.hero.Magics[index])) { CurrentMagicIndex = index; if (referee.ApplyMagic(map.hero.Magics[CurrentMagicIndex], -1, -1)) CurrentMagicIndex = -1; } } else if (keyStateNow.IsKeyDown(Keys.D2) && keyStateLast.IsKeyUp(Keys.D2)) { int index = 1; if (map.hero.Magics[index] != MagicType.Empty && map.hero.ManaCurrent >= map.hero.CostMagic(map.hero.Magics[index])) { CurrentMagicIndex = index; if (referee.ApplyMagic(map.hero.Magics[CurrentMagicIndex], -1, -1)) CurrentMagicIndex = -1; } } else if (keyStateNow.IsKeyDown(Keys.D3) && keyStateLast.IsKeyUp(Keys.D3)) { int index = 2; if (map.hero.Magics[index] != MagicType.Empty && map.hero.ManaCurrent >= map.hero.CostMagic(map.hero.Magics[index])) { CurrentMagicIndex = index; if (referee.ApplyMagic(map.hero.Magics[CurrentMagicIndex], -1, -1)) CurrentMagicIndex = -1; } } else if (keyStateNow.IsKeyDown(Keys.D4) && keyStateLast.IsKeyUp(Keys.D4)) { int index = 3; if (map.hero.Magics[index] != MagicType.Empty && map.hero.ManaCurrent >= map.hero.CostMagic(map.hero.Magics[index])) { CurrentMagicIndex = index; if (referee.ApplyMagic(map.hero.Magics[CurrentMagicIndex], -1, -1)) CurrentMagicIndex = -1; } } else if (keyStateNow.IsKeyDown(Keys.D5) && keyStateLast.IsKeyUp(Keys.D5)) { int index = 4; if (map.hero.Magics[index] != MagicType.Empty && map.hero.ManaCurrent >= map.hero.CostMagic(map.hero.Magics[index])) { CurrentMagicIndex = index; if (referee.ApplyMagic(map.hero.Magics[CurrentMagicIndex], -1, -1)) CurrentMagicIndex = -1; } } #endregion //===== Mouse Update ===== //mouse click if (mouseStateNow.LeftButton == ButtonState.Pressed && mouseStateLast.LeftButton == ButtonState.Released) { //choose one magic if (CurrentMagicIndex != -1) { //chosen CONVERTER if (buttonMagic[CurrentMagicIndex].Parameter == MagicType.Converter) { for (int i = 0; i < buttonMagic.Length; ++i) { if (buttonMagic[i] != null && buttonMagic[i].Rectangle.Contains(stateX, stateY)) { referee.ApplyMagic(map.hero.Magics[CurrentMagicIndex], i, stateY); break; } } } //not CONVERTER, apply magic, if posible else if (stateX >= 0 && stateY >= 0 && stateX < Constants.MAP_SIZE * Constants.TEXTURE_SIZE && stateY < Constants.MAP_SIZE * Constants.TEXTURE_SIZE && map.visible[stateX / Constants.TEXTURE_SIZE, stateY / Constants.TEXTURE_SIZE] != 0) referee.ApplyMagic(map.hero.Magics[CurrentMagicIndex], stateX, stateY); CurrentMagicIndex = -1; } else MouseClick(stateX, stateY); } //not mouse click switch (map.GameState) { #region case GameState.Menu case GameState.Menu: //===== information ===== bool cleanString = true; //if button of race under cursor for (int i = 0; i < buttonRaces.Count; ++i) { if (buttonRaces[i].Rectangle.Contains(stateX, stateY)) { if (buttonRaces[i].Invisible) { switch (buttonRaces[i].Parameter) { case Race.Gnome: InformationInMenu = localization.Get("RACE_INVISIBLE_GNOME"); break; case Race.Goblin: InformationInMenu = localization.Get("RACE_INVISIBLE_GOBLIN"); break; case Race.Orc: InformationInMenu = localization.Get("RACE_INVISIBLE_ORC"); break; } } else { InformationInMenu = localization.Get("RACE_" + (i + 1)); InformationInMenu += " " + localization.Get("CONVERT_SKILL_STRING") + "\n"; InformationInMenu += localization.Get("CONVERT_BONUS_" + (i + 1)); } cleanString = false; } } //if button of class under cursor for (int i = 0; i < buttonClass.Count; ++i) { if (buttonClass[i].Rectangle.Contains(stateX, stateY)) { if (buttonClass[i].Invisible) { switch (buttonClass[i].Parameter) { case Class.Berserker: InformationInMenu = localization.Get("CLASS_INVISIBLE_BERSERKER"); break; case Class.Rogue: InformationInMenu = localization.Get("CLASS_INVISIBLE_ROGUE"); break; case Class.Monk: InformationInMenu = localization.Get("CLASS_INVISIBLE_MONK"); break; case Class.Sorcerer: InformationInMenu = localization.Get("CLASS_INVISIBLE_SORCERER"); break; case Class.Warlord: InformationInMenu = localization.Get("CLASS_INVISIBLE_WARLORD"); break; case Class.Assassin: InformationInMenu = localization.Get("CLASS_INVISIBLE_ASSASSIN"); break; case Class.Paladin: InformationInMenu = localization.Get("CLASS_INVISIBLE_PALADIN"); break; case Class.Bloodmage: InformationInMenu = localization.Get("CLASS_INVISIBLE_BLOODMAGE"); break; case Class.Transmuter: InformationInMenu = localization.Get("CLASS_INVISIBLE_TRANSMUTER"); break; case Class.Crusader: InformationInMenu = localization.Get("CLASS_INVISIBLE_CRUSADER"); break; case Class.Tinker: InformationInMenu = localization.Get("CLASS_INVISIBLE_TINKER"); break; } } else { InformationInMenu = localization.Get("CLASS_" + (i + 1)); InformationInMenu += " " + localization.Get("CLASS_TRAITS_STRING") + ":\n"; InformationInMenu += localization.Get("CLASS_STRING_BONUS_" + (i + 1)); } cleanString = false; } } if (cleanString) InformationInMenu = ""; break; #endregion #region GameState.Game case GameState.Game: monsterCurrent = null; //if cursor over visible block of map if (stateX >= 0 && stateY >= 0 && stateX < Constants.MAP_SIZE * Constants.TEXTURE_SIZE && stateY < Constants.MAP_SIZE * Constants.TEXTURE_SIZE && map.visible[stateX / Constants.TEXTURE_SIZE, stateY / Constants.TEXTURE_SIZE] != 0) { foreach (Monster monster in map.monsterList) { if (monster.Rectangle.Contains(stateX, stateY)) { monsterCurrent = monster; break; } } } buttonBonusCurrent = null; if (buttonAttack.Rectangle.Contains(stateX, stateY)) buttonBonusCurrent = buttonAttack; buttonMagicCurrent = null; for (int i = 0; i < buttonMagic.Length; ++i) { if (buttonMagic[i] == null) continue; if (buttonMagic[i].Rectangle.Contains(stateX, stateY)) { buttonMagicCurrent = buttonMagic[i]; buttonMagicCurrent.Parameter = map.hero.Magics[i]; } } break; #endregion } keyStateLast = Keyboard.GetState(); mouseStateLast = Mouse.GetState(); }
/// <summary> /// Initialization of game interface /// </summary> public void InitializeGame() { //magics buttonMagic = new ButtonMagic[5]; //if Wizard then 4 slot of magic if (map.hero.ClassHero == Class.Wizard) { for (int i = 0; i < 4; ++i) { buttonMagic[i] = new ButtonMagic(new Rectangle(405 + 30 * i, 175, 20, 20), MagicType.Empty); } } else { for (int i = 0; i < 3; ++i) { buttonMagic[i] = new ButtonMagic(new Rectangle(410 + 40 * i, 175, 20, 20), MagicType.Empty); } } buttonMagic[4] = new ButtonMagic(new Rectangle(535, 175, 20, 20), MagicType.Converter); //other button buttonAttack = new Button<TileType>(new Rectangle(405, 101, 20, 20), TileType.Attackboost); buttonPotionHealth = new Button<TileType>(new Rectangle(485, 50, 20, 20), TileType.HealthPotion); buttonPotionMana = new Button<TileType>(new Rectangle(485, 77, 20, 20), TileType.ManaPotion); }