From 74b8d06dbbec347bd5946e3b1966e9b27f8a897c Mon Sep 17 00:00:00 2001
From: weberma73121 <weberma73121@th-nuernberg.de>
Date: Mon, 18 Jan 2021 15:58:20 +0100
Subject: [PATCH] Lives display

---
 PixelShaders.cpp |  5 ++++
 PixelShaders.hpp |  8 +++++++
 main.cpp         |  5 ++--
 player.cpp       | 61 ++++++++++++++++++++++++++++++++++++++++++++++++
 player.hpp       |  2 ++
 5 files changed, 79 insertions(+), 2 deletions(-)

diff --git a/PixelShaders.cpp b/PixelShaders.cpp
index 376ec5e..d5298d7 100644
--- a/PixelShaders.cpp
+++ b/PixelShaders.cpp
@@ -49,3 +49,8 @@ Color DiagonalFadeoutShader::peekUnchecked(PixelPoint const &pos) const
 	}
 	return (pos.x <= x_end) ? _0 : src;
 }
+Color ReloadShader::peekUnchecked(PixelPoint const &pos) const
+{
+    auto src = input.peek(pos);
+
+}
diff --git a/PixelShaders.hpp b/PixelShaders.hpp
index bb20dc2..6f42fc3 100644
--- a/PixelShaders.hpp
+++ b/PixelShaders.hpp
@@ -31,5 +31,13 @@ public:
 
 	virtual Color peekUnchecked(PixelPoint const &pos) const;
 };
+class ReloadShader: public ShadedPixelBuffer{
+public:
+    float percent;
+    virtual Color peekUnchecked(PixelPoint const &pos) const;
+    ReloadShader(PixelBuffer const &input, float percent) :
+        ShadedPixelBuffer(input), percent(percent) {
+    }
+};
 
 #endif /* PIXELSHADERS_HPP */
diff --git a/main.cpp b/main.cpp
index 8aa9c7d..eebdf98 100644
--- a/main.cpp
+++ b/main.cpp
@@ -31,7 +31,7 @@ float difficultyChangeTime = 60.0f;
 int screenWidth = 320;
 int screenHeigth = 320;
 int difficulty = 0;
-
+//lives
 
 // global helper funktion to add "buildings"
 void addBuilding(float x, float y, int size, Level &level_ptr)
@@ -229,8 +229,9 @@ public:
             framebuffer.blit_topleft({ 0, 0 }, levelBuffer);
             for(auto & i : Highscore.ScoreBoard){
                 framebuffer.blit_topleft(i.ScorePos,i.getScoreSprite());
-            }
+            }            
         }
+        framebuffer.blit_topleft({3,3},player_.getLivesSprite(player_.getHitPoints()));
         // kruegerzo72182>
         // <hoffmanncl72341
         platform.render(framebuffer);
diff --git a/player.cpp b/player.cpp
index 700dbbd..2ea762a 100644
--- a/player.cpp
+++ b/player.cpp
@@ -176,6 +176,7 @@ void Player::move(Platform &p, FloatSeconds const & Frametime, Level &level)
             case ' ':
             {
                 shoot(level);
+                attack=true;
             }
             }
         }
@@ -218,3 +219,63 @@ void Player::shoot(Level &level)
     }
 
 }
+static StaticPixelBuffer<39,7> constexpr lives[6]={
+    {{{
+          {"                                       "},
+          {"                                       "},
+          {"                                       "},
+          {"                                       "},
+          {"                                       "},
+          {"                                       "},
+          {"                                       "}
+      }}},
+    {{{
+          {" 22 22                                 "},
+          {"2222222                                "},
+          {"2222222                                "},
+          {"2222222                                "},
+          {" 22222                                 "},
+          {"  222                                  "},
+          {"   2                                   "}
+      }}},
+    {{{
+          {" 22 22   22 22                         "},
+          {"2222222 2222222                        "},
+          {"2222222 2222222                        "},
+          {"2222222 2222222                        "},
+          {" 22222   22222                         "},
+          {"  222     222                          "},
+          {"   2       2                           "}
+      }}},
+    {{{
+          {" 22 22   22 22   22 22                 "},
+          {"2222222 2222222 2222222                "},
+          {"2222222 2222222 2222222                "},
+          {"2222222 2222222 2222222                "},
+          {" 22222   22222   22222                 "},
+          {"  222     222     222                  "},
+          {"   2       2       2                   "}
+      }}},
+    {{{
+          {" 22 22   22 22   22 22   22 22         "},
+          {"2222222 2222222 2222222 2222222        "},
+          {"2222222 2222222 2222222 2222222        "},
+          {"2222222 2222222 2222222 2222222        "},
+          {" 22222   22222   22222   22222         "},
+          {"  222     222     222     222          "},
+          {"   2       2       2       2           "}
+      }}},
+    {{{
+          {" 22 22   22 22   22 22   22 22   22 22 "},
+          {"2222222 2222222 2222222 2222222 2222222"},
+          {"2222222 2222222 2222222 2222222 2222222"},
+          {"2222222 2222222 2222222 2222222 2222222"},
+          {" 22222   22222   22222   22222   22222 "},
+          {"  222     222     222     222     222  "},
+          {"   2       2       2       2       2   "}
+      }}}
+};
+const PixelBuffer& Player::getLivesSprite(int hitpoints)
+{
+    return lives[hitpoints];
+}
diff --git a/player.hpp b/player.hpp
index c37d0df..bc13f98 100644
--- a/player.hpp
+++ b/player.hpp
@@ -17,11 +17,13 @@ protected:
     int animationstep=0;
     float timetillreload=0.0f;
     float animationtimer=0.0f;
+    bool attack=false;
 public:
     Player(float x, float y);
     PixelBuffer const& getSprite() override;
     void move(Platform &p, FloatSeconds const & Frametime, Level &level);
     void shoot(Level &level);
+    const PixelBuffer& getLivesSprite(int hitpoints);
 };
 
 #endif // PLAYER_HPP
-- 
GitLab