diff options
Diffstat (limited to 'Player.cpp')
-rw-r--r-- | Player.cpp | 12 |
1 files changed, 11 insertions, 1 deletions
@@ -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; } |