summaryrefslogtreecommitdiffhomepage
path: root/Player.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Player.cpp')
-rw-r--r--Player.cpp12
1 files changed, 11 insertions, 1 deletions
diff --git a/Player.cpp b/Player.cpp
index 490b810..4e13ad0 100644
--- a/Player.cpp
+++ b/Player.cpp
@@ -12,12 +12,14 @@ static constexpr float ACCELERATION {1800};
static constexpr float MAX_SPEED {180};
static constexpr float DAMP {2200};
static constexpr float MARGIN {0.3f};
+static constexpr float HIT_INVUL {1.2f};
static float damped_velocity(float dt, float direction, float velocity);
Player::Player() :
+ m_invulnerability {HIT_INVUL / 2.f},
m_position {400, 450},
m_velocity {0, 0},
m_controller {std::make_unique<KeyboardController>()}
@@ -33,13 +35,21 @@ Player::update(const float dt)
m_velocity.y = std::clamp(damped_velocity(dt, direction.y, m_velocity.y), -MAX_SPEED, MAX_SPEED);
m_position.x += m_velocity.x * dt;
m_position.y += m_velocity.y * dt;
+ m_invulnerability -= dt;
}
void
Player::draw()
{
- DrawCircle(m_position.x, m_position.y, 4, LIGHTGRAY);
+ DrawCircle(m_position.x, m_position.y, 4, m_invulnerability > 0 ? RED : LIGHTGRAY);
+}
+
+
+void
+Player::hit()
+{
+ m_invulnerability = HIT_INVUL;
}