blob: f6837bb4537fbe6a9bea2ea2518fd5ab6392521f (
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
#pragma once
#include "animation.h"
#include "map.h"
#include "size2d.h"
#include "vec2d.h"
struct SDL_Renderer;
struct Player
{
enum class States
{
REST = 0,
TAKEOFF = 1,
FLIGHT = 2,
LANDING = 3,
WALK = 4,
FALL = 5
};
explicit Player(SDL_Renderer* renderer);
void set_state(const States& s);
void handle_keyboard();
const Animation& sprite(const States& state);
void update_state(const double dt, const Map& map);
void draw();
// coordinates of the character
vec2d<double> pos{150., 200.};
// speed of the character
vec2d<double> speed{0., 0.};
/*!
* \brief backwards - facing left or right
*/
bool backwards{false};
// will be used to differentiate high jump from a long jump
vec2d<double> jump{0., 0.};
/*!
* \brief state - current sprite
*/
States state{States::REST};
TimeStamp timestamp{Clock::now()};
/*!
* \brief renderer - draw here
*/
SDL_Renderer* renderer{nullptr};
// size of the sprite on the screen
size2d<int> sprite_size{256, 128};
/*!
* \brief sprites - sprite sequences to be drawn
*/
const std::array<Animation, 6> sprites;
};
|