aboutsummaryrefslogtreecommitdiffstats
path: root/src/entities.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/entities.cpp')
-rw-r--r--src/entities.cpp34
1 files changed, 27 insertions, 7 deletions
diff --git a/src/entities.cpp b/src/entities.cpp
index d5d9af2..58c1651 100644
--- a/src/entities.cpp
+++ b/src/entities.cpp
@@ -111,18 +111,38 @@ void Entity::spawn(float x, float y)
void Entity::takeHit(unsigned int _health, unsigned int cooldown)
{
- // modify variables
- health = fmax(health - _health, 0);
- forcedMove = true;
- hitCooldown = cooldown;
+ if (hitCooldown <= 1) {
+ // modify variables
+ health = fmax(health - _health, 0);
+ forcedMove = true;
+ hitCooldown = cooldown;
+
+ // pushback
+ vel.x = player->left ? -0.5f : 0.5f;
+ vel.y = 0.2f;
+ }
+}
+
+unsigned int Entity::coolDown()
+{
+ return hitCooldown;
+}
- // pushback
- vel.x = player->left ? -0.5f : 0.5f;
- vel.y = 0.2f;
+void Entity::setCooldown(unsigned int c)
+{
+ hitCooldown = c;
}
+
+
void Entity::handleHits(void)
{
+ int c = hitCooldown - game::time::getDeltaTime();
+ if (c >= 0)
+ hitCooldown = c;
+ else
+ hitCooldown = 0;
+
if (!forcedMove)
return;