blob: c5be5a8dd2cb6c9d9401f9e7942b3920a1d23594 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
#include "Player.h"
#include <algorithm>
#include <memory>
#include <raylib.h>
#include "KeyboardController.h"
static constexpr float ACCELERATION {1900};
static constexpr float MAX_SPEED {160};
Player::Player() :
m_position {400, 450},
m_velocity {0, 0},
m_controller {std::make_unique<KeyboardController>()}
{
}
void
Player::update(const float dt)
{
const auto direction = m_controller->direction();
const Vector2 acceleration {
direction.x * ACCELERATION,
direction.y * ACCELERATION,
};
m_velocity.x = std::clamp(m_velocity.x + acceleration.x * dt, -MAX_SPEED, MAX_SPEED);
m_velocity.y = std::clamp(m_velocity.y + acceleration.y * dt, -MAX_SPEED, MAX_SPEED);
m_position.x += m_velocity.x * dt;
m_position.y += m_velocity.y * dt;
}
void
Player::draw()
{
DrawCircle(m_position.x, m_position.y, 10, LIGHTGRAY);
}
|