14 object_t *tempObj, *enemyObj, *posObj, *itemObj, *aiObj;
15 entity_t *tempEnt, *cachedEnt;
16 ai_function_t *enemyAI;
17 int tempInt, i, j, x, y, enemies, objects, positions, tileX, tileY;
18 char *temp_str = NULL, *aiStr, *enemyName, *objectName, *aiFile, *tileX_str, *tileY_str;
19 vec2_t *spawn, *temp_pos, obj_pos, tile_pos;
20 if(!level || !level->keys)
22 printf(
"Could not load NULL lvl");
37 printf(
"Level %s has no Name \n", level->name);
40 tempInt = tempTok - level->keys;
43 if( (tempTok =
FindKey(level->keys,
"Hint", g_str)) != NULL)
45 tempInt = tempTok - level->keys;
53 printf(
"Level %s has no Background \n",
gCurrentLevel->mName);
56 tempInt = tempTok - level->keys;
69 printf(
"Level %s spawn parse error \n",
gCurrentLevel->mName);
79 printf(
"Level failed to find enemies in level : %s \n", level->name);
82 if(enemyObj && enemyObj->children)
84 enemies =
CountMem(enemyObj->children,
sizeof(object_t));
85 for(i = 0; i < enemies; i++)
129 positions = posObj->children ?
CountMem(posObj->children,
sizeof(object_t)) : 1;
131 for(j = 0; j < positions; j++)
133 temp_pos =
ParseToVec2(posObj->children ? &posObj->children[j] : posObj, g_str);
136 obj_pos.
x = tileX ? (tileX - temp_pos->
x)/cachedEnt->mSprites[0]->mSize.x : 1;
137 obj_pos.
y = tileY ? (tileY - temp_pos->
y)/cachedEnt->mSprites[0]->mSize.y : 1;
138 for(x = 0; x < obj_pos.
x; x++)
140 for(y = 0; y < obj_pos.
y; y++)
145 printf(
"Max Entities reached for level %s", level->name);
149 memcpy(tempEnt, cachedEnt ,
sizeof(entity_t));
151 tile_pos.
x = tileX ? temp_pos->
x + x*cachedEnt->mSprites[0]->mSize.x: temp_pos->
x;
152 tile_pos.
y = tileY ? temp_pos->
y + y*cachedEnt->mSprites[0]->mSize.y: temp_pos->
y;
153 tempEnt->mPosition = tile_pos;
154 tempEnt->mData = enemyAI;
158 tempEnt->mWeight = 1;
159 tempEnt->mNextThink = SDL_GetTicks() + 10;
160 tile_pos.
x = 0; tile_pos.
y = 0;
165 if(temp_str) free(temp_str);
174 printf(
"Level failed to find objects in level : %s \n", level->name);
177 if(itemObj && itemObj->children)
179 objects =
CountMem(itemObj->children,
sizeof(object_t));
180 for(i = 0; i < objects; i++)
204 obj_pos.
x = tileX ? (tileX - 0)/cachedEnt->mSprites[0]->mSize.x : 1;
205 obj_pos.
y = tileY ? (tileY - 0)/cachedEnt->mSprites[0]->mSize.y : 1;
207 positions = posObj->children ?
CountMem(posObj->children,
sizeof(object_t)) : 1;
209 for(j = 0; j < positions; j++)
211 temp_pos =
ParseToVec2(posObj->children ? &posObj->children[j] : posObj, g_str);
214 obj_pos.
x = tileX ? (tileX - temp_pos->
x)/cachedEnt->mSprites[0]->mSize.x : 1;
215 obj_pos.
y = tileY ? (tileY - temp_pos->
y)/cachedEnt->mSprites[0]->mSize.y : 1;
216 for(x = 0; x < obj_pos.
x; x++)
218 for(y = 0; y < obj_pos.
y; y++)
223 printf(
"Max Entities reached in level : %s \n", level->name);
227 memcpy(tempEnt, cachedEnt,
sizeof(entity_t));
229 tempEnt->Think = NULL;
232 tile_pos.
x = tileX ? temp_pos->
x + x*cachedEnt->mSprites[0]->mSize.x: temp_pos->
x;
233 tile_pos.
y = tileY ? temp_pos->
y + y*cachedEnt->mSprites[0]->mSize.y: temp_pos->
y;
234 tempEnt->mPosition = tile_pos;
235 tile_pos.
x = 0; tile_pos.
y = 0;
252 printf(
"Level not loaded, unable to print");
int CountMem(void *src, int size_type)
#define LEVEL_ITEM_XTRA_STR
#define LEVEL_ENEMY_OBJ_STR
object_t * FindObject(object_t *obj, char *name)
char * JsmnToString(jsmntok_t *token, char *g_str)
vec2_t * ParseToVec2(struct object_s *object, char *str)
int ConvertFileToUseable(char *fileName, jsmn_parser *parser, char **stringStorage, jsmntok_t **jsmnStorage)
ai_function_t * ParsePresetAI(object_t *obj, char *g_str)
entity_t * InitNewEntity()
void TouchGoal(entity_t *self, entity_t *other, int type)
void DrawGeneric(entity_t *self)
void FreeNonPlayerEntities()
entity_t * FindCachedEntity(const char *name)
#define LEVEL_ITEM_NAME_STR
#define LEVEL_ITEM_OBJ_STR
jsmntok_t * FindKey(jsmntok_t *token, char *key, char *g_str)
int LoadLevel(object_t *level, char *g_str)
#define LEVEL_POSITION_STR
char ** ParseToStringArray(struct object_s *object, char *str)
sprite_t * LoadSprite(const char *name, int flags)
int DrawSprite(sprite_t *sprite, int *frame, vec2_t *position, SDL_Renderer *renderer)
#define LEVEL_VARIABLES_STR
char * FindValue(struct object_s *obj, char *key, char *g_str)
void FreeEntity(entity_t *ent)
void TouchGeneric(entity_t *self, entity_t *other, int type)
object_t * ParseToObject(jsmntok_t *token, char *g_str)
void ThinkEnemy(entity_t *self)
#define LEVEL_BACKGROUND_STR
#define LEVEL_ENEMY_NAME_STR
ai_function_t * ParseAI(object_t *obj, char *g_str, char **variables)