From 0660af11caa453842cd9a996d0eb18297da833a6 Mon Sep 17 00:00:00 2001
From: Claudio Hoffmann <hoffmanncl72341@th-nuernberg.de>
Date: Sat, 16 Jan 2021 02:20:31 +0100
Subject: [PATCH] =?UTF-8?q?Entity:=20Add=20an=20unexpectedly=20awesome=20d?=
 =?UTF-8?q?estruction=20animation=20=F0=9F=92=A5?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 Entity.cpp       | 2 +-
 PixelShaders.cpp | 2 +-
 PixelShaders.hpp | 5 +++--
 3 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/Entity.cpp b/Entity.cpp
index 3f4dd65..da56f29 100644
--- a/Entity.cpp
+++ b/Entity.cpp
@@ -65,7 +65,7 @@ int Entity::takeDamage()
 void Entity::blit(DynamicPixelBuffer &buf)
 {
 	if(hittime > 0.0f) {
-		HitShader hs{ getSprite(), hittime, HIT_TIME };
+		HitShader hs{ getSprite(), (hittime / HIT_TIME), (hitpoints == 0) };
 		buf.blit_topleft(topleft, hs);
 	} else if(hitpoints > 0) {
 		buf.blit_topleft(topleft, getSprite());
diff --git a/PixelShaders.cpp b/PixelShaders.cpp
index 7ffd413..2552824 100644
--- a/PixelShaders.cpp
+++ b/PixelShaders.cpp
@@ -22,5 +22,5 @@ Color HitShader::peekUnchecked(PixelPoint const &pos) const
 	if(src == _t) {
 		return _t;
 	}
-	return (dist(rng.rng) > 0.95f) ? _3 : src;
+	return (dist(rng.rng) > 0.95f) ? _3 : (is_final ? _t : src);
 }
diff --git a/PixelShaders.hpp b/PixelShaders.hpp
index 33429e6..cb83bc9 100644
--- a/PixelShaders.hpp
+++ b/PixelShaders.hpp
@@ -6,9 +6,10 @@
 class HitShader : public ShadedPixelBuffer {
 public:
 	float percent;
+	bool is_final;
 
-	HitShader(PixelBuffer const &input, float time_cur, float time_total)
-		: ShadedPixelBuffer(input), percent(time_cur / time_total) {
+	HitShader(PixelBuffer const &input, float percent, bool is_final)
+		: ShadedPixelBuffer(input), percent(percent), is_final(is_final) {
 	}
 
 	virtual Color peekUnchecked(PixelPoint const &pos) const;
-- 
GitLab