gamedev
entities.h
1 #ifndef ENTITIES_H
2 #define ENTITIES_H
3 
4 #include <common.h>
5 #include <Quest.h>
6 #include <inventory.h>
7 
8 #define DEBUG
9 
10 #define NPCp(n) ((NPC *)n)
11 #define Structurep(n) ((Structures *)n)
12 #define Mobp(n) ((Mob *)n)
13 
14 #define PLAYER_INV_SIZE 30 // The size of the player's inventory
15 #define NPC_INV_SIZE 3 // Size of an NPC's inventory
16 
17 enum _TYPE { //these are the main types of entities
18  OBJECTT = -2,
19  STRUCTURET = -1,
20  PLAYERT,
21  NPCT,
22  MOBT
23 };
24 
25 enum GENDER{
26  MALE,
27  FEMALE,
28  NONE
29 };
30 
31 enum MOB_SUB {
32  MS_RABBIT = 1,
33  MS_BIRD,
34  MS_TRIGGER
35 };
36 
37 class Entity{
38 public:
39  Inventory *inv;
40 
41  /*
42  * Movement variables
43  */
44 
45  vec2 loc;
46  vec2 vel;
47 
48  float width;
49  float height;
50 
51  float speed; // A speed factor for X movement
52 
53  /*
54  * Movement flags
55  */
56 
57  bool near; // Causes name to display
58  bool canMove; // Enables movement
59  bool right,left; // Direction faced by Entity
60  bool alive;
61  unsigned char ground; // Shows how the Entity is grounded (if it is)
62 
63  /*
64  * Health variables
65  */
66 
67  float health;
68  float maxHealth;
69 
70  /*
71  * Identification variables
72  */
73 
74  _TYPE type;
75  int subtype;
76 
77  char *name;
78  GENDER gender;
79 
80  Texturec *tex;
81 
82 
83  void draw(void);
84  void spawn(float, float);
85 
86  int ticksToUse; // Used by wander()
87 
88  virtual void wander(int){}
89  virtual void interact(){}
90 
91  virtual ~Entity(){}
92 };
93 
94 class Player : public Entity {
95 public:
96  QuestHandler qh;
97  bool light = false;
98 
99  Player();
100  ~Player();
101  void interact();
102 };
103 
104 class NPC : public Entity{
105 public:
106  std::vector<int (*)(NPC *)>aiFunc;
107 
108  NPC();
109  ~NPC();
110 
111  void addAIFunc(int (*func)(NPC *),bool preload);
112  void interact();
113  void wander(int);
114 };
115 
116 class Structures : public Entity{
117 public:
118  void *inWorld;
119  void *inside;
120 
121  Structures();
122  ~Structures();
123 
124  unsigned int spawn(_TYPE, float, float);
125 };
126 
127 class Mob : public Entity{
128 public:
129  double init_y;
130  void (*hey)(Mob *callee);
131 
132  Mob(int);
133  Mob(int,unsigned int);
134  ~Mob();
135 
136  void wander(int);
137 };
138 
139 class Object : public Entity{
140 private:
141  int identifier;
142 public:
143  char *pickupDialog;
144  bool questObject = false;
145 
146  Object(ITEM_ID id, bool qo, const char *pd);
147  ~Object();
148 
149  void interact(void);
150 };
151 #endif // ENTITIES_H
152 
Definition: entities.h:139
Definition: entities.h:127
Definition: entities.h:116
Definition: common.h:46
Definition: Texture.h:12
Definition: entities.h:37
Definition: entities.h:104
Definition: inventory.h:64
Definition: entities.h:94
Definition: Quest.h:21