-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathentity.hh
More file actions
105 lines (83 loc) · 2 KB
/
Copy pathentity.hh
File metadata and controls
105 lines (83 loc) · 2 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
#ifndef _GRAVITY_ENTITY_HH_
#define _GRAVITY_ENTITY_HH_
#include "mesh.hh"
#include <box2d/box2d.h>
#include <vector>
#include <ostream>
using namespace std;
struct TrailPoint {
TrailPoint() :
time(0.0)
{}
TrailPoint(b2Vec2 pos, float time) :
pos(pos),
time(time)
{}
b2Vec2 pos;
float time;
};
struct Trail {
Trail() :
size(0),
time(0.0)
{}
int size;
float time;
vector<TrailPoint> points;
};
enum class CollectibleType {
PLUS_SCORE,
MINUS_SCORE,
PLUS_TIME,
MINUS_TIME,
SPAWN_PLANET,
};
struct Entity {
protected:
void SaveBody(const b2Body *b, ostream &s) const;
void SaveTrail(const Trail &t, ostream &s) const;
b2Body *LoadBody(istream &s, b2World *world);
Trail LoadTrail(istream &s);
public:
Entity();
~Entity();
bool hasPhysics;
b2Body *body;
bool hasGravity;
float gravityCoeff;
bool hasTrail;
Trail trail;
bool isAffectedByGravity;
bool isSun;
bool isEnemy;
bool isPlanet;
int planetWhooshChannel;
bool isCollectible;
bool hasScore;
int score;
bool hasTime;
int time;
bool spawnPlanet;
bool isDrawable;
Mesh *mesh;
void Save(ostream &s) const;
void Load(istream &s, b2World *world);
static Entity *CreatePlanet(b2World *world,
b2Vec2 pos,
float radius,
float density,
b2Vec2 v0=b2Vec2(0, 0));
static Entity *CreateSun(b2World *world,
b2Vec2 pos,
float radius,
float density,
float gravityCoeff);
static Entity *CreateCollectible(b2World *world,
b2Vec2 pos,
CollectibleType type);
static Entity *CreateEnemyShip(b2World *world,
b2Vec2 pos,
b2Vec2 velocity,
float angle);
};
#endif /* _GRAVITY_ENTITY_HH_ */