public HUD(Hero hero, Entity enemy, Fight fight) { this.topLeftFrame = new Vector2(45, 35); this.topRightFrame = new Vector2(445, 35); this.bottomLeftFrame = new Vector2(25, 555); this.bottomRightFrame = new Vector2(735, 555); this.hero = hero; this.enemy = enemy; this.enemyHit = false; this.heroHit = false; enemyHitDelay = 0; heroHitDelay = 0; this.heroInventory = new InventoryGUI(this.hero, fight); this.combatLog = new List <string>(); this.logPos = new Vector2(this.topRightFrame.X + 15, this.topRightFrame.Y + 10); #region Initialize HP/Mana Bars this.heroHpPercentage = (int)((float)this.hero.CurrentHealth / (float)this.hero.MaxHealth * 100.0); this.heroHp.Width = this.heroHpPercentage * 2; this.heroHp.Height = 25; this.heroHp.X = Convert.ToInt32(bottomLeftFrame.X + 15); this.heroHp.Y = Convert.ToInt32(bottomLeftFrame.Y + 55); this.heroManaPercentage = (int)((float)this.hero.CurrentMana / (float)this.hero.MaxMana * 100.0); this.heroMana.Width = this.heroManaPercentage * 2; this.heroMana.Height = 25; this.heroMana.X = Convert.ToInt32(bottomLeftFrame.X + 15); this.heroMana.Y = Convert.ToInt32(bottomLeftFrame.Y + 85); this.enemyHpPercentage = (int)((float)this.enemy.CurrentHealth / (float)this.enemy.MaxHealth * 100.0); this.enemyHp.Width = this.enemyHpPercentage * 2; this.enemyHp.Height = 25; this.enemyHp.X = Convert.ToInt32(bottomRightFrame.X + 15); this.enemyHp.Y = Convert.ToInt32(bottomRightFrame.Y + 55); this.enemyManaPercentage = (int)((float)this.enemy.CurrentMana / (float)this.enemy.MaxMana * 100.0); this.enemyMana.Width = this.enemyManaPercentage * 2; this.enemyMana.Height = 25; this.enemyMana.X = Convert.ToInt32(bottomRightFrame.X + 15); this.enemyMana.Y = Convert.ToInt32(bottomRightFrame.Y + 85); #endregion choiceHUD = ChoiceHUD.Blank; menuHUD = MenuHUD.Main; spellChoice = SpellChoice.Blank; #region Initialize Button Position this.button1 = new Vector2(topLeftFrame.X + 15, topLeftFrame.Y + 80); this.button2 = new Vector2(topLeftFrame.X + 210, topLeftFrame.Y + 80); this.button3 = new Vector2(topLeftFrame.X + 15, topLeftFrame.Y + 125); this.button4 = new Vector2(topLeftFrame.X + 210, topLeftFrame.Y + 125); this.buttonN = new Vector2(this.topLeftFrame.X + 190, this.topLeftFrame.Y + 15); this.buttonP = new Vector2(this.topLeftFrame.X + 115, this.topLeftFrame.Y + 15); #endregion }
public void Update(MouseInput mouseInput, KeyboardInput keyboardInput) { #region Update HP/Mana Bars this.heroHpPercentage = (int)((float)this.hero.CurrentHealth / (float)this.hero.MaxHealth * 100.0); this.heroManaPercentage = (int)((float)this.hero.CurrentMana / (float)this.hero.MaxMana * 100.0); this.enemyHpPercentage = (int)((float)this.enemy.CurrentHealth / (float)this.enemy.MaxHealth * 100.0); this.enemyManaPercentage = (int)((float)this.enemy.CurrentMana / (float)this.enemy.MaxMana * 100.0); this.heroHp.Width = this.heroHpPercentage * 2; this.heroMana.Width = this.heroManaPercentage * 2; this.enemyHp.Width = this.enemyHpPercentage * 2; this.enemyMana.Width = this.enemyManaPercentage * 2; #endregion #region Update HUD Choice if (menuHUD == MenuHUD.Main) { if (attackRect.Contains((int)mouseInput.Pos.X, (int)mouseInput.Pos.Y)) { choiceHUD = ChoiceHUD.Attack; } else if (defendRect.Contains((int)mouseInput.Pos.X, (int)mouseInput.Pos.Y)) { choiceHUD = ChoiceHUD.Defend; } else if (spellsRect.Contains((int)mouseInput.Pos.X, (int)mouseInput.Pos.Y)) { choiceHUD = ChoiceHUD.Spells; } else if (inventoryRect.Contains((int)mouseInput.Pos.X, (int)mouseInput.Pos.Y)) { choiceHUD = ChoiceHUD.Inventory; } else { choiceHUD = ChoiceHUD.Blank; } } else if (menuHUD == MenuHUD.Spells) { if (nextRect.Contains((int)mouseInput.Pos.X, (int)mouseInput.Pos.Y)) { choiceHUD = ChoiceHUD.Next; } else if (prevRect.Contains((int)mouseInput.Pos.X, (int)mouseInput.Pos.Y)) { choiceHUD = ChoiceHUD.Previous; } else if (arcaneShockRect.Contains((int)mouseInput.Pos.X, (int)mouseInput.Pos.Y)) { spellChoice = SpellChoice.ArcaneShock; } else if (selfCureRect.Contains((int)mouseInput.Pos.X, (int)mouseInput.Pos.Y)) { spellChoice = SpellChoice.SelfCure; } else { spellChoice = SpellChoice.Blank; choiceHUD = ChoiceHUD.Blank; } if (mouseInput.IsRightClicked()) { menuHUD = MenuHUD.Main; } } else if (menuHUD == MenuHUD.Inventory) { if (mouseInput.IsRightClicked()) { menuHUD = MenuHUD.Main; } } #endregion #region Hit Animation Timer if (this.enemyHit) { enemyHitDelay++; if (enemyHitDelay > 20) { this.enemyHitDelay = 0; this.enemyHit = false; } } if (this.heroHit) { heroHitDelay++; if (heroHitDelay > 20) { this.heroHitDelay = 0; this.heroHit = false; } } #endregion this.heroInventory.Update(mouseInput, keyboardInput); }