Dumb-ways-to-memorize
2D game
Data Structures | Macros | Functions | Variables
entity.h File Reference
#include "globals.h"
#include "graphics.h"
#include "ai_interpret.h"
+ Include dependency graph for entity.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  entity_t
 

Macros

#define MAX_ENTITIES   250
 
#define ENTITY_DIR_LEFT   0
 
#define ENTITY_DIR_RIGHT   1
 

Functions

int InitEntitySystem ()
 
entity_t * InitNewEntity ()
 
entity_t * FindNextFreeCachePos ()
 
entity_t * FindCachedEntity (const char *name)
 
entity_t * FindEntity (const char *name)
 
entity_t * FindFreeEntity (int *position)
 
entity_t * LookForEntityAtPos (vec2_t position)
 
int Distance2Entity (entity_t *self, entity_t *other)
 
void RunEntities ()
 
void DrawEntities ()
 
void PrintEntity (entity_t *ent)
 
void FreeEntity (entity_t *ent)
 
void FreeNonPlayerEntities ()
 
void ShutdownEntitySystem ()
 
void DrawGeneric (entity_t *self)
 
void DrawPlayer (entity_t *self)
 
void ThinkGeneric (entity_t *self)
 
void ThinkPlayer (entity_t *self)
 
void ThinkEnemy (entity_t *self)
 
void TouchGeneric (entity_t *self, entity_t *other, int type)
 
void TouchPlayer (entity_t *self, entity_t *other, int type)
 
void TouchEnemy (entity_t *self, entity_t *other, int type)
 
void TouchGoal (entity_t *self, entity_t *other, int type)
 

Variables

entity_t * gEntityDictionary
 
entity_t * gEntities
 
int gLastEntity
 
void(*)(entity_t *) GetFunctionAI (ai_function_t *data)
 

Macro Definition Documentation

#define ENTITY_DIR_LEFT   0

Definition at line 9 of file entity.h.

Referenced by DoPlayerThink().

#define ENTITY_DIR_RIGHT   1

Definition at line 10 of file entity.h.

Referenced by DoPlayerThink(), and Spawn().

#define MAX_ENTITIES   250

Function Documentation

int Distance2Entity ( entity_t *  self,
entity_t *  other 
)

Distance 2 entity other from entity self.

Parameters
[in,out]selfIf non-null, the class instance that this method operates on.
[in,out]otherIf non-null, the other entity.
Returns
An int.
Author
Anthony Rios
Date
3/29/2016

Definition at line 371 of file entity.c.

Referenced by ThinkEnemy().

372 {
373  int x, y;
374  x = self->mPosition.x - other->mPosition.x;
375  y = self->mPosition.y - self->mPosition.y;
376  return powf(powf(x, 2) + powf(y, 2), (float) 1/2);
377 }
void DrawEntities ( )

Draw entities, if they have draw functions.

Author
Anthony Rios
Date
3/29/2016

Definition at line 264 of file entity.c.

References Draw(), gEntities, and MAX_ENTITIES.

Referenced by DrawPlaying().

265 {
266  int i;
267  if(!gEntities)
268  {
269  return;
270  }
271  for(i = 0; i < MAX_ENTITIES; i++)
272  {
273  if(!gEntities[i].Draw)
274  {
275  continue;
276  }
277  gEntities[i].Draw(&gEntities[i]);
278  }
279 }
#define MAX_ENTITIES
Definition: entity.h:8
entity_t * gEntities
Definition: entity.c:11
void Draw()
Definition: game.c:547
void DrawGeneric ( entity_t *  self)

Draws the entity via self->mAnimation if set, or the first sprite which is idle.

Parameters
[in,out]selfIf non-null, the class instance that this method operates on.
Author
Anthony Rios
Date
3/29/2016

Definition at line 17 of file entity.c.

References ANIMATION_IDLE, DrawSprite(), and gRenderer.

Referenced by InitPlayer(), LoadLevel(), and ParseToEntity().

18 {
19  if(!self)
20  {
21  return;
22  }
23  if(!self->mSprites)
24  {
25  return;
26  }
27  if(self->mAnimation)
28  {
29  //IncrementFrame(self->mAnimation);
30  DrawSprite(self->mAnimation, &self->mCurrentFrame, &self->mPosition, gRenderer);
31  } else
32  {
33  //IncrementFrame(self->mSprites[ANIMATION_IDLE]);
34  DrawSprite(self->mSprites[ANIMATION_IDLE], &self->mCurrentFrame, &self->mPosition, gRenderer);
35  }
36 
37 }
SDL_Renderer * gRenderer
Definition: graphics.c:10
int DrawSprite(sprite_t *sprite, int *frame, vec2_t *position, SDL_Renderer *renderer)
Definition: graphics.c:152
void DrawPlayer ( entity_t *  self)

Definition at line 40 of file entity.c.

41 {
42  //DrawSprite(self->mSprites, &self->mPosition, gRenderer);
43 }
entity_t* FindCachedEntity ( const char *  name)

Searches for the cached entity whose name matches given str.

Parameters
nameThe name of the entity.
Returns
null if it fails, else the found cached entity.
Author
Anthony Rios
Date
3/29/2016

Definition at line 301 of file entity.c.

References gEntityDictionary, and MAX_ENTITIES.

Referenced by AttackAI(), InitPlayer(), JumpAI(), LoadLevel(), MoveAI(), NothingAI(), ParseToPowerUp(), and WalkAI().

302 {
303  int i;
304  for(i = 0; i < MAX_ENTITIES; i++)
305  {
306  if(!gEntityDictionary[i].mName)
307  break;
308  if(!strcmp(name, gEntityDictionary[i].mName))
309  {
310  return &gEntityDictionary[i];
311  }
312  }
313  return NULL;
314 }
entity_t * gEntityDictionary
Definition: game.c:41
#define MAX_ENTITIES
Definition: entity.h:8
entity_t* FindEntity ( const char *  name)

Searches for the first entity with the name of given str.

Parameters
nameThe name of the searched for entity.
Returns
null if it fails, else the found entity.
Author
Anthony Rios
Date
3/29/2016

Definition at line 316 of file entity.c.

References gEntities, and MAX_ENTITIES.

Referenced by ThinkEnemy().

317 {
318  int i;
319  for(i = 0; i < MAX_ENTITIES; i++)
320  {
321  if(!gEntities[i].mName)
322  continue;
323  if(!strcmp(name, gEntities[i].mName))
324  {
325  return &gEntities[i];
326  }
327  }
328  return NULL;
329 }
#define MAX_ENTITIES
Definition: entity.h:8
entity_t * gEntities
Definition: entity.c:11
entity_t* FindFreeEntity ( int *  position)

Searches for the first free entity.

Parameters
[in,out]positionIf non-null, the position.
Returns
null if it fails, else the found free entity.
Author
Anthony Rios
Date
3/29/2016

Definition at line 331 of file entity.c.

References gEntities, gLastEntity, and MAX_ENTITIES.

Referenced by InitNewEntity().

332 {
333  int i;
334  for(i = gLastEntity; i < MAX_ENTITIES; i++)
335  {
336  if(!gEntities[i].mName)
337  {
338  if(position)
339  *position = i;
340  return &gEntities[i];
341  }
342  }
343  for(i = 0; i < gLastEntity; i++)
344  {
345  if(!gEntities[i].mName)
346  {
347  if(position)
348  *position = i;
349  return &gEntities[i];
350  }
351  }
352  return NULL;
353 }
#define MAX_ENTITIES
Definition: entity.h:8
int gLastEntity
Definition: entity.c:12
entity_t * gEntities
Definition: entity.c:11
entity_t* FindNextFreeCachePos ( )

Searches for the next free cache position in gEntitiesDictionary.

Returns
null if it fails, else the found free cache position.
Author
Anthony Rios
Date
3/29/2016

Definition at line 250 of file entity.c.

References gEntityDictionary, and MAX_ENTITIES.

Referenced by LoadEntityData().

251 {
252  int i;
253  for(i = 0; gEntityDictionary[i].mName; i++)
254  {
255  ;
256  }
258  {
259  return NULL;
260  }
261  return &gEntityDictionary[i];
262 }
entity_t * gEntityDictionary
Definition: game.c:41
#define MAX_ENTITIES
Definition: entity.h:8
void FreeEntity ( entity_t *  ent)

Free entity.

Note
right now it just acts like memset(0) on entities in the global Entities scope. But it free's any other data that isn't globally set.
Parameters
[in,out]entIf non-null, the ent.
Author
Anthony Rios
Date
3/29/2016

Definition at line 379 of file entity.c.

References gEntities, and MAX_ENTITIES.

Referenced by Destroy(), FreeNonPlayerEntities(), LoadLevel(), ShutdownEntitySystem(), ThinkGeneric(), and ThinkPlayer().

380 {
381  int i, isGlobal = 0;
382  if(!ent)
383  return;
384  i = 0;
385  //if(ent->mSprites)
386  //{
387  //while(ent->mSprites[i])
388  //{
389  //FreeSprite(ent->mSprites[i]);
390  //i++;
391  //}
392  //free(ent->mSprites);
393  //}
394  for(i = 0; i < MAX_ENTITIES; i++)
395  {
396  if(ent == &gEntities[i])
397  {
398  isGlobal = 1;
399  memset(ent, 0, sizeof(entity_t));
400  }
401  }
402  if(!isGlobal)
403  {
404  free(ent);
405  }
406 
407 }
#define MAX_ENTITIES
Definition: entity.h:8
entity_t * gEntities
Definition: entity.c:11
void FreeNonPlayerEntities ( )

Frees the non player entities, use for Destroy World.

Author
Anthony Rios
Date
3/29/2016

Definition at line 409 of file entity.c.

References FreeEntity(), gEntities, gPlayer, and MAX_ENTITIES.

Referenced by LoadLevel(), and ThinkPlayer().

410 {
411  int i , entities;
412  if(!gEntities)
413  {
414  return;
415  }
416 
417  for(i = 0; i < MAX_ENTITIES; i++)
418  {
419  if(&gEntities[i] == (entity_t*) gPlayer)
420  {
421  continue;
422  }
423  FreeEntity(&gEntities[i]);
424  }
425 }
#define MAX_ENTITIES
Definition: entity.h:8
entity_t * gEntities
Definition: entity.c:11
void FreeEntity(entity_t *ent)
Definition: entity.c:379
entity_t * gPlayer
Definition: player.c:9
int InitEntitySystem ( )

Init entity system.

Returns
An int of failure state. 0 if good, -1 if error.
Author
Anthony Rios
Date
3/29/2016

Definition at line 217 of file entity.c.

References gEntities, gEntityDictionary, gLastEntity, and MAX_ENTITIES.

Referenced by Setup().

218 {
219  if( (gEntities = (entity_t*) malloc(sizeof(entity_t)*MAX_ENTITIES)) == NULL )
220  {
221  printf("Couldn't alloc EntitySys");
222  return -1;
223  }
224  if( (gEntityDictionary = (entity_t*) malloc(sizeof(entity_t)*MAX_ENTITIES)) == NULL )
225  {
226  printf("Couldn't alloc EntitySys");
227  return -1;
228  }
229  memset(gEntities, 0, sizeof(entity_t)*MAX_ENTITIES);
230  memset(gEntityDictionary, 0, sizeof(entity_t)*MAX_ENTITIES);
231  gLastEntity = 0;
232  return 0;
233 }
entity_t * gEntityDictionary
Definition: game.c:41
#define MAX_ENTITIES
Definition: entity.h:8
int gLastEntity
Definition: entity.c:12
entity_t * gEntities
Definition: entity.c:11
entity_t* InitNewEntity ( )

Init new entity in the memory of global entity space.

Returns
null if it fails, else a pointer to an entity_t.
Author
Anthony Rios
Date
3/29/2016

Definition at line 235 of file entity.c.

References FindFreeEntity(), gEntities, and gLastEntity.

Referenced by InitPlayer(), LoadLevel(), and Spawn().

236 {
237  int pos;
238  entity_t *retVal;
239  if(gEntities == NULL)
240  {
241  printf("Entity system unintialiazeed");
242  exit(-1);
243  }
244 
245  retVal = FindFreeEntity(&pos);
246  gLastEntity = pos;
247  return retVal;
248 }
int gLastEntity
Definition: entity.c:12
entity_t * gEntities
Definition: entity.c:11
entity_t * FindFreeEntity(int *position)
Definition: entity.c:331
entity_t* LookForEntityAtPos ( vec2_t  position)

Look for entity at position.

Parameters
positionThe position.
Returns
null if it fails, else a pointer to an entity_t.
Author
Anthony Rios
Date
3/29/2016

Definition at line 355 of file entity.c.

References gEntities, MAX_ENTITIES, vec2_t::x, and vec2_t::y.

Referenced by GetAtPoint().

356 {
357  int i;
358  for(i = 0; i < MAX_ENTITIES; i++)
359  {
360  if(!gEntities[i].mName)
361  continue;
362  if( (gEntities[i].mPosition.x > position.x > gEntities[i].mPosition.x + gEntities[i].mSprites[0]->mSize.x)
363  && (gEntities[i].mPosition.y > position.y > gEntities[i].mPosition.x + gEntities[i].mSprites[0]->mSize.y))
364  {
365  return &gEntities[i];
366  }
367  }
368  return NULL;
369 }
int y
Definition: globals.h:22
#define MAX_ENTITIES
Definition: entity.h:8
entity_t * gEntities
Definition: entity.c:11
int x
Definition: globals.h:21
void PrintEntity ( entity_t *  ent)

Prints the entities data, used for debug.

Parameters
[in,out]entIf non-null, the ent.
Author
Anthony Rios
Date
3/29/2016

Definition at line 195 of file parseentity.c.

Referenced by ParseToEntity().

196 {
197  int i;
198  if(!ent)
199  {
200  printf("Print Entity given NULL Entity \n");
201  return;
202  }
203  if(!ent->mName)
204  {
205  printf("Print Entity given NULL Entity Name");
206  return;
207  }
208  printf("< Entity \n");
209  printf("Entity Name : %s \n", ent->mName);
210  printf("Entity CollisionType : %d \n", ent->mCollisionType);
211  printf("Enity State : %d \n", ent->mEntityState);
212  if(!ent->mSprites)
213  {
214  printf("No Sprites loaded \n");
215  return;
216  }
217  if(!ent->mSprites[0])
218  {
219  printf("No Sprites loaded \n");
220  return;
221  }
222  printf("Entity Sprites : %s \n", ent->mSprites[0]->name);
223  for(i = 1; ent->mSprites[i]; i++)
224  {
225  printf(" %s ", ent->mSprites[i]->name);
226  }
227  printf(" Entity > \n");
228 
229 }
void RunEntities ( )

Executes the entities think functions.

Note
I think I have the logic wrong..
Author
Anthony Rios
Date
3/29/2016

Definition at line 281 of file entity.c.

References gCurrentTime, gEntities, and MAX_ENTITIES.

Referenced by UpdatePlaying().

282 {
283  int i;
284  if(!gEntities)
285  {
286  return;
287  }
288  for(i = 0; i < MAX_ENTITIES; i++)
289  {
290  if(!gEntities[i].Think || !gEntities[i].mName)
291  {
292  continue;
293  }
294  if( gCurrentTime > gEntities[i].mNextThink)
295  {
296  gEntities[i].Think(&gEntities[i]);
297  }
298  }
299 }
unsigned int gCurrentTime
Definition: game.c:50
#define MAX_ENTITIES
Definition: entity.h:8
entity_t * gEntities
Definition: entity.c:11
void ShutdownEntitySystem ( )

Shutdown entity system, frees all the entities.

Author
Anthony Rios
Date
3/29/2016

Definition at line 427 of file entity.c.

References FreeEntity(), gEntities, and MAX_ENTITIES.

428 {
429  int i;
430  if(!gEntities)
431  return;
432  for(i = 0; i < MAX_ENTITIES; i++)
433  {
434  if(!gEntities[i].mName)
435  continue;
436  FreeEntity(&gEntities[i]);
437  }
438  free(gEntities);
439 }
#define MAX_ENTITIES
Definition: entity.h:8
entity_t * gEntities
Definition: entity.c:11
void FreeEntity(entity_t *ent)
Definition: entity.c:379
void ThinkEnemy ( entity_t *  self)

The modular think function for enemy entities with an AI.

Parameters
[in,out]selfIf non-null, the class instance that this method operates on.
Author
Anthony Rios
Date
3/29/2016

Definition at line 102 of file entity.c.

References AI_FLAG_CHECK_OBJECT, AI_FLAG_CHECK_PLAYER, AI_VAR_CHECK, Distance2Entity(), FindEntity(), GetFunctionAI, and gPlayer.

Referenced by LoadLevel().

103 {
104  if(!self) return;
105  if(!self->mData) return;
106  if(self->mData->mFlags & AI_FLAG_CHECK_OBJECT)
107  {
108  if(!self->mData->mObjectCheck)
109  {
110  self->mData = self->mData->mLink;
111  return;
112  }
113  if( Distance2Entity(self, FindEntity(self->mData->mObjectCheck)) < self->mData->mVariables[AI_VAR_CHECK])
114  {
115  if(GetFunctionAI(self->mData))
116  {
117  GetFunctionAI(self->mData)(self);
118  }
119  }
120  } else if (self->mData->mFlags & AI_FLAG_CHECK_PLAYER)
121  {
122  if(Distance2Entity(self, (entity_t*)gPlayer) < self->mData->mVariables[AI_VAR_CHECK])
123  {
124  if(GetFunctionAI(self->mData))
125  {
126  GetFunctionAI(self->mData)(self);
127  }
128  }
129  } else
130  {
131  if(GetFunctionAI(self->mData))
132  {
133  GetFunctionAI(self->mData)(self);
134  }
135  }
136 
137 }
entity_t * FindEntity(const char *name)
Definition: entity.c:316
void(*)(entity_t *) GetFunctionAI(ai_function_t *data)
Definition: ai_interpret.c:238
entity_t * gPlayer
Definition: player.c:9
int Distance2Entity(entity_t *self, entity_t *other)
Definition: entity.c:371
void ThinkGeneric ( entity_t *  self)

Generic think function, checks health and dies when health <= 0

Parameters
[in,out]selfIf non-null, the class instance that this method operates on.
Author
Anthony Rios
Date
3/29/2016

Definition at line 45 of file entity.c.

References FRAME_DELAY, FreeEntity(), and gCurrentTime.

Referenced by ParseToEntity().

46 {
47  if(!self)
48  {
49  return;
50  }
51  if(self->mHealth <= 0)
52  {
53  self->Think = FreeEntity;
54  }
55 
56  self->mNextThink = gCurrentTime + 2*FRAME_DELAY;
57 }
unsigned int gCurrentTime
Definition: game.c:50
#define FRAME_DELAY
Definition: globals.h:135
void FreeEntity(entity_t *ent)
Definition: entity.c:379
void ThinkPlayer ( entity_t *  self)

The player think function, handles lives ,gamestate switching , and input.

Parameters
[in,out]selfIf non-null, the class instance that this method operates on.
Author
Anthony Rios
Date
3/29/2016

Definition at line 59 of file entity.c.

References BUTTON_NO_INPUT, DoPlayerThink(), FreeEntity(), FreeNonPlayerEntities(), gButtonQ, gController, gCurrentPowerUp, gCurrentTime, gGameState, gPlayer, gPlayerLives, GUESS, PLAYER_LIVES, and START.

Referenced by InitPlayer().

60 {
61  //Do input control
62  if(!self) return;
64  {
65  DoPlayerThink(self, gButtonQ);
66  } else if(SDL_GameControllerGetButton(gController, SDL_CONTROLLER_BUTTON_DPAD_LEFT))
67  {
68  DoPlayerThink(self, SDL_CONTROLLER_BUTTON_DPAD_LEFT);
69  } else if(SDL_GameControllerGetButton(gController, SDL_CONTROLLER_BUTTON_DPAD_RIGHT))
70  {
71  DoPlayerThink(self, SDL_CONTROLLER_BUTTON_DPAD_RIGHT);
72  } else if(SDL_GameControllerGetButton(gController, SDL_CONTROLLER_BUTTON_B))
73  {
74  if(gCurrentPowerUp)
75  {
76  //If infinite use
77  if(!gCurrentPowerUp->UpdateUse)
78  {
79  self->PowerUp(gCurrentPowerUp);
80  }
81  }
82  }
83  self->mNextThink = gCurrentTime + 1; //Player always thinks
84  if(self->mHealth < 0)
85  {
86  if(gPlayerLives < 0)
87  {
88  printf("You died, Game over. Start a new game");
92  gGameState = START;
93  } else
94  {
95  printf("You died, select your powerups again \n");
96  gPlayerLives--;
97  gGameState = GUESS;
98  }
99  }
100 }
Definition: globals.h:87
#define PLAYER_LIVES
Definition: player.h:6
unsigned int gCurrentTime
Definition: game.c:50
void FreeNonPlayerEntities()
Definition: entity.c:409
SDL_GameController * gController
Definition: game.c:48
SDL_GameControllerButton gButtonQ
Definition: game.c:49
#define BUTTON_NO_INPUT
GameState gGameState
Definition: game.c:44
int gPlayerLives
Definition: player.c:10
void DoPlayerThink(void *player, SDL_GameControllerButton button)
void FreeEntity(entity_t *ent)
Definition: entity.c:379
Definition: globals.h:86
power_t * gCurrentPowerUp
Definition: parsepowerup.c:16
entity_t * gPlayer
Definition: player.c:9
void TouchEnemy ( entity_t *  self,
entity_t *  other,
int  type 
)

The touch function for an enemy, currently does nothing.

Parameters
[in,out]selfIf non-null, the class instance that this method operates on.
[in,out]otherIf non-null, the other.
typeThe type.
Author
Anthony Rios
Date
3/30/2016

Definition at line 196 of file entity.c.

References COLLISION_TYPE_RAGDOLL, and COLLISION_TYPE_STATIC.

197 {
198  switch(other->mCollisionType)
199  {
201  break;
203  break;
204  default:
205  break;
206  }
207 }
void TouchGeneric ( entity_t *  self,
entity_t *  other,
int  type 
)

Generic touch function, Receives pain from touch and inflict pain on touch depending on hazard types.

Parameters
[in,out]selfIf non-null, the class instance that this method operates on.
[in,out]otherIf non-null, the other.
typeThe type.
Author
Anthony Rios
Date
3/29/2016

Definition at line 139 of file entity.c.

References ANIMATION_HIT, COLLISION_TYPE_RAGDOLL, COLLISION_TYPE_STATIC, CountMem(), FRAME_DELAY, HAZARD_DAMAGE, and HAZARD_STUN_FRAMES.

Referenced by LoadLevel(), and ParseToEntity().

140 {
141  switch(type)
142  {
143  case(COLLISION_TYPE_STATIC):
144  {
145  if(! (other->mHazards & self->mHazards) )
146  {
147  self->mHealth -= HAZARD_DAMAGE;
148  self->mAnimation = ANIMATION_HIT >= CountMem(self->mSprites, sizeof(sprite_t*)) ? NULL : self->mSprites[ANIMATION_HIT];
149  self->mNextThink += HAZARD_STUN_FRAMES*FRAME_DELAY;
150  }
151  break;
152  }
154  {
155  if(! (other->mHazards & self->mHazards) )
156  {
157  self->mHealth -= HAZARD_DAMAGE;
158  other->mHealth -= HAZARD_DAMAGE;
159  self->mAnimation = ANIMATION_HIT >= CountMem(self->mSprites, sizeof(sprite_t*)) ? NULL : self->mSprites[ANIMATION_HIT];
160  }
161  }
162  default:
163  break;
164  }
165 }
int CountMem(void *src, int size_type)
Definition: mymath.c:51
#define HAZARD_STUN_FRAMES
Definition: globals.h:101
#define HAZARD_DAMAGE
Definition: globals.h:100
#define FRAME_DELAY
Definition: globals.h:135
void TouchGoal ( entity_t *  self,
entity_t *  other,
int  type 
)

The touch function for the goal entity / flag. Switches gamestate based on if you won or should go to the next level.

Parameters
[in,out]selfIf non-null, the class instance that this method operates on.
[in,out]otherIf non-null, the other entity it touched.
typeThe type.
Author
Anthony Rios
Date
3/29/2016

Definition at line 209 of file entity.c.

References CHOOSE, CountMem(), gGameState, gPlayer, gSelectedPowerUps, gUsedPowerUps, and START.

Referenced by LoadLevel().

210 {
211  if(other == gPlayer)
212  {
213  gGameState = CountMem(gUsedPowerUps, sizeof(char*)) >= CountMem(gSelectedPowerUps, sizeof(char*)) ? START : CHOOSE;
214  }
215 }
int CountMem(void *src, int size_type)
Definition: mymath.c:51
char ** gUsedPowerUps
Definition: game.c:29
Definition: globals.h:88
GameState gGameState
Definition: game.c:44
char ** gSelectedPowerUps
Definition: game.c:28
Definition: globals.h:86
entity_t * gPlayer
Definition: player.c:9
void TouchPlayer ( entity_t *  self,
entity_t *  other,
int  type 
)

The player touch function called on collision. If he touches a hazard, he gets damaged.

Parameters
[in,out]selfIf non-null, the class instance that this method operates on.
[in,out]otherIf non-null, the other.
typeThe type.
Author
Anthony Rios
Date
3/30/2016

Definition at line 168 of file entity.c.

References ANIMATION_HIT, COLLISION_TYPE_RAGDOLL, COLLISION_TYPE_STATIC, CountMem(), FRAME_DELAY, HAZARD_DAMAGE, and HAZARD_STUN_FRAMES.

Referenced by InitPlayer().

169 {
170  switch(type)
171  {
172  case(COLLISION_TYPE_STATIC):
173  {
174  if(! (other->mHazards & self->mHazards) )
175  {
176  self->mHealth -= HAZARD_DAMAGE;
177  self->mAnimation = ANIMATION_HIT >= CountMem(self->mSprites, sizeof(sprite_t*)) ? NULL : self->mSprites[ANIMATION_HIT];
178  self->mNextThink += HAZARD_STUN_FRAMES*FRAME_DELAY;
179  }
180  break;
181  }
183  {
184  if(! (other->mHazards & self->mHazards) )
185  {
186  self->mHealth -= HAZARD_DAMAGE;
187  self->mAnimation = ANIMATION_HIT >= CountMem(self->mSprites, sizeof(sprite_t*)) ? NULL : self->mSprites[ANIMATION_HIT];
188  self->mNextThink += HAZARD_STUN_FRAMES*FRAME_DELAY;
189  }
190  break;
191  }
192 
193  }
194 }
int CountMem(void *src, int size_type)
Definition: mymath.c:51
#define HAZARD_STUN_FRAMES
Definition: globals.h:101
#define HAZARD_DAMAGE
Definition: globals.h:100
#define FRAME_DELAY
Definition: globals.h:135

Variable Documentation

entity_t* gEntities

The memory for entities that are currently running in the game

Definition at line 11 of file entity.c.

Referenced by DrawEntities(), FindEntity(), FindFreeEntity(), FreeEntity(), FreeNonPlayerEntities(), GetWorld(), InitEntitySystem(), InitNewEntity(), LookForEntityAtPos(), RunEntities(), RunPhysics(), and ShutdownEntitySystem().

entity_t* gEntityDictionary

Entities loaded from files AKA cached entities

Definition at line 41 of file game.c.

Referenced by FindCachedEntity(), FindNextFreeCachePos(), and InitEntitySystem().

void(*)(entity_t *) GetFunctionAI(ai_function_t *data)

Returns a function pointer to the think function, given ai_function data.

Parameters
[in,out]parameter1If non-null, the first parameter.
Returns
null if it fails, else a GetFunctionAI(ai_function_t *data.
Author
Anthony Rios
Date
3/29/2016

Definition at line 238 of file ai_interpret.c.

Referenced by ThinkEnemy().

239 {
240  if(!data)
241  {
242  return NULL;
243  }
244  switch(data->mAction)
245  {
246  case(AI_ACTION_NOTHING) :
247  return NothingAI;
248  case(AI_ACTION_MOVE):
249  return MoveAI;
250  case(AI_ACTION_WALK):
251  return WalkAI;
252  case(AI_ACTION_JUMP):
253  return JumpAI;
254  case(AI_ACTION_ATTACK):
255  return AttackAI;
256  default:
257  return NULL;
258  }
259 }
void NothingAI(entity_t *ent)
Definition: ai_interpret.c:25
void MoveAI(entity_t *ent)
Definition: ai_interpret.c:61
void WalkAI(entity_t *ent)
Definition: ai_interpret.c:106
void AttackAI(entity_t *ent)
Definition: ai_interpret.c:200
void JumpAI(entity_t *ent)
Definition: ai_interpret.c:147
int gLastEntity

The last entity that was free'd or created

Definition at line 12 of file entity.c.

Referenced by FindFreeEntity(), InitEntitySystem(), and InitNewEntity().