From 5a2f708e085d14ac3eb0b5d62c10c6cf16bd0ba7 Mon Sep 17 00:00:00 2001 From: JoshuaNavarro Date: Sun, 21 Jul 2019 18:52:53 -0700 Subject: [PATCH] Added in player HUD with simple health (with lerp!) and ammo display. --- .../Graphics/UI/Clock.aseprite | Bin 664 -> 0 bytes .../SeasideScramble/Graphics/UI/Heart.png | Bin 0 -> 126 bytes .../SSCFonts/SSCFontCharacterSheet.cs | 5 -- .../SeasideScrambleMinigame/SSCGuns/SSCGun.cs | 1 + .../SSCMenus/HUD/CharacterHUD.cs | 76 +++++++++++++++--- .../SeasideScrambleMinigame/SSCPlayer.cs | 37 ++++++++- .../SeasideScramble.cs | 19 +++-- GeneralMods/Revitalize/Revitalize.csproj | 3 + .../CharacterSheets/GenericCharacterSheets.cs | 3 +- .../Fonts/Components/TexturedString.cs | 2 + 10 files changed, 119 insertions(+), 27 deletions(-) delete mode 100644 GeneralMods/Revitalize/Content/Minigames/SeasideScramble/Graphics/UI/Clock.aseprite create mode 100644 GeneralMods/Revitalize/Content/Minigames/SeasideScramble/Graphics/UI/Heart.png diff --git a/GeneralMods/Revitalize/Content/Minigames/SeasideScramble/Graphics/UI/Clock.aseprite b/GeneralMods/Revitalize/Content/Minigames/SeasideScramble/Graphics/UI/Clock.aseprite deleted file mode 100644 index 184dd3e039b48de5bca6ed45eb8ace61fc0db795..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 664 zcmcJNPe_w-9EZQlHC-JNLMRY@nIRp7+z`u@WI<5sArz(}=sRB>Y=>D*B>&Yiq1t6T z2z%2&J$TcLmsp^J;wcL{G!YLPOz@CG9!g62^}HGt-u=P*!24dF=kva=c}8S&$|mRK zoM>Vbkq)kZr$}tp!&5t#@c;Z~|7-n<>9SVz$LBifRU$5}4Boj~1p^gs8244ejfcf> zZ6W}7mqy{Qy>j?^>pl$4m%{5KVOSfy2J36DKu=W#tgh~crTP$T34ejcn1XE|GVuNS z0aP53v6;7U_{j?x4258`uO9Z?j=^b<2d*_5aJBy(j3;Ygtjn?|lS!CLrC>UpRuR_O zt#@wCWfq$l#2TisgAptspLW8jCYfGhDJ7Fe0`H97hZ6kq1}IK?TC-xzu{n$x_awoRKey1($$qwD5Pb71h^ zp=$imI<)L9dwHQDdvW}`{n@g&$(OkJ(edhe#@nuyujJ()^YnvA iBAB>ww;&VFo%_E)M!3HGx`C7_=l&hzUV+hC0CMTTmAlDyxF73lk`9OOuXTO=2?@Icr}v7 WsXA}vTc2j2fefCmelF{r5}E+R_$deg literal 0 HcmV?d00001 diff --git a/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SSCFonts/SSCFontCharacterSheet.cs b/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SSCFonts/SSCFontCharacterSheet.cs index 66b9cde7..129b1c13 100644 --- a/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SSCFonts/SSCFontCharacterSheet.cs +++ b/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SSCFonts/SSCFontCharacterSheet.cs @@ -26,10 +26,5 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame.SSCFonts this.CharacterAtlus.Add('9', new TexturedCharacter('9', SeasideScramble.self.textureUtils.getTexture("SSCUI", "9"), Color.White)); } - public override TexturedCharacter getTexturedCharacter(char c) - { - return this.CharacterAtlus[c]; - } - } } diff --git a/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SSCGuns/SSCGun.cs b/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SSCGuns/SSCGun.cs index 69b61b3e..7c3dd10a 100644 --- a/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SSCGuns/SSCGun.cs +++ b/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SSCGuns/SSCGun.cs @@ -119,6 +119,7 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame.SSCGuns this.remainingAmmo = this.maxAmmo; this.firingDelay = FiringRate; this.reloadSpeed = ReloadSpeed; + this.timeRemainingUntilReload = this.reloadSpeed; this.consumesXAmmoPerShot = ConsumesXAmmo; } diff --git a/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SSCMenus/HUD/CharacterHUD.cs b/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SSCMenus/HUD/CharacterHUD.cs index fc3f7f3c..eb88ca5b 100644 --- a/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SSCMenus/HUD/CharacterHUD.cs +++ b/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SSCMenus/HUD/CharacterHUD.cs @@ -11,28 +11,48 @@ using StardustCore.UIUtilities.SpriteFonts.Components; namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame.SSCMenus.HUD { - public class CharacterHUD: IClickableMenuExtended + public class CharacterHUD : IClickableMenuExtended { public AnimatedSprite background; public SSCEnums.PlayerID playerID; public bool showHUD; - public TexturedString str; + + public AnimatedSprite heart; + public TexturedString playerHealth; + public int remainingHealthLerpFrames; + public int framesToUpdate = 5; + + public AnimatedSprite gun; + public TexturedString playerAmmo; + + public SSCPlayer Player + { + get + { + return SeasideScramble.self.getPlayer(this.playerID); + } + } public CharacterHUD() { } - public CharacterHUD(int x, int y, int width, int height,SSCEnums.PlayerID Player) : base(x, y, width, height, false) + public CharacterHUD(int x, int y, int width, int height, SSCEnums.PlayerID Player) : base(x, y, width, height, false) { - this.background = new AnimatedSprite("Background",new Vector2(x,y),new AnimationManager(SeasideScramble.self.textureUtils.getExtendedTexture("SSCUI", "DialogBox"),new Animation(0,0,32,32)),Color.White); - + this.background = new AnimatedSprite("Background", new Vector2(x, y), new AnimationManager(SeasideScramble.self.textureUtils.getExtendedTexture("SSCUI", "DialogBox"), new Animation(0, 0, 32, 32)), Color.White); this.playerID = Player; this.showHUD = false; - this.str = SeasideScramble.self.gameFont.ParseString("012",new Vector2(100,100),Color.White,true,2f); - this.str.setPosition(new Vector2(this.xPositionOnScreen+100, this.yPositionOnScreen+50)); + this.heart = new AnimatedSprite("Heart", new Vector2(x + 32, y + 10), new AnimationManager(SeasideScramble.self.textureUtils.getExtendedTexture("SSCUI", "Heart"), new Animation(0, 0, 7, 6)), Color.White); + this.playerHealth = SeasideScramble.self.gameFont.ParseString("100", new Vector2(100, this.yPositionOnScreen + 10), Color.White, true, 2f); + this.playerHealth.setPosition(new Vector2(this.xPositionOnScreen + 100, this.yPositionOnScreen + 10)); + + + this.gun = new AnimatedSprite("Gun", new Vector2(x + 32, y + 50), new AnimationManager(SeasideScramble.self.textureUtils.getExtendedTexture("Guns", "BasicGun"), new Animation(0, 0, 16, 16)), Color.White); + this.playerAmmo = SeasideScramble.self.gameFont.ParseString("100", new Vector2(100, this.yPositionOnScreen + 50), Color.White, true, 2f); + this.playerAmmo.setPosition(new Vector2(this.xPositionOnScreen + 100, this.yPositionOnScreen + 50)); } public override void update(GameTime time) @@ -41,10 +61,38 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame.SSCMenus.HUD if (SeasideScramble.self.getPlayer(this.playerID) != null) { this.background.color = SeasideScramble.self.getPlayer(this.playerID).playerColor; - if (this.str.getText() != "345") + this.healthDisplayLerp(); + if (this.Player.gun.remainingAmmo == SSCGuns.SSCGun.infiniteAmmo) { - this.str.setText("345", SeasideScramble.self.gameFont, Color.White); + this.playerAmmo.setText("999", SeasideScramble.self.gameFont, Color.White); } + else + { + this.playerAmmo.setText(this.Player.gun.remainingAmmo.ToString().PadLeft(3,'0'), SeasideScramble.self.gameFont, Color.White); + } + } + } + + /// + /// Has a small counting lerp for display text. + /// + private void healthDisplayLerp() + { + if (this.remainingHealthLerpFrames == 0) + { + this.remainingHealthLerpFrames = this.framesToUpdate; + if (Convert.ToInt32(this.playerHealth.getText()) != this.Player.currentHealth) + { + int health = Convert.ToInt32(this.playerHealth.getText()); + health = health - 1; + string healthStr = health.ToString(); + healthStr = healthStr.PadLeft(3, '0'); + this.playerHealth.setText(healthStr, SeasideScramble.self.gameFont, Color.White); + } + } + else + { + this.remainingHealthLerpFrames--; } } @@ -57,8 +105,11 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame.SSCMenus.HUD if (this.showHUD == false) return; //Draw the HUD background. //b.Draw(this.background.texture, new Vector2(100, 100), SeasideScramble.self.camera.getXNARect(), SeasideScramble.self.players[this.playerID].playerColor, 0f, Vector2.Zero, new Vector2(4f, 2f), SpriteEffects.None, 0f); - this.background.draw(b,this.background.position,new Vector2(8f,4f),0f); - this.str.draw(b,new Rectangle(0,0,16,16),0f); + this.background.draw(b, this.background.position, new Vector2(8f, 4f), 0f); + this.playerHealth.draw(b, new Rectangle(0, 0, 16, 16), 0f); + this.playerAmmo.draw(b, new Rectangle(0, 0, 16, 16), 0f); + this.heart.draw(b, 8f, 0f); + this.gun.draw(b, 4f, 0f); } /// @@ -66,7 +117,10 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame.SSCMenus.HUD /// public void displayHUD() { + this.playerHealth.setText(SeasideScramble.self.getPlayer(this.playerID).currentHealth.ToString(), SeasideScramble.self.gameFont, Color.White); this.showHUD = true; + + SeasideScramble.self.getPlayer(this.playerID).takeDamage(100); } /// diff --git a/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SSCPlayer.cs b/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SSCPlayer.cs index 8c620269..1f007cc3 100644 --- a/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SSCPlayer.cs +++ b/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SSCPlayer.cs @@ -40,6 +40,17 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame public SSCMenus.HUD.CharacterHUD HUD; + public int currentHealth; + public int maxHealth; + + public bool isDead + { + get + { + return this.currentHealth <= 0; + } + } + public SSCPlayer(SSCEnums.PlayerID PlayerID) { this.playerID = PlayerID; @@ -131,7 +142,10 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame this.gun=new SSCGuns.SSCGun(new StardustCore.Animations.AnimatedSprite("MyFirstGun",this.position,new AnimationManager(SeasideScramble.self.textureUtils.getExtendedTexture("Guns","BasicGun"),new Animation(0,0,16,16)),Color.White), SeasideScramble.self.projectiles.getDefaultProjectile(this, this.position, Vector2.Zero, 1f, new Rectangle(0, 0, 16, 16), Color.White, 4f, 300),10,1000,3000); this.hitBox = new Rectangle((int)this.position.X, (int)this.position.Y, 64, 64); - this.HUD = new SSCMenus.HUD.CharacterHUD(100, 100, 200, 200, this.playerID); + this.HUD = new SSCMenus.HUD.CharacterHUD(100, 20, 100, 100, this.playerID); + + this.maxHealth = 100; + this.currentHealth = 100; } /// @@ -181,7 +195,6 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame this.HUD.draw(b); } - #region /// /// Called every frame to do update logic. /// @@ -242,6 +255,7 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame this.showMouseCursor = true; } } + if (this.currentHealth < 0) this.currentHealth = 0; this.gun.update(Time); this.HUD.update(Time); @@ -260,6 +274,7 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame // Input logic // //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// + #region /// /// Checks when the gamepad receives input. @@ -484,5 +499,23 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame } + public void takeDamage(int amount) + { + this.currentHealth -= amount; + if (this.currentHealth < 0) { + this.currentHealth = 0; + } + } + + public void heal(int amount) + { + this.takeDamage(amount * -1); + } + + public void healToFull() + { + this.currentHealth = this.maxHealth; + } + } } diff --git a/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SeasideScramble.cs b/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SeasideScramble.cs index 1a27825d..cb393103 100644 --- a/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SeasideScramble.cs +++ b/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SeasideScramble.cs @@ -163,10 +163,7 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame foreach(SSCPlayer p in this.players.Values) { p.draw(b); - if(p.playerID== SSCEnums.PlayerID.One) - { - p.drawMouse(b); - } + } /* @@ -175,14 +172,20 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame this.menuManager.activeMenu.draw(b); } */ + foreach (SSCPlayer p in this.players.Values) + { + p.drawHUD(b); + if (p.playerID == SSCEnums.PlayerID.One) + { + p.drawMouse(b); + } + } + this.menuManager.drawAll(b); this.projectiles.draw(b); - foreach (SSCPlayer p in this.players.Values) - { - p.drawHUD(b); - } + b.End(); } diff --git a/GeneralMods/Revitalize/Revitalize.csproj b/GeneralMods/Revitalize/Revitalize.csproj index f4dca3ce..018dca7b 100644 --- a/GeneralMods/Revitalize/Revitalize.csproj +++ b/GeneralMods/Revitalize/Revitalize.csproj @@ -191,6 +191,9 @@ Always + + Always + Always diff --git a/GeneralMods/StardustCore/UIUtilities/SpriteFonts/CharacterSheets/GenericCharacterSheets.cs b/GeneralMods/StardustCore/UIUtilities/SpriteFonts/CharacterSheets/GenericCharacterSheets.cs index ca844abf..8fabe758 100644 --- a/GeneralMods/StardustCore/UIUtilities/SpriteFonts/CharacterSheets/GenericCharacterSheets.cs +++ b/GeneralMods/StardustCore/UIUtilities/SpriteFonts/CharacterSheets/GenericCharacterSheets.cs @@ -20,7 +20,8 @@ namespace StardustCore.UIUtilities.SpriteFonts.CharacterSheets public virtual TexturedCharacter getTexturedCharacter(char c) { - return new TexturedCharacter(); + var original = this.CharacterAtlus[c]; + return TexturedCharacter.Copy(original); } public virtual GenericCharacterSheets create(string Path) diff --git a/GeneralMods/StardustCore/UIUtilities/SpriteFonts/Fonts/Components/TexturedString.cs b/GeneralMods/StardustCore/UIUtilities/SpriteFonts/Fonts/Components/TexturedString.cs index 0a9c832a..d4d7a617 100644 --- a/GeneralMods/StardustCore/UIUtilities/SpriteFonts/Fonts/Components/TexturedString.cs +++ b/GeneralMods/StardustCore/UIUtilities/SpriteFonts/Fonts/Components/TexturedString.cs @@ -74,6 +74,8 @@ namespace StardustCore.UIUtilities.SpriteFonts.Components this.scale = other.scale; this.position = other.position; this.label = other.label; + this.displayText = other.displayText; + } /// Adds a textured character to a textured string.