Dumb-ways-to-memorize
2D game
parsefunction.c
Go to the documentation of this file.
1 #include "globals.h"
2 #include "parsefunction.h"
3 #include "SDL.h"
4 #include <string.h>
5 #include <stdio.h>
6 
7 //Function Globals
8 char *FunctionNames[] = {"X mouse", "X", "mouse", "self", "at-point", "world" , 0};
10 
11 void (*ParseToFunction(const char *name))
12 {
13  int i;
14 
15  for(i = 0; FunctionNames[i]; i++)
16  {
17  if(!strcmp(FunctionNames[i], name))
18  {
19  return FunctionSymbols[i];
20  }
21  }
22  return NULL;
23 }
24 
25 void GetWorld(entity_t *self, entity_t **targ)
26 {
27  *targ = gEntities;
28  return;
29 }
30 
31 void GetAtPoint(entity_t *self, entity_t **targ)
32 {
33  vec2_t *temp = (vec2_t*) malloc(sizeof(vec2_t));
34  GetMousePos(self, temp);
35  *targ = LookForEntityAtPos(*temp);
36  free(temp);
37  return;
38 }
39 
40 void GetSelf(entity_t *self, entity_t **targ)
41 {
42  *targ = self;
43  return;
44 }
45 
46 
47 void GetX(entity_t *self, int *button)
48 {
49  *button = SDL_GetKeyFromName("X");
50  return;
51 }
52 
53 void GetMousePos(entity_t *self, vec2_t *pos)
54 {
55  SDL_GetRelativeMouseState( &pos->x, &pos->y);
56  return;
57 }
58 
59 void GetXMouse(entity_t *self, int * button, vec2_t *pos)
60 {
61  GetX(self, button);
62  GetMousePos(self, pos);
63 }
void GetAtPoint(entity_t *self, entity_t **targ)
Definition: parsefunction.c:31
int y
Definition: globals.h:22
void FunctionSymbols
Definition: parsefunction.c:9
void GetXMouse(entity_t *self, int *button, vec2_t *pos)
Definition: parsefunction.c:59
void GetMousePos(entity_t *self, vec2_t *pos)
Definition: parsefunction.c:53
void GetX(entity_t *self, int *button)
Definition: parsefunction.c:47
void GetSelf(entity_t *self, entity_t **targ)
Definition: parsefunction.c:40
entity_t * LookForEntityAtPos(vec2_t position)
Definition: entity.c:355
char * FunctionNames[]
Definition: parsefunction.c:8
entity_t * gEntities
Definition: entity.c:11
void * ParseToFunction(const char *name)
Definition: parsefunction.c:11
char * name
Definition: parseobject.h:24
int x
Definition: globals.h:21
void GetWorld(entity_t *self, entity_t **targ)
Definition: parsefunction.c:25
Definition: globals.h:19