-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEntity.h
More file actions
324 lines (296 loc) · 7.89 KB
/
Entity.h
File metadata and controls
324 lines (296 loc) · 7.89 KB
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
//
// Created by Ben Dickson on 5/9/17.
//
#ifndef LIBRARY_ENTITY_H
#define LIBRARY_ENTITY_H
#include <cstdlib>
#include <list>
#include <map>
#include "Point.h"
#include "PhysicalModel.h"
using namespace std;
class Entity
{
public:
static enum EntityType{PLAYER,NPC,PROJECTILE,BOX,SURFACE,ENEMY,GENERIC};
static enum CollisionRule{DAMAGE,HEALTH,KILLS,DIES,BOUNCES,STOPS,GAMEOVER,LEVELCOMPLETE,TRIGGER};
static enum CollisionDirection{ALL,UP,DOWN,LEFT,RIGHT};
static enum Consumables{FUEL,BULLETS,BATTERY,OXYGEN};
static enum Collectibles{KEY,JETPACK};
private:
// graphics / physics rules
map<string,PhysicalModel*> element;
EntityType modelType = GENERIC;
int ec = 0 , r=0; // ec = element count (maintained here for speed) | r = rotation
double x,y , vx = 0.0,vy=0.0, e=0.0 , m=1.0 , vMax=0; // x/y pos | vx/vy velocities | e = elasticity | m = mass
bool canRotate = false;
int renderLayer=3;
bool movable = false;
bool affectedByGravity = false;
string name;
// gameplay / interaction rules
map<EntityType,list<CollisionRule>> collisionRules;
list<CollisionDirection> collisionDirections;
int health = 100;
int damage = 0;
int invincible = true;
map<Consumables,int> bag;
map<Collectibles,bool> belt;
// constructor based stuff
enum ConType{INT,DOUBLE,STRING,ENUM,BOOL};
static map<string,ConType> conImport;
// import values
bool importDouble(string var , double value);
bool importInt(string var, int value);
bool importString(string var, string value);
bool importEnum(string var, string value);
bool importBool(string var, bool value);
public:
inline int elementCount() const;
inline int getRenderLayer();
inline bool isMoving() const;
inline Point getGlobalPos() const;
// modifiers
inline int healthModifier(int h)
{
health+=h;
return health;
}
// getters
inline bool isAffectedByGravity()
{
return affectedByGravity;
}
inline bool isMovable()
{
return movable;
}
inline void enableCollection(Consumables c, int v=0)
{
if(v<0)
{
v=0;
}
map<Consumables,int>::iterator bf=bag.find(c);
if(bf==bag.end())
{
bag.insert(pair<Consumables ,int>(c,v));
}
else
{
((*bf).second)+=v;
}
}
inline void enableCollection(Collectibles c, bool v=false)
{
map<Collectibles,bool>::iterator bf=belt.find(c);
if(bf==belt.end())
{
belt.insert(pair<Collectibles ,bool>(c,v));
}
else
{
((*bf).second)=v;
}
}
bool inline canCollect(Consumables c)
{
return bag.find(c)!=bag.end();
}
bool inline canCollect(Collectibles c)
{
return belt.find(c)!=belt.end();
}
inline int collectConsumable(Consumables c,int count)
{
map<Consumables,int>::iterator bf=bag.find(c);
if(bf==bag.end())
{
return 0;
}
else
{
((*bf).second)+=count;
if(((*bf).second)<0)
{
((*bf).second)=0;
}
return ((*bf).second);
}
}
inline bool collectCollectibles(Collectibles c)
{
map<Collectibles,bool>::iterator bf=belt.find(c);
if(bf==belt.end())
{
return false;
}
else
{
return (((*bf).second)=true);
}
}
// collection setters
inline void addCollisionRule(EntityType k , CollisionRule m)
{
map<EntityType,list<CollisionRule>>::iterator it = find(collisionRules.begin(),collisionRules.end(),k);
if(it == collisionRules.end())
{
list<CollisionRule> ne;
ne.push_back(m);
collisionRules.insert(pair<EntityType,list<CollisionRule>>(k,ne));
}
else
{
((*it).second).push_back(m);
}
}
inline void addCollisionDirection(CollisionDirection c)
{
list<CollisionDirection>::iterator it = find(collisionDirections.begin(),collisionDirections.end(),c);
if(it == collisionDirections.end())
{
collisionDirections.push_back(c);
}
}
// setters
inline void setAffectedByGravity(bool c)
{
affectedByGravity = c;
}
inline void setMovable(bool c)
{
movable = c;
}
inline void setRenderLayer(int c)
{
renderLayer = c;
}
inline void setHealth(int c)
{
health = c;
}
inline void setDamage(int c)
{
damage = c;
}
inline void setX(double nx)
{
x = nx;
}
inline void setY(double ny)
{
y = ny;
}
// constructors and Entity construction methods
inline bool addPhysicalModel(string name, PhysicalModel* m)
{
if(element.find(name)==element.end())
{
element.insert(pair<string,PhysicalModel*>(name,m));
return true;
}
else
{
return false;
}
}
inline bool parseConstructorPair(pair<string,string> p)
{
map<string,ConType>::iterator it = conImport.find(p.first);
if(it!=conImport.end())
{
switch((*it).second)
{
case DOUBLE:
return importDouble(p.first,stod(p.second));
case INT:
return importInt(p.first,stoi(p.second));
case STRING:
return importString(p.first,p.second);
case ENUM:
return importEnum(p.first,p.second);
case BOOL:
return importBool(p.first,p.second=="true");
}
}
return false;
}
Entity(string c_name)
{
name = c_name;
}
/*
Entity(double cx,double cy)
{
x = cx;
y = cy;
};
Entity(double cx,double cy , EntityType cModelType)
{
Entity(cx,cy);
modelType = cModelType;
};
Entity(double cx,double cy , int cr)
{
Entity(cx,cy);
r = cr;
};
Entity(double cx,double cy , int cr, EntityType cModelType)
{
Entity(cx,cy,cr);
modelType = cModelType;
};
Entity(double cx,double cy , EntityType cModelType , double ce)
{
Entity(cx,cy,cModelType);
e = ce;
};
Entity(double cx,double cy , int cr, EntityType cModelType , double ce)
{
Entity(cx,cy,cr,cModelType);
e = ce;
};
Entity(double cx,double cy , int cr, EntityType cModelType , double ce , double cm)
{
Entity(cx,cy,cr,cModelType,ce);
m = cm;
};
Entity(double cx,double cy ,EntityType cModelType , double ce , double cm)
{
Entity(cx,cy,cModelType,ce);
m = cm;
};
Entity(double cx,double cy , int cr , bool cCanRotate)
{
Entity(cx,cy,cr);
canRotate = cCanRotate;
};
Entity(double cx,double cy , int cr, bool cCanRotate, EntityType cModelType)
{
Entity(cx,cy,cr,cModelType);
canRotate = cCanRotate;
};
Entity(double cx,double cy , bool cCanRotate , EntityType cModelType , double ce)
{
Entity(cx,cy,cModelType,ce);
canRotate = cCanRotate;
};
Entity(double cx,double cy , int cr, bool cCanRotate, EntityType cModelType , double ce)
{
Entity(cx,cy,cr,cModelType,ce);
canRotate = cCanRotate;
};
Entity(double cx,double cy , int cr, bool cCanRotate, EntityType cModelType , double ce , double cm)
{
Entity(cx,cy,cr,cModelType,ce,cm);
canRotate = cCanRotate;
};
Entity(double cx,double cy, bool cCanRotate ,EntityType cModelType , double ce , double cm)
{
Entity(cx,cy,cModelType,ce,cm);
canRotate = cCanRotate;
};
*/
};
#endif //LIBRARY_ENTITY_H