Dumb-ways-to-memorize
2D game
globals.h
Go to the documentation of this file.
1 #ifndef __GLOBALS_H
2 #define __GLOBALS_H
3 
4 
5 #include <jsmn.h>
6 #define STRING_TYPE(X) (X == sizeof(char) ? "Char" \
7  : (X == sizeof(int) ? "Int" \
8  : (X == sizeof(jsmntok_t) ? "Jsmn" \
9  : "Unkown" ) ) )
10 /**< Returns string of the type of size X*/
11 
12 #define SIGN_BIT 0xF000
13 
14 /** Defines an alias representing the 2D vector */
15 typedef struct vec2_s
16 {
17  int x;
18  int y;
20 
22 
23 //Address of a value, basically generic typing int*
24 typedef unsigned int address_t;
25 //Key Value pair struct
26 typedef struct KV_Pair_s
27 {
28  char *key;
29  address_t value;
31 
32 //#define VEC2_ADD(A, B, C) (C[0] = A[0] + B[0], C[1] = A[1] + B[1])
33 //#define VEC2_SUBTRACT(A, B, C) (C[0] = A[0] - B[0], C[1] = A[1] - B[1])
34 void Vec2Add(vec2_t *A, vec2_t *B, vec2_t *C);
35 void Vec2Subtract(vec2_t *First, vec2_t *Second, vec2_t *C);
36 void Vec2MultiplyScalar(vec2_t *A, int B, vec2_t *C);
37 extern int LargestDivisor(int num);
38 
39 
40 /** Defines the enum relating to entity states */
41 typedef enum
42 {
43  ENTITY_STATE_DEAD, /**< An enum constant representing the entity state dead */
44  ENTITY_STATE_ALIVE, /**< An enum constant representing the entity state alive option */
45  ENTITY_STATE_OTHER /**< An enum constant representing the entity state other, which is used for non-health based entities */
47 
48 /** Defines the enum which are the collision types for the physics engine */
49 typedef enum
50 {
51  COLLISION_TYPE_STATIC, /**< An enum constant representing the collision type static - which means it collides, but doesn't move */
52  COLLISION_TYPE_RAGDOLL, /**< An enum constant representing the collision type ragdoll - which collides + moves */
53  COLLISION_TYPE_CLIP /**< An enum constant representing the collision type clip - which means it doesn't collide , but moves. Should be used for particle entities (maybe) */
55 
56 /** Defines the enum for menu item states */
57 typedef enum
58 {
60  MENU_ITEM_STATE_SELECTED = 0x1, /**< An enum constant representing the menu item state selected - which means the player is hovering over this now */
61  MENU_ITEM_STATE_NOT_SELECTED = 0x2, /**< An enum constant representing the menu item state not selected */
62  MENU_ITEM_STATE_PICKED = 0x4, /**< An enum constant representing the menu item state picked - which is a option that is checked */
65 
66 /** Defines an enum for animation states in mSprites array */
67 typedef enum
68 {
69  ANIMATION_IDLE, /**< An enum constant representing the idle animation */
70  ANIMATION_WALK, /**< An enum constant representing the walk animation*/
71  ANIMATION_JUMP, /**< An enum constant representing the jump animation */
72  ANIMATION_ATTACK, /**< An enum constant representing the attack animation */
73  ANIMATION_HIT, /**< An enum constant representing the hit animation */
74  ANIMATION_MAX = 20 /**< An enum constant representing the maximum animations */
75 
77 
78 /** Defines the enum for the game states */
79 typedef enum
80 {
81  SPLASH = 0x1, /**< An enum constant representing the splash screen game state */
82  START = 0x2, /**< An enum constant representing the start screen game state */
83  GUESS = 0x4, /**< An enum constant representing the first time the player chooses the power_ups */
84  CHOOSE = 0x8, /**< An enum constant representing the state in which the player selects a power_up from the chosen power ups in guess */
85  PLAYING = 0x10, /**< An enum constant representing the playing game state, which is consistent of the level, enemy entities, and the player */
86  END = 0x20, /**< An enum constant representing the player has chosen to quit the game */
88 
89 extern GameState gGameState; /**< State of the game */
90 extern GameState StrToGameState(char *str); /**< Converts a string into a game state*/
91 extern int StrToMenuType(char *str); /**< Converts a string into a menu type*/
92 
93 //For Hazards
94 #define HAZARD_NULL 0x0
95 #define HAZARD_MAX (0x1 >> 31)
96 #define HAZARD_DAMAGE 10
97 #define HAZARD_STUN_FRAMES 10
98 extern char **Hazards_str; /**< The hazards string array which is defined in the gamedata file */
99 extern int StrToHazard(char *str); /**< Converts a string into a hazard, using the parsed hazards_str for comparison */
101 //For EntParsing
102 #define ENTITIES_FILE_STR "Entities"
103 extern char *gEntitiesFile; /**< The name of the entities file */
104 extern char *Collisions_str[]; /**< The collisions type strings for parsing */
105 extern char *EntityStates_str[]; /**< The entity state strings for parsing */
106 collision_type_t StrToCollisionType(char *str); /**< Converts a string into a entity collision type */
107 entity_state_t StrToEntityState(char *str); /**< Converts a string into an entity state */
108 
109 //For PowerUps
110 #define POWER_UPS_STR "PowerUps"
111 extern char *gPowerUpsFile; /**< The name of the power ups file */
112 extern vec2_t *mousePos; /**< The mouse position */
113 extern int *keyPower; /**< The key press related to using the power */
114 extern char **gSelectedPowerUps; /**< The power ups the player selects */
115 extern char **gUsedPowerUps; /**< The used power ups for this game run */
116 extern char *gCurrentPowerUpName; /**< The current power up name */
117 
118 //For Levels
119 extern char **gLevels; /**< The level names */
120 extern char **gSelectedLevels; /**< The selected levels to load */
121 int SelectLevels();
122 int LoadSelectedLevel(int level);
124 
125 extern void *gWorld;
126 extern void *gMouse;
127 
128 //Game Globals
129 #define G_NAME_STR "Name"
130 #define LOC_NAME_STR "name"
131 #define FRAME_DELAY 13
132 #define PHYSICS_LIMITER 2
133 extern int gPlayerLives; /**< The lives of the player */
134 extern int gLevelsPerGame; /**< The levels per game */
135 extern int gScreenWidth; /**< The set Width of the screen */
136 extern int gScreenHeight; /**< Te set Height of the screen */
137 extern unsigned int gCurrentTime; /**< The current time , updated from last update call*/
138 extern vec2_t gGravity; /**< The gravity which affects all the assets */
139 
140 extern int exitRequest; /**< The integer to be changed to exit */
141 
142 //Memory Functions
143 /**
144  * Counts the memory of type size_type, given that the final address is null.
145  *
146  * @param [in,out] src If non-null, source of memory.
147  * @param size_type Size of the type.
148  *
149  * @return The total number of memory, if src is null 0 is returned.
150  *
151  * @author Anthony Rios
152  * @date 2/1/2016
153  */
154 extern int CountMem(void *src, int size_type);
155 
156 /**
157  * Allocate memory and copy over src into it. Adds Null to end.
158  * Returns NULL on size 0
159  *
160  * @param [in,out] dst If non-null, destination for the allocation.
161  * @param [in,out] src If non-null, source for the adding.
162  * @param size_type Size of the type.
163  * @param size The size.
164  *
165  * @return 0 on success, -1 on error.
166  *
167  * @author Anthony Rios
168  * @date 2/1/2016
169  */
170 extern int AllocateDynamic(void **dst, void *src, int size_type, int size);
171 
172 /**
173  * Compare memory to memory array.
174  *
175  * @param [in,out] mem If non-null, the memory.
176  * @param [in,out] mem_array If non-null, array of memories.
177  * @param size_type Size of type, via sizeof() function.
178  * @param size_array Size of Array.
179  *
180  * @return 0 if equal, -1 if not.
181  *
182  * @author Anthony Rios
183  * @date 1/31/2016
184  */
185 extern int CompareMemToMemArray(void *mem, void *mem_array, int size_type, int size_array);
186 
187 //Foward dec of object_s for global objects & functions
188 struct object_s;
189 /**
190  * Parse given obj/str to vector 2.
191  *
192  * @param [in,out] object If non-null, the object.
193  * @param [in,out] str If non-null, the string.
194  *
195  * @return null if it fails, else a pointer to a vec2_t.
196  *
197  * @author Anthony Rios
198  * @date 3/29/2016
199  */
200 extern vec2_t *ParseToVec2(struct object_s *object, char* str);
201 
202 /**
203  * Parse obj/data to string array.
204  *
205  * @param [in,out] object If non-null, the object.
206  * @param [in,out] str If non-null, the string.
207  *
208  * @return null if it fails, else a handle to a char.
209  *
210  * @author Anthony Rios
211  * @date 3/29/2016
212  */
213 extern char **ParseToStringArray(struct object_s *object, char* str);
214 
215 //Prepoccessor defed LINKS and STRICT_MODE
216 //JSON Parser
217 extern jsmn_parser gParser; /**< The global jsmn parser */
218 extern jsmntok_t *gGameTokens; /**< Tokens for GameData */
219 extern struct object_s *gGameObject; /**< The game object */
220 extern jsmntok_t *gEntityTokens; /**< The entity jsmn tokens */
221 extern struct object_s *gEntityObject; /**< The entity object */
222 extern jsmntok_t *gLevelTokens; /**< The level jsmn tokens */
223 extern struct object_s *gLevelObject; /**< The current level object */
224 extern char *gGameData; /**< Game Data File - holding the contents of file via string*/
225 extern char *gEntityData; /**< The current parsed string of the entity file */
226 extern char *gLevelData; /**< Information describing the current level */
227 
228 #endif
Definition: jsmn.h:40
void * gMouse
int CountMem(void *src, int size_type)
Definition: mymath.c:51
int SelectLevels()
Definition: game.c:297
Definition: globals.h:87
GameState StrToGameState(char *str)
Definition: mystrings.c:274
void Vec2MultiplyScalar(vec2_t *A, int B, vec2_t *C)
Definition: mymath.c:41
unsigned int gCurrentTime
Definition: game.c:50
char ** gSelectedPowerUps
Definition: game.c:28
char * Collisions_str[]
Definition: entity.c:14
char * gCurrentPowerUpName
Definition: game.c:43
vec2_t * mousePos
Definition: parsepowerup.c:17
char * gLevelData
Definition: game.c:38
struct object_s * gEntityObject
Definition: game.c:34
vec2_t * ParseToVec2(struct object_s *object, char *str)
char ** gUsedPowerUps
Definition: game.c:29
char * gEntityData
Definition: game.c:37
entity_state_t StrToEntityState(char *str)
Definition: mystrings.c:370
jsmntok_t * gLevelTokens
Definition: game.c:32
int StrToHazard(char *str)
Definition: mystrings.c:317
struct object_s * gLevelObject
Definition: game.c:35
vec2_t gGravity
Definition: dumb_physics.c:7
int gScreenWidth
Definition: graphics.c:16
int LargestDivisor(int num)
Definition: mymath.c:5
int gLevelsPerGame
Definition: game.c:24
int gScreenHeight
Definition: graphics.c:17
char * gGameData
Definition: game.c:36
void * gWorld
void Vec2Subtract(vec2_t *First, vec2_t *Second, vec2_t *C)
Definition: mymath.c:31
int AllocateDynamic(void **dst, void *src, int size_type, int size)
Definition: mymath.c:66
char ** Hazards_str
Definition: entity.c:13
collision_type_t StrToCollisionType(char *str)
Definition: mystrings.c:344
char * gEntitiesFile
Definition: game.c:39
entity_state_t
Definition: globals.h:45
Definition: globals.h:88
char ** gLevels
Definition: game.c:26
menu_item_state_t
Definition: globals.h:61
int * keyPower
Definition: parsepowerup.c:18
int LoadSelectedLevel(int level)
Definition: game.c:390
vec2_t gZeroPos
Definition: game.c:46
int CompareMemToMemArray(void *mem, void *mem_array, int size_type, int size_array)
Definition: mymath.c:77
int exitRequest
Definition: game.c:22
jsmntok_t * gGameTokens
Definition: game.c:30
struct object_s * gGameObject
Definition: game.c:33
int gPlayerLives
Definition: player.c:10
animation_state_t
Definition: globals.h:71
char * gPowerUpsFile
Definition: game.c:40
char * EntityStates_str[]
Definition: entity.c:15
jsmn_parser gParser
Definition: game.c:25
collision_type_t
Definition: globals.h:53
char ** ParseToStringArray(struct object_s *object, char *str)
GameState gGameState
Definition: game.c:44
jsmntok_t * gEntityTokens
Definition: game.c:31
char ** gSelectedLevels
Definition: game.c:27
void Vec2Add(vec2_t *A, vec2_t *B, vec2_t *C)
Definition: mymath.c:20
int StrToMenuType(char *str)
Definition: menu.c:697
GameState
Definition: globals.h:83
unsigned int address_t
Definition: globals.h:28
Definition: globals.h:86
void RandomizeSelectedLevels()
Definition: game.c:343
Definition: globals.h:85
Definition: globals.h:19
Definition: globals.h:90