TapestryEngine

A 2D Platformer Game Engine
Log | Files | Refs

24dd2faf3a26428e59a0eb86a64b4917540828f3.svn-base (17886B)


      1 #include "Level.h"
      2 
      3 Actor* FindRef(std::vector<ActorName*> refs, char* name)
      4 {
      5 	for (int i = 0; i < (int)refs.size(); i++)
      6 	{
      7 		if (strcmp(refs.at(i)->name, name) == false)
      8 		{
      9 			return refs.at(i)->act;
     10 		}
     11 	}
     12 
     13 	return NULL;
     14 }
     15 
     16 bool Level::LoadWorld(cJSON* level)
     17 {
     18 	cJSON* world = cJSON_GetObjectItem(level, "world");
     19 	mHeight = cJSON_GetObjectItem(world, "world_h")->valueint;
     20 	mWidth = cJSON_GetObjectItem(world, "world_w")->valueint;
     21 	
     22 	
     23 	
     24 	char * ter = cJSON_GetObjectItem(world, "terrain")->valuestring;
     25 	mColMap = LoadSurfaceBMP(ter);
     26 
     27 	cJSON* backs = cJSON_GetObjectItem(world, "backgrounds");
     28 	for (int i = 0; i < cJSON_GetArraySize(backs); i++)
     29 	{
     30 		cJSON* layer = cJSON_GetArrayItem(backs, i);
     31 		char* back = cJSON_GetObjectItem(layer, "back")->valuestring;
     32 
     33 		SDL_Texture* back_tex = SDL_CreateTextureFromSurface(mRen, LoadSurfaceBMP(back));
     34 		int alpha = cJSON_GetObjectItem(layer, "alpha")->valueint;
     35 
     36 		if (alpha != 0)
     37 		{
     38 			SDL_SetTextureAlphaMod(back_tex, alpha);
     39 		}
     40 
     41 		mBack.push_back(back_tex);
     42 
     43 		float p_factor = (float)cJSON_GetObjectItem(layer, "parallax_factor")->valueint;
     44 		mParallax_back.push_back(p_factor);
     45 	}
     46 
     47 	cJSON* fores = cJSON_GetObjectItem(world, "foregrounds");
     48 	for (int i = 0; i < cJSON_GetArraySize(fores); i++)
     49 	{
     50 		cJSON* layer = cJSON_GetArrayItem(fores, i);
     51 		char* fore = cJSON_GetObjectItem(layer, "fore")->valuestring;
     52 
     53 		SDL_Texture* fore_tex = SDL_CreateTextureFromSurface(mRen, LoadSurfaceBMP(fore));
     54 		int alpha = cJSON_GetObjectItem(layer, "alpha")->valueint;
     55 
     56 		if (alpha != 0)
     57 		{
     58 			SDL_SetTextureAlphaMod(fore_tex, alpha);
     59 		}
     60 
     61 		mFore.push_back(fore_tex);
     62 	}
     63 
     64 	cJSON* overs = cJSON_GetObjectItem(world, "overlays");
     65 	for (int i = 0; i < cJSON_GetArraySize(overs); i++)
     66 	{
     67 		cJSON* layer = cJSON_GetArrayItem(overs, i);
     68 		char* overs = cJSON_GetObjectItem(layer, "over")->valuestring;
     69 
     70 		SDL_Texture* over_tex = SDL_CreateTextureFromSurface(mRen, LoadSurfaceBMP(overs));
     71 		int alpha = cJSON_GetObjectItem(layer, "alpha")->valueint;
     72 
     73 		if (alpha != 0)
     74 		{
     75 			SDL_SetTextureAlphaMod(over_tex, alpha);
     76 		}
     77 
     78 		mOver.push_back(over_tex);
     79 
     80 		float p_factor = (float)cJSON_GetObjectItem(layer, "parallax_factor")->valueint;
     81 		mParallax_over.push_back(p_factor);
     82 	}
     83 	return true;
     84 }
     85 
     86 bool Level::LoadCamera(cJSON* level)
     87 {
     88 	cJSON* camera = cJSON_GetObjectItem(level, "camera");
     89 	int camx = cJSON_GetObjectItem(camera, "x")->valueint;
     90 	int camy = cJSON_GetObjectItem(camera, "y")->valueint;
     91 	int camh = cJSON_GetObjectItem(camera, "h")->valueint;
     92 	int camw = cJSON_GetObjectItem(camera, "w")->valueint;
     93 
     94 	mCam = Camera(camh, camw, camx, camy, mHeight, mWidth);
     95 	
     96 	cJSON* blockers = cJSON_GetObjectItem(camera, "blockers");
     97 	
     98 	for (int i = 0; i < cJSON_GetArraySize(blockers); i++)
     99 	{
    100 		cJSON* blocker = cJSON_GetArrayItem(blockers, i);
    101 		SDL_Rect* r = new SDL_Rect;
    102 		r->h = cJSON_GetObjectItem(blocker, "h")->valueint;
    103 		r->w = cJSON_GetObjectItem(blocker, "w")->valueint;
    104 		r->x = cJSON_GetObjectItem(blocker, "x")->valueint;
    105 		r->y = cJSON_GetObjectItem(blocker, "y")->valueint;
    106 
    107 		mCam.LogBlocker(r);
    108 	}
    109 
    110 	return true;
    111 }
    112 
    113 bool Level::LoadAnimations(cJSON* level)
    114 {
    115 	cJSON* animations = cJSON_GetObjectItem(level, "animations");
    116 	mAnim_names = (char**)malloc(cJSON_GetArraySize(animations) * sizeof(char*));
    117 	for (int i = 0; i < cJSON_GetArraySize(animations); i++)
    118 	{
    119 		cJSON* anim_pack = cJSON_GetArrayItem(animations, i);
    120 		mAnim_names[i] = cJSON_GetObjectItem(anim_pack, "pack_name")->valuestring;
    121 		//gCons->ConsPrintf("Animation Pack Name: %s\n", anim_names[i]);
    122 
    123 		cJSON* frame_size = cJSON_GetObjectItem(anim_pack, "frame_size");
    124 		int h = cJSON_GetObjectItem(frame_size, "h")->valueint;
    125 		int w = cJSON_GetObjectItem(frame_size, "w")->valueint;
    126 
    127 		cJSON* col_data = cJSON_GetObjectItem(anim_pack, "col_data");
    128 		int off_x = cJSON_GetObjectItem(col_data, "off_x")->valueint;
    129 		int off_y = cJSON_GetObjectItem(col_data, "off_y")->valueint;
    130 		int col_h = cJSON_GetObjectItem(col_data, "col_h")->valueint;
    131 		int col_w = cJSON_GetObjectItem(col_data, "col_w")->valueint;
    132 
    133 		cJSON* anim_set = cJSON_GetObjectItem(anim_pack, "anim_set");
    134 
    135 		FrameSet* frame_data = (FrameSet*)malloc(cJSON_GetArraySize(anim_set) * sizeof(FrameSet));
    136 		int* Index = (int*)malloc(cJSON_GetArraySize(anim_set) * sizeof(int));
    137 
    138 		for (int j = 0; j < cJSON_GetArraySize(anim_set); j++)
    139 		{
    140 			cJSON* anim = cJSON_GetArrayItem(anim_set, j);
    141 			char* filename = cJSON_GetObjectItem(anim, "filename")->valuestring;
    142 			int frame_count = cJSON_GetObjectItem(anim, "frame_count")->valueint;
    143 			int frame_rate = cJSON_GetObjectItem(anim, "frame_rate")->valueint;
    144 			//int h = cJSON_GetObjectItem(anim, "h")->valueint;
    145 			//int w = cJSON_GetObjectItem(anim, "w")->valueint;
    146 			char* id_str = cJSON_GetObjectItem(anim, "id")->valuestring;
    147 
    148 			int id = ConvertStringToSymbol(id_str);
    149 			//gCons->ConsPrintf("image source path: %s\n", filename);
    150 			frame_data[j] = FrameSet(mRen, filename, frame_count, frame_rate, h, w);
    151 			Index[j] = id;
    152 		}
    153 		AnimDataPack* pack = new AnimDataPack(cJSON_GetArraySize(anim_set), frame_data, Index);
    154 		pack->SetColData(off_x, off_y, col_h, col_w);
    155 		mAnimData.push_back(pack);
    156 
    157 
    158 		LoadAnimGraph(anim_pack);
    159 	}
    160 
    161 	return true;
    162 }
    163 
    164 bool Level::LoadAnimGraph(cJSON* anim_pack)
    165 {
    166 	AnimGraphData* anim_g = new AnimGraphData( *mAnimData.back() );
    167 
    168 	cJSON* loop_ids = cJSON_GetObjectItem(anim_pack, "loop_ids");
    169 	for (int i = 0; i < (int)cJSON_GetArraySize(loop_ids); i++)
    170 	{
    171 		int id = ConvertStringToSymbol(cJSON_GetArrayItem(loop_ids, i)->valuestring);
    172 		anim_g->DefineLoop(id);
    173 	}
    174 	anim_g->CreateTranisitionMatrix();
    175 
    176 	cJSON* transition_ids = cJSON_GetObjectItem(anim_pack, "transition_ids");
    177 	for (int i = 0; i < (int)cJSON_GetArraySize(transition_ids); i++)
    178 	{
    179 		int id = ConvertStringToSymbol(cJSON_GetArrayItem(transition_ids, i)->valuestring);
    180 		anim_g->DefineTransitions(id);
    181 	}
    182 
    183 	cJSON* anim_graph = cJSON_GetObjectItem(anim_pack, "anim_graph");
    184 	for (int i = 0; i < (int)cJSON_GetArraySize(anim_graph); i++)
    185 	{
    186 		cJSON* loop = cJSON_GetArrayItem(anim_graph, i);
    187 		char* loop_name = cJSON_GetObjectItem(loop, "loop_name")->valuestring;
    188 		int init_id = ConvertStringToSymbol(loop_name);
    189 
    190 		cJSON* transitions = cJSON_GetObjectItem(loop, "transitions");
    191 		for(int j = 0; j < (int)cJSON_GetArraySize(transitions); j++)
    192 		{
    193 			char* transition = cJSON_GetArrayItem(transitions, j)->valuestring;
    194 			int trans_id = ConvertStringToSymbol(transition);
    195 			
    196 			int target_id = anim_g->GetLoopIDIndex(j);
    197 
    198 			anim_g->PopulateTransitionMatrix(init_id, target_id, trans_id);
    199 		}
    200 	}
    201 	mAnimGraphs.push_back(anim_g);
    202 	
    203 	return false;
    204 }
    205 
    206 bool Level::LoadActors(cJSON* level)
    207 {
    208 	cJSON* actors = cJSON_GetObjectItem(level, "actors");
    209 	std::vector<ActorName*> ActorRefs;
    210 
    211 	mAHM = ActorHandleManager();
    212 	mSpatMon = SpatialMonitor(mHeight, mWidth, &mAHM);
    213 
    214 	for (int i = 0; i < cJSON_GetArraySize(actors); i++)
    215 	{
    216 		cJSON* act = cJSON_GetArrayItem(actors, i);
    217 		
    218 		char* anim_pack = cJSON_GetObjectItem(act, "anim_pack")->valuestring;
    219 		//gCons->ConsPrintf("sought set name: %s\n", anim_pack);
    220 
    221 		AnimGraph* actor_pack = NULL;
    222 		for (int j = 0; j <  (int)mAnimData.size(); j++)
    223 		{
    224 			if (!strcmp(anim_pack, mAnim_names[j]))
    225 			{
    226 				actor_pack = new AnimGraph(mAnimGraphs.at(j));
    227 			}
    228 		}
    229 #ifdef DEBUG
    230 		assert(actor_pack != NULL);
    231 #endif
    232 
    233 	
    234 		SDL_Rect PosRect;
    235 		PosRect.x = cJSON_GetObjectItem(act, "x")->valueint;
    236 		PosRect.y = cJSON_GetObjectItem(act, "y")->valueint;
    237 		PosRect.h = actor_pack->GetAnimPack()->GetAnimData()->GetCol_h();
    238 		PosRect.w = actor_pack->GetAnimPack()->GetAnimData()->GetCol_w();
    239 		SDL_Rect DrawRect;
    240 		DrawRect.x = actor_pack->GetAnimPack()->GetAnimData()->GetOff_x();
    241 		DrawRect.y = actor_pack->GetAnimPack()->GetAnimData()->GetOff_y();
    242 		DrawRect.h = actor_pack->GetH();
    243 		DrawRect.w = actor_pack->GetW();
    244 
    245 		ActorName* ref = new ActorName;
    246 		ref->name = cJSON_GetObjectItem(act, "name")->valuestring;
    247 
    248 		char* type = cJSON_GetObjectItem(act, "type")->valuestring;
    249 		if (!strcmp(type, "player"))
    250 		{
    251 			Player* actor = new Player(mColMap, actor_pack, PosRect, DrawRect, &mAHM, &mSpatMon, &mPrtLib, &mSoundLib); //needs a delete
    252 			ref->act = actor;
    253 			//mSpatMon.LogActor(*actor);
    254 			mInput->mFeed.Subscribe(actor);
    255 			
    256 
    257 			mCam.SetFollowTarget(actor);
    258 			mCast.push_back(actor);
    259 			mPlayer = actor;
    260 
    261 			AnimGraph* hat_pack = NULL;
    262 			for (int j = 0; j < (int)mAnimData.size(); j++)
    263 			{
    264 				if (!strcmp("sword", mAnim_names[j]))
    265 				{
    266 					hat_pack = new AnimGraph(mAnimGraphs.at(j));
    267 				}
    268 			}
    269 			actor->SetSword(actor->AttachHat(new sword(hat_pack, actor, &mAHM, NULL, &mPrtLib, &mSoundLib)));
    270 		}
    271 		else if (!strcmp(type, "test_blocker"))
    272 		{
    273 			Test_Blocker* actor = new Test_Blocker(actor_pack, PosRect, DrawRect, &mAHM, &mSpatMon, &mPrtLib, &mSoundLib);
    274 			ref->act = actor;
    275 			//mSpatMon.LogActor(*actor);
    276 			mCast.push_back(actor);
    277 		}
    278 		else if (!strcmp(type, "gate")) //Gate is a multiactor entity.
    279 		{
    280 			int dir = ConvertStringToSymbol(cJSON_GetObjectItem(act, "dir")->valuestring);
    281 			Gate* actor = new Gate(actor_pack, PosRect, DrawRect, &mAHM, &mSpatMon, &mPrtLib, &mSoundLib, dir);
    282 			//mSpatMon.LogActor(*actor);
    283 			mCast.push_back(actor);
    284 			actor_pack->mFeed.Subscribe(actor);
    285 
    286 			AnimGraph* winch_pack = NULL;
    287 			for (int j = 0; j < (int)mAnimData.size(); j++)
    288 			{
    289 				if (!strcmp("winch", mAnim_names[j]))
    290 				{
    291 					winch_pack = new AnimGraph(mAnimGraphs.at(j));
    292 				}
    293 			}
    294 			PosRect.h = winch_pack->GetAnimPack()->GetAnimData()->GetCol_h();
    295 			PosRect.w = winch_pack->GetAnimPack()->GetAnimData()->GetCol_w();
    296 			PosRect.y -= 29;
    297 			if (dir == LEFT)
    298 			{
    299 				PosRect.x += 7;
    300 			}
    301 			else //dir == right
    302 			{
    303 				PosRect.x -= (21);
    304 			}
    305 
    306 			DrawRect.x = winch_pack->GetAnimPack()->GetAnimData()->GetOff_x();
    307 			DrawRect.y = winch_pack->GetAnimPack()->GetAnimData()->GetOff_y();
    308 			DrawRect.h = winch_pack->GetH();
    309 			DrawRect.w = winch_pack->GetW();
    310 			Winch* actor2 = new Winch(winch_pack, PosRect, DrawRect, &mAHM, &mSpatMon, &mPrtLib, &mSoundLib, actor, dir);
    311 			ref->act = actor2;  //Gate ref refers to the paired winch because its more useful
    312 			actor2->mFeed.Subscribe(actor);
    313 			//mSpatMon.LogActor(*actor2);
    314 			mCast.push_back(actor2);
    315 		}
    316 		else if (!strcmp(type, "gateman")) //Gateman must be attached to a gate. currently hardcoded to actor name "gate0"
    317 		{
    318 			Gateman* actor = new Gateman(actor_pack, PosRect, DrawRect, &mAHM, &mSpatMon, &mPrtLib, &mSoundLib, cJSON_GetObjectItem(act, "lines")->valuestring, FindRef(ActorRefs, "gate0")->GetHandle());
    319 			ref->act = actor;
    320 			//mSpatMon.LogActor(*actor);
    321 			mCast.push_back(actor);
    322 		}
    323 		else if (!strcmp(type, "talker"))
    324 		{
    325 			Talker* actor = new Talker(actor_pack, PosRect, DrawRect, &mAHM, &mSpatMon, &mPrtLib, &mSoundLib, cJSON_GetObjectItem(act, "lines")->valuestring);
    326 			ref->act = actor;
    327 			//mSpatMon.LogActor(*actor);
    328 			mCast.push_back(actor);
    329 		}
    330 		else if (!strcmp(type, "door"))
    331 		{
    332 			int x_off = cJSON_GetObjectItem(act, "x_off")->valueint;
    333 			int y_off = cJSON_GetObjectItem(act, "y_off")->valueint;
    334 			Door* actor = new Door(actor_pack, PosRect, DrawRect, &mAHM, &mSpatMon, &mPrtLib, &mSoundLib, x_off, y_off);
    335 			ref->act = actor;
    336 			PosRect.x = cJSON_GetObjectItem(act, "x2")->valueint;
    337 			PosRect.y = cJSON_GetObjectItem(act, "y2")->valueint;
    338 			Door* actor2 = new Door(actor_pack, PosRect, DrawRect, &mAHM, &mSpatMon, &mPrtLib, &mSoundLib, x_off, y_off);
    339 			actor->SetTeleDest(actor2->GetTelePos());
    340 			actor2->SetTeleDest(actor->GetTelePos());
    341 			SDL_Rect* r = new SDL_Rect;
    342 			r->h = 0;
    343 			r->w = 0;
    344 			r->x = 100;
    345 			r->y = 100;
    346 			//actor->SetTeleDest(r);
    347 			//mSpatMon.LogActor(*actor);
    348 			//mSpatMon.LogActor(*actor2);
    349 			mCast.push_back(actor);
    350 			mCast.push_back(actor2);
    351 		}
    352 		else if (!strcmp(type, "sludge_seal"))
    353 		{
    354 			Pursuer* actor = new Pursuer(mColMap, actor_pack, PosRect, DrawRect, &mAHM, &mSpatMon, &mPrtLib, &mSoundLib);
    355 			ref->act = actor;
    356 			//mSpatMon.LogActor(*actor);
    357 			mCast.push_back(actor);
    358 		}
    359 		else if (!strcmp(type, "pursuer"))
    360 		{
    361 			Sludge_Seal* actor = new Sludge_Seal(mColMap, actor_pack, PosRect, DrawRect, &mAHM, &mSpatMon, &mPrtLib, &mSoundLib);
    362 			ref->act = actor;
    363 			//mSpatMon.LogActor(*actor);
    364 			mCast.push_back(actor);
    365 		}
    366 		else if (!strcmp(type, "wanderer"))
    367 		{
    368 			Wanderer* actor = new Wanderer(mColMap, actor_pack, PosRect, DrawRect, &mAHM, &mSpatMon, &mPrtLib, &mSoundLib);
    369 			ref->act = actor;
    370 			//mSpatMon.LogActor(*actor);
    371 			mCast.push_back(actor);
    372 		}
    373 		else if (!strcmp(type, "rabbit"))
    374 		{
    375 			Rabbit* actor = new Rabbit(mColMap, actor_pack, PosRect, DrawRect, &mAHM, &mSpatMon, &mPrtLib, &mSoundLib);
    376 			ref->act = actor;
    377 			//mSpatMon.LogActor(*actor);
    378 			mCast.push_back(actor);
    379 		}
    380 		else
    381 		{
    382 			gCons->ConsPrintf("Failed to load actor: %s is an unrecognized actor type\n", type);
    383 		}
    384 		ActorRefs.push_back(ref);
    385 	}
    386 	
    387 	return true;
    388 }
    389 
    390 bool Level::LoadParticles(cJSON* level)
    391 {
    392 	cJSON* particles = cJSON_GetObjectItem(level, "particles");
    393 	for (int i = 0; i < cJSON_GetArraySize(particles); i++)
    394 	{
    395 		cJSON* prt = cJSON_GetArrayItem(particles, i);
    396 		
    397 		char* anim_pack = cJSON_GetObjectItem(prt, "anim_pack")->valuestring;
    398 		//gCons->ConsPrintf("sought set name: %s\n", anim_pack);
    399 
    400 		//AnimDataPack* particle_anims = NULL;
    401 		AnimGraph* particle_anims = NULL;
    402 		for (int j = 0; j < (int)mAnimData.size(); j++)
    403 		{
    404 			//gCons->ConsPrintf("stored set name: %s\n", anim_names[j]);
    405 			if (!strcmp(anim_pack, mAnim_names[j]))
    406 			{
    407 				particle_anims = new AnimGraph(mAnimGraphs.at(j));
    408 			}
    409 		}
    410 #ifdef DEBUG
    411 		assert(particle_anims != NULL);
    412 #endif
    413 		int prth = particle_anims->GetH();
    414 		int prtw = particle_anims->GetW();
    415 		
    416 		ParticleData* pd = new ParticleData;
    417 		pd->AnimData = particle_anims;
    418 		pd->Height = prth;
    419 		pd->Width = prtw;
    420 		pd->spat = &mSpatMon;
    421 		
    422 		mPrtLib.LogParticleData(pd, anim_pack);
    423 		return true;
    424 	}
    425 	return false;
    426 }
    427 
    428 bool Level::LoadSounds(cJSON* level)
    429 {
    430 	cJSON* sounds = cJSON_GetObjectItem(level, "sounds");
    431 
    432 	for (int i = 0; i < cJSON_GetArraySize(sounds); i++)
    433 	{
    434 		cJSON* sound = cJSON_GetArrayItem(sounds, i);
    435 		char* fname = cJSON_GetObjectItem(sound, "filename")->valuestring;
    436 		char* name  = cJSON_GetObjectItem(sound, "name"    )->valuestring;
    437 		int vol     = cJSON_GetObjectItem(sound, "vol"     )->valueint;
    438 
    439 		Mix_Chunk* snd = new Mix_Chunk;
    440 		snd = LoadSound(fname);
    441 		Mix_VolumeChunk(snd, vol);
    442 
    443 		mSoundLib.LogSoundData(snd, name);
    444 	}
    445 
    446 	cJSON* sound_regions = cJSON_GetObjectItem(level, "sound_regions");
    447 
    448 	for (int i = 0; i < cJSON_GetArraySize(sound_regions); i++)
    449 	{
    450 		cJSON* region = cJSON_GetArrayItem(sound_regions, i);
    451 		SDL_Rect reg_rect;
    452 		reg_rect.x = cJSON_GetObjectItem(region, "x")->valueint;
    453 		reg_rect.y = cJSON_GetObjectItem(region, "y")->valueint;
    454 		reg_rect.h = cJSON_GetObjectItem(region, "h")->valueint;
    455 		reg_rect.w = cJSON_GetObjectItem(region, "w")->valueint;
    456 
    457 		RegionSound* rs = mSoundLib.SpawnRegionSound(reg_rect);
    458 
    459 		cJSON* tracks = cJSON_GetObjectItem(region, "tracks");
    460 		for (int j = 0; j < cJSON_GetArraySize(tracks); j++)
    461 		{
    462 			char* track = cJSON_GetArrayItem(tracks, j)->valuestring;
    463 			rs->LogTrack(mSoundLib.GetSoundData(track));
    464 		}
    465 	}
    466 
    467 	return false;
    468 }
    469 
    470 bool Level::LoadHud(cJSON* level)
    471 {
    472 	cJSON* texs = cJSON_GetObjectItem(level, "hud_textures");
    473 
    474 	//Load LifeMeter Widget
    475 	char* life_base = cJSON_GetObjectItem(texs, "life_base")->valuestring;
    476 	char* life_bar = cJSON_GetObjectItem(texs, "life_bar" )->valuestring;
    477 
    478 	SDL_Rect LifePos;
    479 	LifePos.h = 15;
    480 	LifePos.w = 250;
    481 	LifePos.x = 25;
    482 	LifePos.y = 25;
    483 	mHUD.LogWidget( new LifeMeter(mPlayer, LifePos, mRen, life_base, life_bar) );
    484 	//
    485 
    486 	//Load Fader widget
    487 	char* black = cJSON_GetObjectItem(texs, "fader")->valuestring;
    488 
    489 	Fader* f = new Fader(mRen, black);
    490 	mPlayer->mFeed.Subscribe(f);
    491 	mHUD.LogWidget(f);
    492 	//
    493 
    494 	//Load Dialogue Widget
    495 	char* text_box = cJSON_GetObjectItem(texs, "text_box")->valuestring;
    496 
    497 	SDL_Rect DialoguePos;
    498 	DialoguePos.h = 0;
    499 	DialoguePos.w = 0;
    500 	DialoguePos.x = 300;
    501 	DialoguePos.y = 200;
    502 
    503 	SDL_Color fg = {0,0,0};
    504 
    505 	Dialogue* d = new Dialogue(DialoguePos, mRen, "Tapestry.ttf", text_box, fg, mPlayer);
    506 	mPlayer->mFeed.Subscribe(d);
    507 
    508 	mHUD.LogWidget(d);
    509 	//
    510 
    511 	return true;
    512 }
    513 
    514 bool Level::Load(const char* filename)
    515 {
    516 	cJSON* root = LoadJSON(filename);
    517 	//PrintJSON(root);
    518 	cJSON* level = cJSON_GetObjectItem(root, "level");
    519 
    520 	LoadWorld(level);
    521 
    522 	LoadCamera(level);
    523 
    524 	gDiagDraw = new DiagnosticDraw(mRen, mCam);
    525 
    526 	LoadAnimations(level);
    527 
    528 	LoadActors(level);
    529 
    530 	LoadParticles(level);
    531 
    532 	LoadSounds(level);
    533 
    534 	LoadHud(level);
    535 
    536 //	int cells[9];
    537 
    538 //	mSpatMon.GetAdjacentCells(36, cells);
    539 
    540 	return true;
    541 }
    542 
    543 bool Level::Update()
    544 {
    545 	///Update Actors
    546 	for (int i = 0; i < (int)(mCast.size()); i++)
    547 	{
    548 		mCast.at(i)->ActorUpdate();
    549 	}
    550 	///Update Particles
    551 	for (int i = 0; i < (int)(mPrtLib.GetParticles()->size()); i++)
    552 	{
    553 		mPrtLib.GetParticles()->at(i)->ActorUpdate();
    554 	}
    555 
    556 	///Draw HUD
    557 	mHUD.UpdateWidgets();
    558 
    559 	mCam.ActorFollow(mRen, 150, 75);
    560 
    561 	///Draw Backgrounds
    562 	for (int i = 0; i < (int)mBack.size(); i++)
    563 	{
    564 		DrawParallax(mRen, mBack.at(i), mCam, mParallax_back.at(i), mHeight, mWidth);
    565 	}
    566 	///Draw Foregrounds
    567 	for (int i = 0; i < (int)mFore.size(); i++)
    568 	{
    569 		SDL_RenderCopy(mRen, mFore.at(i), mCam.GetCamView(), NULL);
    570 	}
    571 
    572 	///Draw Actors
    573 	for (int i = 0; i < (int)mCast.size(); i++)
    574 	{
    575 		DrawActor(mRen, *mCast.at(i), mCam);
    576 	}
    577 
    578 	///Draw Particles
    579 	for (int i = 0; i < (int)(mPrtLib.GetParticles()->size()); i++)
    580 	{
    581 		DrawActor(mRen, *mPrtLib.GetParticles()->at(i), mCam);
    582 	}
    583 
    584 	///Draw overlays
    585 	for (int l = 0; l < (int)mOver.size(); l++)
    586 	{
    587 		DrawParallax(mRen, mOver.at(l), mCam, mParallax_over.at(l), mHeight, mWidth);
    588 	}
    589 
    590 	mHUD.DrawWidgets();
    591 
    592 	///Play Sounds
    593 	mSoundLib.UpdateRegionSounds(mPlayer->GetPosition());
    594 	mSoundLib.UpdatePointSounds(mCam.GetCenterX(), mCam.GetCenterY());
    595 	
    596 	//gCons->ConsPrintf("%d channels are playing\n", Mix_Playing(-1));
    597 
    598 	///Draw Diagnositic rectangles
    599 	gDiagDraw->Update();
    600 	
    601 	return true;
    602 }
    603 
    604 bool Level::EventProcess(Event eve)
    605 {
    606 	return true;
    607 }