Browse Source

Add player health & a heart sprite.

GitOrigin-RevId: 3389f46044
master
Colin McMillen 4 years ago
parent
commit
c189cfcc09
  1. 5
      Shared/Player.cs
  2. 18
      Shared/Scene.cs
  3. 1
      Shared/Textures.cs

5
Shared/Player.cs

@ -36,8 +36,13 @@ namespace SemiColinGames {
private double jumpTime = 0;
public Player() {
Health = MaxHealth;
}
public int MaxHealth { get; private set; } = 5;
public int Health { get; private set; }
public int Facing { get; private set; } = 1;
public Point Position { get { return position; } }

18
Shared/Scene.cs

@ -95,15 +95,23 @@ namespace SemiColinGames {
Debug.Draw(graphics, basicEffect);
// Draw in-world UI on top of everything.
if (paused) {
spriteBatch.Begin(
SpriteSortMode.Deferred, null, SamplerState.PointClamp, null, null, null, null);
spriteBatch.Begin(
SpriteSortMode.Deferred, null, SamplerState.PointClamp, null, null, null, null);
for (int i = 0; i < player.MaxHealth; i++) {
Vector2 pos = new Vector2(16 + 16 * i, 8);
if (player.Health > i) {
spriteBatch.Draw(Textures.Heart.Get, pos, new Rectangle(0, 0, 16, 16), Color.White);
} else {
spriteBatch.Draw(Textures.Heart.Get, pos, new Rectangle(16, 0, 16, 16), Color.White);
}
}
if (paused) {
string text = "Paused";
Vector2 position = Textures.BannerFont.CenteredOn(text, camera.HalfSize);
Text.DrawOutlined(spriteBatch, Textures.BannerFont, text, position, Color.White);
spriteBatch.End();
}
spriteBatch.End();
// Get ready to draw sceneTarget to screen.
graphics.SetRenderTarget(null);
@ -124,7 +132,7 @@ namespace SemiColinGames {
}
// Actually draw to screen.
spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend,
spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend,
SamplerState.PointClamp, DepthStencilState.Default,
RasterizerState.CullNone);
spriteBatch.Draw(sceneTarget, drawRect, Color.White);

1
Shared/Textures.cs

@ -34,6 +34,7 @@ namespace SemiColinGames {
public static SpriteFont BannerFont;
public static TextureRef Player = new TextureRef("sprites/ccg/ninja_female");
public static TextureRef Heart = new TextureRef("sprites/semicolin/heart");
// Backgrounds are indexed by draw order; the first element should be drawn furthest back.
public static TextureRef[] Backgrounds = new TextureRef[] {

Loading…
Cancel
Save