From cd2fa4719914b9eaf03b209963d6889bf4210b81 Mon Sep 17 00:00:00 2001 From: trandit <trandit@mcmaster.ca> Date: Tue, 15 Nov 2016 15:42:46 -0500 Subject: [PATCH] Renamed DrawUI to DrawClass. Added doxygen to said class --- .../Blaze_Brigade/Blaze_Brigade.csproj | 2 +- src/Blaze-Brigade/Blaze_Brigade/DrawClass.cs | 359 ++++++++++++++++++ src/Blaze-Brigade/Blaze_Brigade/Game.cs | 24 +- src/Blaze-Brigade/Blaze_Brigade/drawUI.cs | 309 --------------- 4 files changed, 372 insertions(+), 322 deletions(-) create mode 100644 src/Blaze-Brigade/Blaze_Brigade/DrawClass.cs delete mode 100644 src/Blaze-Brigade/Blaze_Brigade/drawUI.cs diff --git a/src/Blaze-Brigade/Blaze_Brigade/Blaze_Brigade.csproj b/src/Blaze-Brigade/Blaze_Brigade/Blaze_Brigade.csproj index 2073274..56040de 100644 --- a/src/Blaze-Brigade/Blaze_Brigade/Blaze_Brigade.csproj +++ b/src/Blaze-Brigade/Blaze_Brigade/Blaze_Brigade.csproj @@ -70,7 +70,7 @@ <ItemGroup> <Compile Include="Animation.cs" /> <Compile Include="Archer.cs" /> - <Compile Include="drawUI.cs" /> + <Compile Include="DrawClass.cs" /> <Compile Include="FireBlast.cs" /> <Compile Include="IronSword.cs" /> <Compile Include="LongBow.cs" /> diff --git a/src/Blaze-Brigade/Blaze_Brigade/DrawClass.cs b/src/Blaze-Brigade/Blaze_Brigade/DrawClass.cs new file mode 100644 index 0000000..3519559 --- /dev/null +++ b/src/Blaze-Brigade/Blaze_Brigade/DrawClass.cs @@ -0,0 +1,359 @@ +using Controller; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Model; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace View +{ + /// <summary> + /// Draw Class containing all the different draw methods + /// </summary> + static class DrawClass + { + /** + Draw unit sprites + * @params spriteBatch to draw 2D bitmap to screen + * @params player The player's unit to draw + */ + public static void DrawUnit(SpriteBatch spriteBatch, Player player) // draw it all to the screen. + { + for (int i = 0; i < player.getNumOfUnits(); i++) + { + Unit unit = player.getUnits().ElementAt(i); //gets unit at i + if (unit.Alive) + { + spriteBatch.Draw(unit.getSpriteImage(), unit.PixelCoordinates, + unit.getCurrentFrame(), Color.White, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.8f); + } + } + } + /** + Draw Damage pop up from attacking + * @params spriteBatch to draw 2D bitmap to screen + * @params font the font to be used + */ + public static void drawDamagePopup(SpriteBatch spriteBatch, SpriteFont font) + { + if (GameState.currentPlayerDamagePopup) + { + spriteBatch.DrawString(font, GameState.CurrentPlayerDamageDealt, GameState.lastDefendingUnit.PixelCoordinates + (new Vector2(12, -35)), Color.White, 0, + Vector2.Zero, 1f, SpriteEffects.None, 0f); + } + if (GameState.enemyPlayerDamagePopup) + { + spriteBatch.DrawString(font, GameState.EnemyPlayerDamageDealt, GameState.lastAttackingUnit.PixelCoordinates + (new Vector2(12, -35)), Color.White, 0, + Vector2.Zero, 1f, SpriteEffects.None, 0f); + } + } + + /** + Draw highlightable nodes + * @params spriteBatch to draw 2D bitmap to screen + * @params graph The current game graph + * @params moveableNode The texture for moveableNode + * @params attackableNode The texture for attackableNode + */ + public static void drawHighlightNodes(SpriteBatch spriteBatch, Graph graph, Texture2D moveableNode, Texture2D attackableNode) + { + Unit unit = GameState.selectedUnit; + if (GameState.beforeMove && !GameState.attackSelect) // if unit has yet to move, display the overall move and attack range of unit + { + // Highlight movable nodes in blue + foreach (Node move in GameState.moveableNodes) + { + spriteBatch.Draw(moveableNode, move.getPosition(), null, Color.White * 0.2f, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.9f); + } + // Highlight attackable nodes in red + LinkedList<Node> attackableNodes = GameFunction.getAttackableNodes(graph, unit); + + foreach (Node attack in attackableNodes) + { + if ((!GameState.moveableNodes.Contains(attack)) && (attack.unitOnNode != unit) && (!attack.isObstacle)) + { + spriteBatch.Draw(attackableNode, attack.getPosition(), null, Color.White * 0.2f, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.9f); + } + } + } + else // else if unit has already moved, only display the attack range + { + LinkedList<Node> attackableNodes = GameFunction.getAttackRangeAfterMoving(graph, unit); + foreach (Node attack in attackableNodes) + { + spriteBatch.Draw(attackableNode, attack.getPosition(), null, Color.White * 0.2f, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.9f); + } + } + } + + /** + Draw highlightable nodes + * @params spriteBatch to draw 2D bitmap to screen + */ + public static void drawDropDownMenu(SpriteBatch spriteBatch) + { + Unit unit = GameState.selectedUnit; + unit.setButtonCoordinates(unit.PixelCoordinates); + Button[] unitButtons = unit.getButtons(); + for (int i = 0; i < 4; i++) + { + if (unitButtons[i].Active) + { + spriteBatch.Draw(unitButtons[i].getImage(), unitButtons[i].getPixelCoordinates(), null, Color.White, 0, Vector2.Zero, 1f, SpriteEffects.None, 0f); + } + } + } + + /** + Draw highlightable nodes + * @params spriteBatch to draw 2D bitmap to screen + * @params font The font used to draw the text + */ + public static void drawInventoryMenu(SpriteBatch spriteBatch, SpriteFont font) + { + Unit unit = GameState.selectedUnit; + unit.setButtonCoordinates(unit.PixelCoordinates); //update button positions + Button[] unitButtons = unit.getButtons(); //for each inventory button + for (int i = 5; i < 9; i++) + { + if (unitButtons[i].Active) //if inventory menu buttons are active + { + if (unitButtons[i].hasItem) //if current menu button actually has an item stored in it + { + spriteBatch.DrawString(font, unitButtons[i].weapon.name.ToString(), unitButtons[i].getPixelCoordinates() + (new Vector2(15, 5)), Color.Black, 0, + Vector2.Zero, 1f, SpriteEffects.None, 0f); //draws item stored in unitButtons[i] + spriteBatch.Draw(unitButtons[i].getImage(), unitButtons[i].getPixelCoordinates(), null, Color.White, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.1f); + } + } + } + } + + /** + Draw highlightable nodes + * @params spriteBatch to draw 2D bitmap to screen + * @params player1 Player 1 + * @params player2 Player 2 + */ + public static void drawUnitsAtGameOver(SpriteBatch spriteBatch, Player player1, Player player2) + { + // draws faded units + #region Player 1 Units + // redraws units for player 1 in darker shade for game over + for (int i = 0; i < player1.getNumOfUnits(); i++) + { + Unit unit = player1.getUnits().ElementAt(i); //gets unit at i + if (unit.Alive) + { + spriteBatch.Draw(unit.getSpriteImage(), unit.PixelCoordinates, + unit.getCurrentFrame(), Color.Black * 0.5f, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.5f); + } + } + #endregion + + #region Player 2 Units + // redraws units for player 2 in darker shade for game over + for (int i = 0; i < player2.getNumOfUnits(); i++) + { + Unit unit = player2.getUnits().ElementAt(i); + if (unit.Alive) + { + spriteBatch.Draw(unit.getSpriteImage(), unit.PixelCoordinates, + unit.getCurrentFrame(), Color.Black * 0.5f, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.5f); + } + } + #endregion + } + + /** + Draw end turn button + * @params spriteBatch to draw 2D bitmap to screen + * @params endTurnButton End turn button texture2D + */ + public static void drawEndTurnButton(SpriteBatch spriteBatch, Texture2D endTurnButton) + { + + spriteBatch.Draw(endTurnButton, GameState.endTurnButtonLocation, null, Color.White, 0, Vector2.Zero, 1f, SpriteEffects.None, 0); + + } + + /** + Draw attack confirmation screen + * @params spriteBatch to draw 2D bitmap to screen + * @params font small font to be used + * @params largeFont Larger font to be used + * @params largestFont Largest font to be used + * @params player1 To know which side of screen info is being printed on + * @params graph The game graph + */ + public static void drawAttackConfirm(SpriteBatch spriteBatch, SpriteFont font, SpriteFont largeFont, SpriteFont largestFont, Player player1, Graph graph) + { + + Unit unit = GameState.selectedUnit; + Unit attackedUnit = GameState.unitToAttack; + Button confirmButton = unit.getButtonType(ButtonType.AttackConfirm); + Vector2 attackInfoLocation2 = new Vector2(519, 0); + + // get attack stats + bool attackType = GameFunction.isMagicalAttack(unit); + int damageDealt = DamageCalculations.getDamageDealt(unit, attackedUnit, attackType); + int hitCount = DamageCalculations.getHitCount(unit, attackedUnit); + int hitRate = DamageCalculations.getHitRate(unit, attackedUnit); + int critRate = DamageCalculations.getCritRate(unit, attackedUnit); + // get enemy counter attack stats + attackType = GameFunction.isMagicalAttack(attackedUnit); + int damageDealt2 = DamageCalculations.getDamageDealt(attackedUnit, unit, attackType); + int hitCount2 = DamageCalculations.getHitCount(attackedUnit, unit); + int hitRate2 = DamageCalculations.getHitRate(attackedUnit, unit); + int critRate2 = DamageCalculations.getCritRate(attackedUnit, unit); + #region If player 1's turn + if (GameState.currentPlayer == player1) + { + spriteBatch.Draw(unit.getCharAttackInfo(), Vector2.Zero, null, Color.White, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.7f); //draw charAttackInfoBackground texture for current character + spriteBatch.DrawString(largeFont, damageDealt.ToString(), new Vector2(180, 458), Color.DarkBlue, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.6f); //draws damage dealt + spriteBatch.DrawString(font, " x " + hitCount.ToString(), new Vector2(195, 459), Color.DarkBlue, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.6f); //draws hit count + spriteBatch.DrawString(largeFont, hitRate.ToString() + " %", new Vector2(170, 488), Color.DarkBlue, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.6f); //draws hit rate + spriteBatch.DrawString(largeFont, critRate.ToString() + " %", new Vector2(170, 518), Color.DarkBlue, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.6f); //draws crit rate + spriteBatch.DrawString(largestFont, unit.Hp.ToString(), new Vector2(342, 475), Color.White, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.6f); //draws unit health + spriteBatch.DrawString(largeFont, unit.equippedWeapon.name.ToString(), new Vector2(40, 348), Color.White, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.6f); //draws unit's weapon + + spriteBatch.Draw(attackedUnit.getCharAttackInfo(), attackInfoLocation2, null, Color.White, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.7f); //draw charAttackInfoBackground for unit being attacked + spriteBatch.DrawString(largestFont, attackedUnit.Hp.ToString(), new Vector2(862, 475), Color.White, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.6f); //draws enemy unit health + spriteBatch.DrawString(largeFont, attackedUnit.equippedWeapon.name.ToString(), new Vector2(715, 348), Color.White, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.6f); //draws unit's weapon + + if (GameFunction.isEnemyUnitInRange(graph, attackedUnit, unit)) + { + spriteBatch.DrawString(largeFont, damageDealt2.ToString(), new Vector2(700, 458), Color.DarkRed, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.6f); //draws counterattack damage + spriteBatch.DrawString(font, " x " + hitCount2.ToString(), new Vector2(715, 459), Color.DarkRed, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.6f); //draws counterattack hit count + spriteBatch.DrawString(largeFont, hitRate2.ToString() + " %", new Vector2(690, 488), Color.DarkRed, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.6f); //draws counterattack hit rate + spriteBatch.DrawString(largeFont, critRate2.ToString() + " %", new Vector2(690, 518), Color.DarkRed, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.6f); //draws counterattack crit rate + } + } + #endregion + #region If player 2's turn + else + { + spriteBatch.Draw(attackedUnit.getCharAttackInfo(), Vector2.Zero, null, Color.White, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.7f); //draw charAttackInfoBackground texture for current character + spriteBatch.DrawString(largeFont, damageDealt.ToString(), new Vector2(180, 458), Color.DarkBlue, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.6f); //draws counterattack damage + spriteBatch.DrawString(font, " x " + hitCount.ToString(), new Vector2(195, 459), Color.DarkBlue, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.6f); //draws counterattack hit count + spriteBatch.DrawString(largeFont, hitRate.ToString() + " %", new Vector2(170, 488), Color.DarkBlue, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.6f); //draws counterattack hit rate + spriteBatch.DrawString(largeFont, critRate.ToString() + " %", new Vector2(170, 518), Color.DarkBlue, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.6f); //draws counterattack crit rate + spriteBatch.DrawString(largestFont, attackedUnit.Hp.ToString(), new Vector2(342, 475), Color.White, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.6f); //draws enemy unit health + spriteBatch.DrawString(largeFont, attackedUnit.equippedWeapon.name.ToString(), new Vector2(40, 348), Color.White, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.6f); //draws unit's weapon + + spriteBatch.Draw(unit.getCharAttackInfo(), attackInfoLocation2, null, Color.White, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.7f); //draw charAttackInfoBackground for current character + spriteBatch.DrawString(largestFont, unit.Hp.ToString(), new Vector2(862, 475), Color.White, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.6f); //draws unit health + spriteBatch.DrawString(largeFont, unit.equippedWeapon.name.ToString(), new Vector2(715, 348), Color.White, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.6f); //draws unit's weapon + + if (GameFunction.isEnemyUnitInRange(graph, unit, attackedUnit)) + { + spriteBatch.DrawString(largeFont, damageDealt.ToString(), new Vector2(700, 458), Color.DarkRed, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.6f); //draws damage + spriteBatch.DrawString(font, " x " + hitCount.ToString(), new Vector2(715, 459), Color.DarkRed, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.6f); //draws hit count + spriteBatch.DrawString(largeFont, hitRate.ToString() + " %", new Vector2(690, 488), Color.DarkRed, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.6f); //draws hit rate + spriteBatch.DrawString(largeFont, critRate.ToString() + " %", new Vector2(690, 518), Color.DarkRed, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.6f); //draws crit rate + } + } + #endregion + + spriteBatch.Draw(confirmButton.getImage(), confirmButton.getPixelCoordinates(), null, Color.White, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.8f); + } + + /** + Draw highlightable nodes + * @params spriteBatch to draw 2D bitmap to screen + * @params player1 Player 1 + * @params font small font to be used + * @params largeFont Larger font to be used + */ + public static void drawInfoScreen(SpriteBatch spriteBatch, Player player1, SpriteFont font, SpriteFont largeFont) + { + Unit unit = GameState.selectedUnit; + + //if player 1, prints info screen for player 1 + if ((GameState.currentPlayer == player1) && (!GameState.attackConfirmOpen)) + { + Vector2 statLocation = new Vector2(170, 535); // starting location for first stat + Vector2 statLocation2 = new Vector2(235, 535); // starting location for first stat + Vector2 increment = new Vector2(0, 20); // increment downwards for each stat + Vector2 infoLocation = new Vector2(20, 513); + int[] stats = unit.getStats(); + + for (int k = 0; k < 4; k++) //for stats - level, str, int, skill, + { + spriteBatch.DrawString(font, stats[k].ToString(), statLocation, Color.White, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.6f); + statLocation = statLocation + increment; //increment downwards + } + for (int t = 4; t < 7; t++) //for stats - speed, defense, resistance + { + spriteBatch.DrawString(font, stats[t].ToString(), statLocation2, Color.White, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.6f); + statLocation2 = statLocation2 + increment; //increment downwards + } + + spriteBatch.DrawString(largeFont, unit.Hp.ToString(), new Vector2(278, 532), Color.White, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.6f); //draws unit hp + spriteBatch.Draw(unit.getCharInfo(), infoLocation, null, Color.White, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.7f); //draw charInfoBackground texture + } + //else, info screen for player 2 + else + { + if (!GameState.attackConfirmOpen) + { + Vector2 statLocation = new Vector2(795, 533); //starting location for first stat + Vector2 statLocation2 = new Vector2(860, 533); //starting location for first stat + Vector2 increment = new Vector2(0, 20); //increment downwards for each stat + Vector2 infoLocation = new Vector2(635, 513); + int[] stats = unit.getStats(); + + for (int k = 0; k < 4; k++) //for stats - level, str, int, skill, + { + spriteBatch.DrawString(font, stats[k].ToString(), statLocation, Color.White, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.6f); + statLocation = statLocation + increment; //increment downwards + } + for (int t = 4; t < 7; t++) //for stats - speed, defense, resistance + { + spriteBatch.DrawString(font, stats[t].ToString(), statLocation2, Color.White, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.6f); + statLocation2 = statLocation2 + increment; //increment downwards + } + + spriteBatch.DrawString(largeFont, unit.Hp.ToString(), new Vector2(893, 532), Color.White, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.6f); //draws unit HP + spriteBatch.Draw(unit.getCharInfo(), infoLocation, null, Color.White, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.7f); //draw charInfoBackground texture + } + } + } + + /** + Draw highlightable nodes + * @params spriteBatch to draw 2D bitmap to screen + * @params gameOver The game over button Texture2D + * @params background The background Texture2D + * @params largestFont Largest font to be used + */ + public static void drawGameOverMenu(SpriteBatch spriteBatch, Texture2D gameOver, Texture2D backGround, SpriteFont largestFont) + { + Vector2 gameOverLocation = new Vector2(-370, -300); + spriteBatch.DrawString(largestFont, "Game Over", new Vector2(350, 200), Color.White, 0, Vector2.Zero, 1f, SpriteEffects.None, 0f); //draws Game Over Text + spriteBatch.Draw(gameOver, Vector2.Zero, null, Color.White, 0, gameOverLocation, 1f, SpriteEffects.None, 0f); + spriteBatch.Draw(backGround, Vector2.Zero, null, Color.Black * 0.5f, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.9f); + } + + /** + Draw highlightable nodes + * @params spriteBatch to draw 2D bitmap to screen + * @params player1Transition The player 1 transition texture2D + * @params player2Transition The player 2 transition texture2D + * @params player1 Player 1 + */ + public static void drawTurnTransition(SpriteBatch spriteBatch, Texture2D player1Transition, Texture2D player2Transition, Player player1) + { + + if (GameState.currentPlayer == player1) + { + spriteBatch.Draw(player1Transition, Vector2.Zero, null, Color.White, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.7f); //draw turn transition + } + else + { + spriteBatch.Draw(player2Transition, Vector2.Zero, null, Color.White, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.7f); //draw turn transition + } + } + } +} diff --git a/src/Blaze-Brigade/Blaze_Brigade/Game.cs b/src/Blaze-Brigade/Blaze_Brigade/Game.cs index e2d3e05..e755462 100644 --- a/src/Blaze-Brigade/Blaze_Brigade/Game.cs +++ b/src/Blaze-Brigade/Blaze_Brigade/Game.cs @@ -334,11 +334,11 @@ namespace Controller spriteBatch.Draw(backGround, Vector2.Zero, null, Color.White, 0, Vector2.Zero, 1f, SpriteEffects.None, 1); // draws units for player 1 and 2 - drawUI.DrawUnit(spriteBatch, player1); - drawUI.DrawUnit(spriteBatch, player2); + DrawClass.DrawUnit(spriteBatch, player1); + DrawClass.DrawUnit(spriteBatch, player2); //draws damage popup - drawUI.drawDamagePopup(spriteBatch, font); + DrawClass.drawDamagePopup(spriteBatch, font); #region When Unit is selected // if unit is currently clicked on @@ -347,14 +347,14 @@ namespace Controller Unit unit = GameState.selectedUnit; if (!GameState.isAnimating) { - drawUI.drawHighlightNodes(spriteBatch, graph, moveableNode, attackableNode); + DrawClass.drawHighlightNodes(spriteBatch, graph, moveableNode, attackableNode); if (GameState.dropDownMenuOpen) // if dropDowMenu should be opened, draw dropDownMenu { - drawUI.drawDropDownMenu(spriteBatch); + DrawClass.drawDropDownMenu(spriteBatch); } if (GameState.inventoryOpen) { - drawUI.drawInventoryMenu(spriteBatch, font); + DrawClass.drawInventoryMenu(spriteBatch, font); } } } @@ -363,12 +363,12 @@ namespace Controller // redraws unit at game over to be darker if (GameState.gameOver) { - drawUI.drawUnitsAtGameOver(spriteBatch, player1, player2); + DrawClass.drawUnitsAtGameOver(spriteBatch, player1, player2); } // draws end turn button if (GameState.endTurnButton) { - drawUI.drawEndTurnButton(spriteBatch, endTurnButton); + DrawClass.drawEndTurnButton(spriteBatch, endTurnButton); } break; } @@ -385,11 +385,11 @@ namespace Controller //draw attack confirm menu if (GameState.attackConfirmOpen && !GameState.isAnimating) { - drawUI.drawAttackConfirm(spriteBatch, font, largeFont, largestFont, player1, graph); + DrawClass.drawAttackConfirm(spriteBatch, font, largeFont, largestFont, player1, graph); } //draw char info screen menu - drawUI.drawInfoScreen(spriteBatch, player1, font, largeFont); + DrawClass.drawInfoScreen(spriteBatch, player1, font, largeFont); Unit unit = GameState.selectedUnit; #region Attack menu @@ -543,12 +543,12 @@ namespace Controller //draw game over menu if (GameState.gameOver) { - drawUI.drawGameOverMenu(spriteBatch, gameOver, backGround, largestFont); + DrawClass.drawGameOverMenu(spriteBatch, gameOver, backGround, largestFont); } //draw turn transition if (GameState.transitionTurn) { - drawUI.drawTurnTransition(spriteBatch, player1Transition, player2Transition, player1); + DrawClass.drawTurnTransition(spriteBatch, player1Transition, player2Transition, player1); } spriteBatch.End(); diff --git a/src/Blaze-Brigade/Blaze_Brigade/drawUI.cs b/src/Blaze-Brigade/Blaze_Brigade/drawUI.cs deleted file mode 100644 index 9d686e1..0000000 --- a/src/Blaze-Brigade/Blaze_Brigade/drawUI.cs +++ /dev/null @@ -1,309 +0,0 @@ -using Controller; -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Graphics; -using Model; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace View -{ - static class drawUI - { - public static void DrawUnit(SpriteBatch spriteBatch, Player player) // draw it all to the screen. - { - for (int i = 0; i < player.getNumOfUnits(); i++) - { - Unit unit = player.getUnits().ElementAt(i); //gets unit at i - if (unit.Alive) - { - spriteBatch.Draw(unit.getSpriteImage(), unit.PixelCoordinates, - unit.getCurrentFrame(), Color.White, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.8f); - } - } - } - - public static void drawDamagePopup(SpriteBatch spriteBatch, SpriteFont font) - { - if (GameState.currentPlayerDamagePopup) - { - spriteBatch.DrawString(font, GameState.CurrentPlayerDamageDealt, GameState.lastDefendingUnit.PixelCoordinates + (new Vector2(12, -35)), Color.White, 0, - Vector2.Zero, 1f, SpriteEffects.None, 0f); - } - if (GameState.enemyPlayerDamagePopup) - { - spriteBatch.DrawString(font, GameState.EnemyPlayerDamageDealt, GameState.lastAttackingUnit.PixelCoordinates + (new Vector2(12, -35)), Color.White, 0, - Vector2.Zero, 1f, SpriteEffects.None, 0f); - } - } - - public static void drawHighlightNodes(SpriteBatch spriteBatch, Graph graph, Texture2D moveableNode, Texture2D attackableNode) - { - Unit unit = GameState.selectedUnit; - if (GameState.beforeMove && !GameState.attackSelect) // if unit has yet to move, display the overall move and attack range of unit - { - // Highlight movable nodes in blue - foreach (Node move in GameState.moveableNodes) - { - spriteBatch.Draw(moveableNode, move.getPosition(), null, Color.White * 0.2f, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.9f); - } - - // Highlight attackable nodes in red - LinkedList<Node> attackableNodes = GameFunction.getAttackableNodes(graph, unit); - - foreach (Node attack in attackableNodes) - { - if ((!GameState.moveableNodes.Contains(attack)) && (attack.unitOnNode != unit) && (!attack.isObstacle)) - { - spriteBatch.Draw(attackableNode, attack.getPosition(), null, Color.White * 0.2f, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.9f); - } - } - - } - else // else if unit has already moved, only display the attack range - { - LinkedList<Node> attackableNodes = GameFunction.getAttackRangeAfterMoving(graph, unit); - foreach (Node attack in attackableNodes) - { - spriteBatch.Draw(attackableNode, attack.getPosition(), null, Color.White * 0.2f, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.9f); - } - } - } - - public static void drawDropDownMenu(SpriteBatch spriteBatch) - { - Unit unit = GameState.selectedUnit; - unit.setButtonCoordinates(unit.PixelCoordinates); - Button[] unitButtons = unit.getButtons(); - for (int i = 0; i < 4; i++) - { - if (unitButtons[i].Active) - { - spriteBatch.Draw(unitButtons[i].getImage(), unitButtons[i].getPixelCoordinates(), null, Color.White, 0, Vector2.Zero, 1f, SpriteEffects.None, 0f); - } - } - } - - public static void drawInventoryMenu(SpriteBatch spriteBatch, SpriteFont font) - { - Unit unit = GameState.selectedUnit; - unit.setButtonCoordinates(unit.PixelCoordinates); //update button positions - - Button[] unitButtons = unit.getButtons(); //for each inventory button - for (int i = 5; i < 9; i++) - { - if (unitButtons[i].Active) //if inventory menu buttons are active - { - if (unitButtons[i].hasItem) //if current menu button actually has an item stored in it - { - spriteBatch.DrawString(font, unitButtons[i].weapon.name.ToString(), unitButtons[i].getPixelCoordinates() + (new Vector2(15, 5)), Color.Black, 0, - Vector2.Zero, 1f, SpriteEffects.None, 0f); //draws item stored in unitButtons[i] - spriteBatch.Draw(unitButtons[i].getImage(), unitButtons[i].getPixelCoordinates(), null, Color.White, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.1f); - } - } - } - - } - public static void drawUnitsAtGameOver(SpriteBatch spriteBatch, Player player1, Player player2) - { - // draws faded units - - #region Player 1 Units - // redraws units for player 1 in darker shade for game over - for (int i = 0; i < player1.getNumOfUnits(); i++) - { - Unit unit = player1.getUnits().ElementAt(i); //gets unit at i - if (unit.Alive) - { - spriteBatch.Draw(unit.getSpriteImage(), unit.PixelCoordinates, - unit.getCurrentFrame(), Color.Black * 0.5f, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.5f); - } - } - #endregion - - #region Player 2 Units - // redraws units for player 2 in darker shade for game over - for (int i = 0; i < player2.getNumOfUnits(); i++) - { - Unit unit = player2.getUnits().ElementAt(i); - if (unit.Alive) - { - spriteBatch.Draw(unit.getSpriteImage(), unit.PixelCoordinates, - unit.getCurrentFrame(), Color.Black * 0.5f, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.5f); - } - } - #endregion - - } - - public static void drawEndTurnButton(SpriteBatch spriteBatch, Texture2D endTurnButton) - { - - spriteBatch.Draw(endTurnButton, GameState.endTurnButtonLocation, null, Color.White, 0, Vector2.Zero, 1f, SpriteEffects.None, 0); - - } - - private static bool findAttackType(Unit unit1) - { - if ((unit1.getClass() == UnitType.Warrior) || (unit1.getClass() == UnitType.Archer)) - { - return false; - } - else - { - return true; - } - } - - public static void drawAttackConfirm(SpriteBatch spriteBatch, SpriteFont font, SpriteFont largeFont, SpriteFont largestFont, Player player1, Graph graph) - { - - Unit unit = GameState.selectedUnit; - Unit attackedUnit = GameState.unitToAttack; - Button confirmButton = unit.getButtonType(ButtonType.AttackConfirm); - Vector2 attackInfoLocation2 = new Vector2(519, 0); - - // get attack stats - bool attackType = findAttackType(unit); - int damageDealt = DamageCalculations.getDamageDealt(unit, attackedUnit, attackType); - int hitCount = DamageCalculations.getHitCount(unit, attackedUnit); - int hitRate = DamageCalculations.getHitRate(unit, attackedUnit); - int critRate = DamageCalculations.getCritRate(unit, attackedUnit); - // get enemy counter attack stats - attackType = findAttackType(attackedUnit); - int damageDealt2 = DamageCalculations.getDamageDealt(attackedUnit, unit, attackType); - int hitCount2 = DamageCalculations.getHitCount(attackedUnit, unit); - int hitRate2 = DamageCalculations.getHitRate(attackedUnit, unit); - int critRate2 = DamageCalculations.getCritRate(attackedUnit, unit); - - if (GameState.currentPlayer == player1) - { - spriteBatch.Draw(unit.getCharAttackInfo(), Vector2.Zero, null, Color.White, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.7f); //draw charAttackInfoBackground texture for current character - spriteBatch.DrawString(largeFont, damageDealt.ToString(), new Vector2(180, 458), Color.DarkBlue, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.6f); //draws damage dealt - spriteBatch.DrawString(font, " x " + hitCount.ToString(), new Vector2(195, 459), Color.DarkBlue, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.6f); //draws hit count - spriteBatch.DrawString(largeFont, hitRate.ToString() + " %", new Vector2(170, 488), Color.DarkBlue, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.6f); //draws hit rate - spriteBatch.DrawString(largeFont, critRate.ToString() + " %", new Vector2(170, 518), Color.DarkBlue, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.6f); //draws crit rate - spriteBatch.DrawString(largestFont, unit.Hp.ToString(), new Vector2(342, 475), Color.White, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.6f); //draws unit health - spriteBatch.DrawString(largeFont, unit.equippedWeapon.name.ToString(), new Vector2(40, 348), Color.White, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.6f); //draws unit's weapon - - spriteBatch.Draw(attackedUnit.getCharAttackInfo(), attackInfoLocation2, null, Color.White, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.7f); //draw charAttackInfoBackground for unit being attacked - spriteBatch.DrawString(largestFont, attackedUnit.Hp.ToString(), new Vector2(862, 475), Color.White, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.6f); //draws enemy unit health - spriteBatch.DrawString(largeFont, attackedUnit.equippedWeapon.name.ToString(), new Vector2(715, 348), Color.White, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.6f); //draws unit's weapon - - if (GameFunction.isEnemyUnitInRange(graph, attackedUnit, unit)) - { - spriteBatch.DrawString(largeFont, damageDealt2.ToString(), new Vector2(700, 458), Color.DarkRed, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.6f); //draws counterattack damage - spriteBatch.DrawString(font, " x " + hitCount2.ToString(), new Vector2(715, 459), Color.DarkRed, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.6f); //draws counterattack hit count - spriteBatch.DrawString(largeFont, hitRate2.ToString() + " %", new Vector2(690, 488), Color.DarkRed, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.6f); //draws counterattack hit rate - spriteBatch.DrawString(largeFont, critRate2.ToString() + " %", new Vector2(690, 518), Color.DarkRed, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.6f); //draws counterattack crit rate - } - } - - else - { - spriteBatch.Draw(attackedUnit.getCharAttackInfo(), Vector2.Zero, null, Color.White, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.7f); //draw charAttackInfoBackground texture for current character - spriteBatch.DrawString(largeFont, damageDealt.ToString(), new Vector2(180, 458), Color.DarkBlue, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.6f); //draws counterattack damage - spriteBatch.DrawString(font, " x " + hitCount.ToString(), new Vector2(195, 459), Color.DarkBlue, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.6f); //draws counterattack hit count - spriteBatch.DrawString(largeFont, hitRate.ToString() + " %", new Vector2(170, 488), Color.DarkBlue, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.6f); //draws counterattack hit rate - spriteBatch.DrawString(largeFont, critRate.ToString() + " %", new Vector2(170, 518), Color.DarkBlue, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.6f); //draws counterattack crit rate - spriteBatch.DrawString(largestFont, attackedUnit.Hp.ToString(), new Vector2(342, 475), Color.White, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.6f); //draws enemy unit health - spriteBatch.DrawString(largeFont, attackedUnit.equippedWeapon.name.ToString(), new Vector2(40, 348), Color.White, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.6f); //draws unit's weapon - - spriteBatch.Draw(unit.getCharAttackInfo(), attackInfoLocation2, null, Color.White, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.7f); //draw charAttackInfoBackground for current character - spriteBatch.DrawString(largestFont, unit.Hp.ToString(), new Vector2(862, 475), Color.White, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.6f); //draws unit health - spriteBatch.DrawString(largeFont, unit.equippedWeapon.name.ToString(), new Vector2(715, 348), Color.White, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.6f); //draws unit's weapon - - if (GameFunction.isEnemyUnitInRange(graph, unit, attackedUnit)) - { - spriteBatch.DrawString(largeFont, damageDealt.ToString(), new Vector2(700, 458), Color.DarkRed, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.6f); //draws damage - spriteBatch.DrawString(font, " x " + hitCount.ToString(), new Vector2(715, 459), Color.DarkRed, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.6f); //draws hit count - spriteBatch.DrawString(largeFont, hitRate.ToString() + " %", new Vector2(690, 488), Color.DarkRed, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.6f); //draws hit rate - spriteBatch.DrawString(largeFont, critRate.ToString() + " %", new Vector2(690, 518), Color.DarkRed, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.6f); //draws crit rate - } - } - spriteBatch.Draw(confirmButton.getImage(), confirmButton.getPixelCoordinates(), null, Color.White, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.8f); - - } - - public static void drawInfoScreen(SpriteBatch spriteBatch, Player player1, SpriteFont font, SpriteFont largeFont) - { - Unit unit = GameState.selectedUnit; - - //if player 1, prints info screen for player 1 - if ((GameState.currentPlayer == player1) && (!GameState.attackConfirmOpen)) - { - Vector2 statLocation = new Vector2(170, 535); // starting location for first stat - Vector2 statLocation2 = new Vector2(235, 535); // starting location for first stat - Vector2 increment = new Vector2(0, 20); // increment downwards for each stat - Vector2 infoLocation = new Vector2(20, 513); - int[] stats = unit.getStats(); - - for (int k = 0; k < 4; k++) //for stats - level, str, int, skill, - { - spriteBatch.DrawString(font, stats[k].ToString(), statLocation, Color.White, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.6f); - statLocation = statLocation + increment; //increment downwards - } - for (int t = 4; t < 7; t++) //for stats - speed, defense, resistance - { - spriteBatch.DrawString(font, stats[t].ToString(), statLocation2, Color.White, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.6f); - statLocation2 = statLocation2 + increment; //increment downwards - } - - spriteBatch.DrawString(largeFont, unit.Hp.ToString(), new Vector2(278, 532), Color.White, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.6f); //draws unit hp - spriteBatch.Draw(unit.getCharInfo(), infoLocation, null, Color.White, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.7f); //draw charInfoBackground texture - } - //else, info screen for player 2 - else - { - if (!GameState.attackConfirmOpen) - { - Vector2 statLocation = new Vector2(795, 533); //starting location for first stat - Vector2 statLocation2 = new Vector2(860, 533); //starting location for first stat - Vector2 increment = new Vector2(0, 20); //increment downwards for each stat - Vector2 infoLocation = new Vector2(635, 513); - int[] stats = unit.getStats(); - - for (int k = 0; k < 4; k++) //for stats - level, str, int, skill, - { - spriteBatch.DrawString(font, stats[k].ToString(), statLocation, Color.White, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.6f); - statLocation = statLocation + increment; //increment downwards - } - for (int t = 4; t < 7; t++) //for stats - speed, defense, resistance - { - spriteBatch.DrawString(font, stats[t].ToString(), statLocation2, Color.White, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.6f); - statLocation2 = statLocation2 + increment; //increment downwards - } - - spriteBatch.DrawString(largeFont, unit.Hp.ToString(), new Vector2(893, 532), Color.White, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.6f); //draws unit HP - spriteBatch.Draw(unit.getCharInfo(), infoLocation, null, Color.White, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.7f); //draw charInfoBackground texture - } - } - } - - public static void drawGameOverMenu(SpriteBatch spriteBatch, Texture2D gameOver, Texture2D backGround, SpriteFont largestFont) - { - - Vector2 gameOverLocation = new Vector2(-370, -300); - spriteBatch.DrawString(largestFont, "Game Over", new Vector2(350, 200), Color.White, 0, Vector2.Zero, 1f, SpriteEffects.None, 0f); //draws Game Over Text - spriteBatch.Draw(gameOver, Vector2.Zero, null, Color.White, 0, gameOverLocation, 1f, SpriteEffects.None, 0f); - spriteBatch.Draw(backGround, Vector2.Zero, null, Color.Black * 0.5f, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.9f); - - - } - - public static void drawTurnTransition(SpriteBatch spriteBatch, Texture2D player1Transition, Texture2D player2Transition, Player player1) - { - - if (GameState.currentPlayer == player1) - { - spriteBatch.Draw(player1Transition, Vector2.Zero, null, Color.White, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.7f); //draw turn transition - } - else - { - spriteBatch.Draw(player2Transition, Vector2.Zero, null, Color.White, 0, Vector2.Zero, 1f, SpriteEffects.None, 0.7f); //draw turn transition - } - } - - } -} -- GitLab