Added in player HUD with simple health (with lerp!) and ammo display.

This commit is contained in:
JoshuaNavarro 2019-07-21 18:52:53 -07:00
parent e1553ca6d8
commit 5a2f708e08
10 changed files with 119 additions and 27 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 126 B

View File

@ -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];
}
}
}

View File

@ -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;
}

View File

@ -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);
}
}
}
/// <summary>
/// Has a small counting lerp for display text.
/// </summary>
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);
}
/// <summary>
@ -66,7 +117,10 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame.SSCMenus.HUD
/// </summary>
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);
}
/// <summary>

View File

@ -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;
}
/// <summary>
@ -181,7 +195,6 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame
this.HUD.draw(b);
}
#region
/// <summary>
/// Called every frame to do update logic.
/// </summary>
@ -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
/// <summary>
/// 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;
}
}
}

View File

@ -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();
}

View File

@ -191,6 +191,9 @@
<Content Include="Content\Minigames\SeasideScramble\Graphics\UI\DialogBox.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Content\Minigames\SeasideScramble\Graphics\UI\Heart.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Content\Minigames\SeasideScramble\Graphics\UI\lastPageButton.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>

View File

@ -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)

View File

@ -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;
}
/// <summary>Adds a textured character to a textured string.</summary>