-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentities.hpp
183 lines (142 loc) · 2.54 KB
/
entities.hpp
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#pragma once
#include <SFML/Graphics.hpp>
class Actor;
class Game;
class Entity
{
protected:
sf::Sprite sprite;
public:
virtual void update(float deltaTime) = 0;
virtual void collide(Actor &actor) = 0;
void draw();
void setPosition(float x, float y);
const sf::Vector2f &getPosition();
sf::FloatRect getBounds();
};
class Actor: public Entity
{
public:
virtual void jump() = 0;
virtual void bigJump() = 0;
virtual void knock() = 0;
virtual void knockHard() = 0;
virtual void slowDown() = 0;
};
class Player: public Actor
{
struct PlayerState {
bool up: 1;
bool down: 1;
bool left: 1;
bool right: 1;
unsigned int padding: 28;
PlayerState(): up(0), down(0), left(0), right(0) {}
} state;
// time passed going downHill
float downTime;
// true if jumping
bool jumping;
// true if the jump is big (= more height)
bool isBigJump;
// true if it's the descending part of the jump
bool fall;
// height of the jump
float height;
// true if the player has crashed
bool crash;
// time spent after crash
float crashTime;
public:
float speed;
// distance traveled in the vertical direction
float travelAmount;
static void preload();
Player();
void goUp();
void goDown();
void goLeft();
void goRight();
void update(float deltaTime);
void collide(Actor &actor);
void jump();
void bigJump();
void knock();
void knockHard();
void slowDown();
};
class Decal: public Entity
{
public:
enum Type {
BLOOD,
FALL,
TRACKS,
WARNING_SIGN1,
WARNING_SIGN2,
WELCOME_SIGN,
WELCOME_SIGN2,
};
static void preload();
Decal(Type type);
void update(float deltaTime);
void collide(Actor &actor);
};
class ActiveEntity: public Entity
{
public:
};
class Tree: public Entity
{
public:
static void preload();
Tree();
void update(float deltaTime);
void collide(Actor &actor);
};
class Rock: public Entity
{
public:
static void preload();
Rock();
void update(float deltaTime);
void collide(Actor &actor);
};
class Dune: public Entity
{
public:
static void preload();
Dune();
void update(float deltaTime);
void collide(Actor &actor);
};
class Jump: public Entity
{
public:
static void preload();
Jump();
void update(float deltaTime);
void collide(Actor &actor);
};
class Monster: public Actor
{
enum State {
CHASING,
EATING,
CELEBRATING
} state;
Game *game;
// for animations
float time;
float eatingTime;
public:
static void preload();
Monster(Game *game);
void update(float deltaTime);
void collide(Actor &actor);
void jump();
void bigJump();
void knock();
void knockHard();
void slowDown();
};