diff options
author | Clyne Sullivan <tullivan99@gmail.com> | 2016-05-02 08:49:54 -0400 |
---|---|---|
committer | Clyne Sullivan <tullivan99@gmail.com> | 2016-05-02 08:49:54 -0400 |
commit | f102149e15ca1ac36cbb4e2627e5ce44f2d5273a (patch) | |
tree | fcf939ba1c26bd25c693ae7b05bd79c00ce2a691 /src/entities.cpp | |
parent | 6a728a46d837384074228959d6330ba29e03aee0 (diff) | |
parent | 13cd55136ffd09afd9f4828a00716ed9f94f0e0b (diff) |
Merge branch 'master' of https://github.com/tcsullivan/gamedev
Diffstat (limited to 'src/entities.cpp')
-rw-r--r-- | src/entities.cpp | 34 |
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; |