Ejemplo n.º 1
0
void renderGameplay(App *app){
	SDL_BlitSurface(app->game.board.image, NULL, app->screen, NULL);

	renderDebug(app);

	if(app->game.winner){
		app->game.winner->grabbing = 0;
	}

	if(app->game.head.body.life <= 0){
		app->game.allan.body.action = ACTION_DEATH;
		app->game.indy.body.action = ACTION_DEATH;
		renderGameOver(app);
	}

	if(app->game.winner){
		renderWinner(app);
	}
	renderLifeBars(app);
	renderEnemies(app);
	renderPlayer(app, &app->game.indy);
	renderPlayer(app, &app->game.allan);
	renderHead(app);
	renderHints(app);

	checkPlayerLife(&app->game.indy, app);
	checkPlayerLife(&app->game.allan, app);

}
Ejemplo n.º 2
0
void updateProcEmpty(GContext* _ctx) {
  renderFloor(_ctx, 0);
  renderClutter(_ctx);
  renderPlayer(_ctx);
  renderWalls(_ctx, true, true, true, true);
  renderWallClutter(_ctx);
  renderArrows(_ctx, 15, 4, 4);
}
Ejemplo n.º 3
0
int main (int argc, char* argv[])
{


	if (!loadMapFromFile ("maps/level1.map"))
	{
		printf ("Can't locate map!");
	}

	initGUI();
	initMap();
	initPlayer();

	SDL_Event e;
	int quit = 0;

	int start_time;
	int urd_time;
	int wait_time;
	int target_time = 1000/FPS;

	while (!quit)
	{
		start_time = SDL_GetTicks();

		while (SDL_PollEvent (&e))
		{
			if (e.type == SDL_QUIT)
			{
				quit = 1;
			}
			else
			{
				player->left = 0;
				player->right = 0;
			}
			processInput ();
		}

		clearScreen();
		updatePlayer (player);
		renderBackground();
		renderMap();
		renderPlayer (player);
		draw();

		urd_time = (SDL_GetTicks() - start_time);
		wait_time = target_time - urd_time;

		SDL_Delay (wait_time);
	}

	destroyGUI();
	deletePlayer (player);

	return 0;
}
Ejemplo n.º 4
0
void updateProcStart(GContext* _ctx) {

  renderFloor(_ctx, 0);

  static const char* _a = "YOU";
  static const char* _b = "CANNOT";
  static const char* _c = "GO";
  static const char* _d = "BACK!";

  renderBorderText(_ctx, GRect(45, 15, 80, 100),  fonts_get_system_font(FONT_KEY_GOTHIC_28_BOLD), _a, 2, GTextAlignmentCenter, false);
  renderBorderText(_ctx, GRect(45, 45, 80, 100),  fonts_get_system_font(FONT_KEY_GOTHIC_28_BOLD), _b, 2, GTextAlignmentCenter, true);
  renderBorderText(_ctx, GRect(45, 75, 80, 100),  fonts_get_system_font(FONT_KEY_GOTHIC_28_BOLD), _c, 2, GTextAlignmentCenter, false);
  renderBorderText(_ctx, GRect(45, 105, 80, 100), fonts_get_system_font(FONT_KEY_GOTHIC_28_BOLD), _d, 2, GTextAlignmentCenter, true);
  renderClutter(_ctx);
  renderPlayer(_ctx);
  renderWalls(_ctx, true, true, true, true);
  renderWallClutter(_ctx);

  drawBitmap(_ctx, m_flagstone[ m_dungeon.m_finalPuzzle ], 0, 9);

  renderArrows(_ctx, 15, 4, 4);
}
Ejemplo n.º 5
0
int main() {
    cfguInit();
    CFGU_GetSystemModel(&MODEL_3DS);
	FILE * file;
	shouldRenderDebug = true;
	if ((file = fopen("settings.bin", "r"))) {
        fread(&shouldRenderDebug,sizeof(bool),1,file);
        fread(&shouldSpeedup,sizeof(bool),1,file);
        osSetSpeedupEnable(shouldSpeedup);
		fclose(file);
	}
    
	sf2d_init();
	csndInit();
	noItem = newItem(ITEM_NULL, 0);
	
	currentMenu = MENU_TITLE;
	currentSelection = 0;
	quitGame = false;

	icons = sfil_load_PNG_buffer(icons2_png, SF2D_PLACE_RAM);
	font = sfil_load_PNG_buffer(Font_png, SF2D_PLACE_RAM);
	bottombg = sfil_load_PNG_buffer(bottombg_png, SF2D_PLACE_RAM);
	
	dirtColor[0] = SWAP_UINT32(sf2d_get_pixel(icons, 16, 0)); 
	dirtColor[1] = SWAP_UINT32(sf2d_get_pixel(icons, 16, 1)); 
	dirtColor[2] = SWAP_UINT32(sf2d_get_pixel(icons, 16, 2)); 
	dirtColor[3] = SWAP_UINT32(sf2d_get_pixel(icons, 16, 3)); 
	dirtColor[4] = SWAP_UINT32(sf2d_get_pixel(icons, 16, 4)); 

	loadSound(&snd_playerHurt, "resources/playerhurt.raw");
	loadSound(&snd_playerDeath, "resources/playerdeath.raw");
	loadSound(&snd_monsterHurt, "resources/monsterhurt.raw");
	loadSound(&snd_test, "resources/test.raw");
	loadSound(&snd_pickup, "resources/pickup.raw");
	loadSound(&snd_bossdeath, "resources/bossdeath.raw");
	loadSound(&snd_craft, "resources/craft.raw");
	
	bakeLights();
	
	int i;
	for (i = 0; i < 5; ++i) {
		minimap[i] = sf2d_create_texture(128, 128, TEXFMT_RGBA8,
				SF2D_PLACE_RAM);
		sf2d_texture_tile32(minimap[i]);
	}
	
	sf2d_set_vblank_wait(true);

	sf2d_set_clear_color(0xFF000000);

	k_up.input = KEY_DUP | KEY_CPAD_UP | KEY_CSTICK_UP;
	k_down.input = KEY_DDOWN | KEY_CPAD_DOWN | KEY_CSTICK_DOWN;
	k_left.input = KEY_DLEFT | KEY_CPAD_LEFT | KEY_CSTICK_LEFT;
	k_right.input = KEY_DRIGHT | KEY_CPAD_RIGHT | KEY_CSTICK_RIGHT;
	k_attack.input = KEY_A | KEY_B | KEY_L | KEY_ZR;
	k_menu.input = KEY_X | KEY_Y | KEY_R | KEY_ZL;
	k_pause.input = KEY_START;
	k_accept.input = KEY_A;
	k_decline.input = KEY_B;
	k_delete.input = KEY_X;
	k_menuNext.input = KEY_R;
	k_menuPrev.input = KEY_L;

	if ((file = fopen("btnSave.bin", "rb"))) {
		fread(&k_up.input, sizeof(int), 1, file);
		fread(&k_down.input, sizeof(int), 1, file);
		fread(&k_left.input, sizeof(int), 1, file);
		fread(&k_right.input, sizeof(int), 1, file);
		fread(&k_attack.input, sizeof(int), 1, file);
		fread(&k_menu.input, sizeof(int), 1, file);
		fread(&k_pause.input, sizeof(int), 1, file);
		fread(&k_accept.input, sizeof(int), 1, file);
		fread(&k_decline.input, sizeof(int), 1, file);
		fread(&k_delete.input, sizeof(int), 1, file);
		fread(&k_menuNext.input, sizeof(int), 1, file);
		fread(&k_menuPrev.input, sizeof(int), 1, file);
		fclose(file);
	}
	
	if ((file = fopen("lastTP.bin", "r"))) {
		char fnbuf[256];
		fgets(fnbuf, 256, file); // get directory to texturepack
		loadTexturePack(fnbuf);   
		fclose(file);
	}

	tickCount = 0;
	initRecipes();
	defineTables();
	while (aptMainLoop()) {
		++tickCount;
		hidScanInput();
		tickKeys(hidKeysHeld(), hidKeysDown());

		if (quitGame) break;

		if (initGame > 0) setupGame(initGame == 1 ? true : false);

		if (currentMenu == 0) {
			tick();
			sf2d_start_frame(GFX_TOP, GFX_LEFT);

			offsetX = xscr;
			offsetY = yscr;
			sf2d_draw_rectangle(0, 0, 400, 240, 0xFF0C0C0C); //RGBA8(12, 12, 12, 255)); //You might think "real" black would be better, but it actually looks better that way
			renderLightsToStencil();

			renderBackground(xscr, yscr);
			renderEntities(player.x, player.y, &eManager);
			renderPlayer();
			
			resetStencilStuff();
			offsetX = 0;
			offsetY = 0;
			
			if(shouldRenderDebug){
			    sprintf(fpsstr, " FPS: %.0f, X:%d, Y:%d, E:%d", sf2d_get_fps(), player.x, player.y, eManager.lastSlot[currentLevel]);
			    drawText(fpsstr, 2, 225);
            }
			
			sf2d_end_frame();

            sf2d_start_frame(GFX_BOTTOM, GFX_LEFT);
                if(!shouldRenderMap){
                    sf2d_draw_texture(bottombg, 0, 0);
                    renderGui();
                } else {
                    renderZoomedMap();
                }
            sf2d_end_frame();
		} else {
			tickMenu(currentMenu);
			renderMenu(currentMenu, xscr, yscr);
		}

		sf2d_swapbuffers();
	}

	freeRecipes();

	freeLightBakes();
	sf2d_free_texture(icons);
	sf2d_free_texture(minimap[0]);
	sf2d_free_texture(minimap[1]);
	sf2d_free_texture(minimap[2]);
	sf2d_free_texture(minimap[3]);
	sf2d_free_texture(minimap[4]);
	freeSounds();
	csndExit();
    cfguExit();
	sf2d_fini();
	return 0;
}
Ejemplo n.º 6
0
int main(int argc, char* args[])
{
		srand(time(NULL));
		PLAYER* player = createPlayer();
		BACKGROUND* background = createBackground();

    LTexture lt;
		BANANA* bananaArray[MAX_NUM_OF_BANANA];
		BARRIER* barrierArray[MAX_NUM_OF_BARRIER];

		int i;
		for(i = 0; i < MAX_NUM_OF_BANANA; i++)
		{
				bananaArray[i] = createBanana();
		}

		for(i = 0; i < MAX_NUM_OF_BARRIER; i++)
		{
				barrierArray[i] = createBarrier();
		}


		if( !init() )
		{
			printf( "Failed to initialize!\n" );
		}
		else
		{

			if( !loadBackground("./media/background.png", &background->background_tex, gRenderer) || !loadPlayer("./media/minion.png", &player->player_tex, gRenderer, gSpriteClips))
			{
      	printf( "Failed to load media!\n" );
			}
			else
			{
				for(i = 0; i < MAX_NUM_OF_BANANA; i++)
				{
						loadBanana("./media/banana.png", &bananaArray[i]->banana_tex, gRenderer);
						setPosRectBanana(bananaArray[i]);
				}

				for(i = 0; i < MAX_NUM_OF_BARRIER; i++)
				{
						loadBarrier("./media/barrier.png", &barrierArray[i]->barrier_tex, gRenderer);
						setPosRectBarrier(barrierArray[i]);
				}

				bool quit = false;
				SDL_Event e;
				player->frame = 0;
				background->scrollingOffset = 0;

				while( !quit )
				{
					while( SDL_PollEvent( &e ) != 0 )
					{
						if( e.type == SDL_QUIT )
						{
							quit = true;
						}

						if(e.key.type == SDL_KEYDOWN)
						{
							switch( e.key.keysym.sym )
							{
									case SDLK_UP:
										if(canMoveUp(player))
										{
											moveUp(player);
										}
										 break;
									case SDLK_DOWN:
										if(canMoveDown(player))
										{
											moveDown(player);
										}
										break;
							}
						}


					}

					--(background->scrollingOffset);
					if( background->scrollingOffset < -background->background_tex.mWidth )
					{
						background->scrollingOffset = 0;
					}

					SDL_Rect* currentClip;

					SDL_SetRenderDrawColor( gRenderer, 0xFF, 0xFF, 0xFF, 0xFF );
					SDL_RenderClear( gRenderer );
					renderBackground(background, background->scrollingOffset, gRenderer);

					currentClip = &gSpriteClips[ player->frame / 16 ];
					renderPlayer(player, currentClip, gRenderer);
					setPosRectPlayer(player);

					for (i = 0; i < MAX_NUM_OF_BANANA; i++)
					{
						if( checkCollision(player->mPlayer, bananaArray[i]->mBanana, background->scrollingOffset))
						{
							increaseTotalScore();
							eraseBanana(bananaArray[i]);
						}

						renderBanana(bananaArray[i], background->scrollingOffset + bananaArray[i]->posX, gRenderer);
					}



					for (i = 0; i < MAX_NUM_OF_BARRIER; i++)
					{
						if( checkCollisionEnd(player->mPlayer, barrierArray[i]->mBarrier, background->scrollingOffset))
						{
							closeWin(player, background, bananaArray, barrierArray);
							return 0;
						}

						renderBarrier(barrierArray[i], background->scrollingOffset + barrierArray[i]->posX, gRenderer);
					}



					++player->frame;

					if( player->frame / 4 >= WALKING_ANIMATION_FRAMES )
					{
						player->frame = 0;
					}


					SDL_RenderPresent(gRenderer);


				}
					closeWin(player, background, bananaArray, barrierArray);

			}
		}
		return 0;
}
Ejemplo n.º 7
0
int main()
{
	sf2d_init();
	csndInit();
	noItem = newItem(ITEM_NULL,0);
	
	currentMenu = MENU_TITLE;
    currentSelection = 0;
	quitGame = false;

    icons = sfil_load_PNG_buffer(icons2_png, SF2D_PLACE_RAM);
    font = sfil_load_PNG_buffer(Font_png, SF2D_PLACE_RAM);
	
	//consoleInit(GFX_BOTTOM, NULL);
   // printf("Press 'Start' to exit.\n");

	loadSound(&snd_playerHurt, "resources/playerhurt.raw");
	loadSound(&snd_playerDeath, "resources/playerdeath.raw");
	loadSound(&snd_monsterHurt, "resources/monsterhurt.raw");
	loadSound(&snd_test, "resources/test.raw");
	loadSound(&snd_pickup, "resources/pickup.raw");
	loadSound(&snd_bossdeath, "resources/bossdeath.raw");
	loadSound(&snd_craft, "resources/craft.raw");
    
    int i;
    for(i = 0;i < 5;++i){
       minimap[i] = sf2d_create_texture(128,128,TEXFMT_RGBA8,SF2D_PLACE_RAM);
	   sf2d_texture_tile32(minimap[i]);
    }
    
    sf2d_set_vblank_wait(true);
	
	sf2d_set_clear_color(0xFF);
	
	/* Default inputs */
	k_up.input = KEY_DUP | KEY_CPAD_UP | KEY_CSTICK_UP;
	k_down.input = KEY_DDOWN | KEY_CPAD_DOWN | KEY_CSTICK_DOWN;
	k_left.input = KEY_DLEFT | KEY_CPAD_LEFT | KEY_CSTICK_LEFT;
	k_right.input = KEY_DRIGHT | KEY_CPAD_RIGHT | KEY_CSTICK_RIGHT;
	k_attack.input = KEY_A | KEY_B | KEY_L | KEY_ZR;
	k_menu.input = KEY_X | KEY_Y | KEY_R | KEY_ZL;
	k_pause.input = KEY_START;
    k_accept.input = KEY_A;
    k_decline.input = KEY_B;
    k_delete.input = KEY_X;
    FILE * file;
    
    /* If btnSave exists, then use that. */
    if ((file = fopen("btnSave.bin", "rb"))){
        fread(&k_up.input, sizeof(int), 1, file);
        fread(&k_down.input, sizeof(int), 1, file);
        fread(&k_left.input, sizeof(int), 1, file);
        fread(&k_right.input, sizeof(int), 1, file);
        fread(&k_attack.input, sizeof(int), 1, file);
        fread(&k_menu.input, sizeof(int), 1, file);
        fread(&k_pause.input, sizeof(int), 1, file);
        fread(&k_accept.input, sizeof(int), 1, file);
        fread(&k_decline.input, sizeof(int), 1, file);
        fread(&k_delete.input, sizeof(int), 1, file);
        fclose(file);
    }
	
	//screenShot = false;
	
    tickCount=0;
    initRecipes();
    defineTables();
	while (aptMainLoop()) {
		++tickCount;
		hidScanInput();
		tickKeys(hidKeysHeld(),hidKeysDown());

		//if (quitGame || hidKeysHeld() & KEY_SELECT) break;
		if (quitGame) break;
		//if (hidKeysDown() & (KEY_L | KEY_R)) screenShot = true;
	//	else screenShot = false;
        
        if(initGame > 0) setupGame(initGame == 1 ? true : false);
        
        if(currentMenu == 0){
            tick();
            sprintf(fpsstr, " FPS: %.0f, X:%d, Y:%d, E:%d", sf2d_get_fps(),player.x, player.y,eManager.lastSlot[currentLevel]);
		    sf2d_start_frame(GFX_TOP, GFX_LEFT);
                if(currentLevel == 0){ 
                    sf2d_draw_texture_part_scale(minimap[1],(-xscr/3)-256,(-yscr/3)-32,0,0,128,128,12.5,7.5);
                    sf2d_draw_rectangle(0,0,400,240, 0xDFDFDFAF);
                }
	            offsetX = xscr;offsetY = yscr;
		        renderBackground(xscr,yscr);
		        renderEntities(player.x, player.y, &eManager);
		        renderPlayer();
	            offsetX = 0;offsetY = 0;
		        renderItemWithText(player.p.activeItem, 10, 205);
		       // drawText(debugText,2,208);
		        drawText(fpsstr,2,225);
		    sf2d_end_frame();
		      
		    sf2d_start_frame(GFX_BOTTOM, GFX_LEFT);	
		        if(currentLevel == 0 && airWizardHealthDisplay > 0){ 
                    sprintf(bossHealthText, "BOSS: %.0f%%", ((float)airWizardHealthDisplay/2000.0)*100);
                    drawText(bossHealthText,2,225);
                }
		        renderGui();
                sf2d_draw_texture(minimap[currentLevel], 192, 112);//y:56
            sf2d_end_frame();
        } else{ 
            tickMenu(currentMenu);
            renderMenu(currentMenu,xscr,yscr);
        }
        
		sf2d_swapbuffers();
	}
	
    freeRecipes();
	sf2d_free_texture(icons);
	sf2d_free_texture(minimap[0]);
	sf2d_free_texture(minimap[1]);
	sf2d_free_texture(minimap[2]);
	sf2d_free_texture(minimap[3]);
	sf2d_free_texture(minimap[4]);
    freeSounds();
    csndExit();
	sf2d_fini();
	return 0;
}
Ejemplo n.º 8
0
void Main()
{
	ResourceLoader resources;

	auto sampler = SamplerState(SamplerState::Default2D);
	sampler.filter = TextureFilter::MinMagMipPoint;
	Graphics2D::SetSamplerState(sampler);

	Window::Resize(320 * 2, 240 * 2);
	Window::SetTitle(L"まちへかえろう(仮)");

	Array<HurdleObject> hurdles;
	Array<BuildingLayer> buildingLayers;
	Array<BuildingLayer2> buildingLayers2;

	Map::instance().init(40, 15);

	for (int i = 0; i < 40; i++)
	{
		Map::instance().set(i, 14, 5);
		Map::instance().set(i, 13, 5);
		Map::instance().set(i, 12, 4);
		Map::instance().set(i, 11, 3);
		Map::instance().set(i, 10, 3);
		Map::instance().set(i, 9, 2);
		Map::instance().set(i, 8, 1);
	}
	auto viewLeft = 0.0;
	auto mycharDead = false;
	ScreenState currentState = ScreenState::InTitle, prevState = currentState;
	bool prevSpacePressed = false;

	auto TitleTimer = TimerMillisec();

	ScriptEngine asEngine;
	asEngine.RegisterMethod(L"int getAt(double x, double y)", &Map::getAt, Map::instance());
	asEngine.RegisterProperty(L"double _viewX", &viewLeft);
	asEngine.RegisterProperty(L"bool _isGameOvered", &mycharDead);
	asEngine.RegisterFunction(L"void playJumpSound()", PlayJumpSound);
	auto context_mychar = asEngine.CreateContextFromScript(L"res/scripts/Mychar.as");

	Record::instance().init();

	int fc = 0;
	while (System::Update())
	{
		bool spacePressedInFrame = !prevSpacePressed && Input::KeySpace.pressed;
		prevSpacePressed = Input::KeySpace.pressed;

		asEngine.setFrameCount(fc);

		switch (currentState)
		{
		case ScreenState::InTitle:
			if (!TitleTimer.isActive) TitleTimer.start();
			renderBackgrounds(viewLeft, resources);
			renderBuildingLayers(buildingLayers, buildingLayers2, resources);
			renderMap(viewLeft, resources);
			renderTitle(TitleTimer.elapsed(), resources);
			renderCurrentMax();

			if (spacePressedInFrame)
			{
				// GameInit
				SoundAsset(SoundResourceLoader::decide).play();
				viewLeft = 0.0;
				mycharDead = false;
				context_mychar.Reenter();
				buildingLayers.clear();
				buildingLayers2.clear();
				hurdles.clear();
				currentState = ScreenState::Gaming;
			}
			break;
		case ScreenState::Gaming:
			// appear hurdles at random
			if (RandomBool(0.02))
			{
				if (hurdles.empty() || hurdles.back().getPos().x - (viewLeft + 320.0f) < -48.0f)
				{
					// allocate space least 48 logical-pixels
					hurdles.emplace_back(HurdleObject(Vec2(viewLeft + 320.0f, 8.0f * 16.0f + 8.0f)));
				}
			}
			// appear building at random
			if (RandomBool(0.02 / 30.0))
			{
				if (buildingLayers.empty() || buildingLayers.back().getPos().x < 0.0f)
				{
					buildingLayers.emplace_back(BuildingLayer(Vec2(320.0f, -60.0f)));
				}
			}
			if (RandomBool(0.01 / 30.0))
			{
				if (buildingLayers2.empty() || buildingLayers2.back().getPos().x < 0.0f)
				{
					buildingLayers2.emplace_back(BuildingLayer2(Vec2(320.0f, -60.0f)));
				}
			}

			asEngine.setFrameCount(fc);
			context_mychar.Execute();

			renderBackgrounds(viewLeft, resources);
			renderBuildingLayers(buildingLayers, buildingLayers2, resources);
			renderMap(viewLeft, resources);
			if (renderHurdlesAndHitTest(viewLeft, context_mychar.GetGlobalDoubleVec2(L"x", L"y"), hurdles, resources))
			{
				if (!mycharDead) SoundAsset(SoundResourceLoader::died).play();
				mycharDead = true;
			}
			renderPlayer(viewLeft, context_mychar.GetGlobalDouble(L"angle"), context_mychar.GetGlobalDoubleVec2(L"x", L"y"), resources);
			renderInfo(toScore(context_mychar.GetGlobalDouble(L"x")));

			// Host Processes
			if (mycharDead && context_mychar.GetGlobalDouble(L"x") < viewLeft - 120.0f)
			{
				// update record
				Record::instance().recordScore(toScore(context_mychar.GetGlobalDouble(L"x")));
				currentState = ScreenState::Result;
			}
			break;
		case ScreenState::Result:
			renderBackgrounds(viewLeft, resources);
			renderBuildingLayers(buildingLayers, buildingLayers2, resources);
			renderMap(viewLeft, resources);
			renderHurdlesAndHitTest(viewLeft, context_mychar.GetGlobalDoubleVec2(L"x", L"y"), hurdles, resources);
			renderResult(toScore(context_mychar.GetGlobalDouble(L"x")), Record::instance().isUpdated(), fc);

			if (spacePressedInFrame)
			{
				// GameInit
				SoundAsset(SoundResourceLoader::decide).play();
				TitleTimer.reset();
				currentState = ScreenState::InTitle;
			}
			break;
		}
		if (prevState != currentState)
		{
			fc = 0;
		}
		prevState = currentState;

		// Common Postprocesses
		fc++;
		viewLeft += 2.5f;
	}

	Map::instance().clean();
}
Ejemplo n.º 9
0
void run(){
	Display gDisplay;
	Assets gAssets;
	ControlState gControlState;

	SDL_Event e;
	bool quit = false;

	srand(time(NULL));

	if (!initDisplay(&gDisplay)) {
		fprintf(stderr, "ERROR: failed to initialize\n");
		exit(1);
	}

	if (!loadAssets(&gAssets, &gDisplay)) {
		fprintf(stderr, "ERROR: failed to load game assets\n");
		exit(1);
	}

	Player p = P_createPlayer();
	AI *ai = AI_createAI();

	LinkedList playerBulletList = LL_createLinkedList();
	LinkedList enemyBulletList = LL_createLinkedList();
	LinkedList enemyList = LL_createLinkedList();

	Timer fpsCapTimer = T_createTimer();
	Timer gameTimer = T_createTimer();

	unsigned int lastShooting = 0;
	unsigned int lastEnemenySpawn = 0;
	unsigned int check = 0;
	T_start(&gameTimer);
	
	int controlarray[4] = {0};
	SDL_Rect healthbar;
	initialisehealthbar(&healthbar);
	quit = staticscreen(gDisplay.renderer, "Assets/startmenu.bmp");
	
	SDL_Surface* temp;
	SDL_Texture* background;
	temp = SDL_LoadBMP("Assets/background.bmp");
	background = SDL_CreateTextureFromSurface(gDisplay.renderer, temp);
	SDL_FreeSurface(temp);
	temp = NULL;

	/*Event loop*/
	do{
		// start frame timer
		T_start(&fpsCapTimer);
		
		// check for exit event
		SDL_PollEvent(&e);
		quit = (e.type == SDL_QUIT);
		
		// check to open ai interface
		if(e.type == SDL_KEYDOWN){
			if(e.key.keysym.sym == SDLK_ESCAPE){
				quit = openaiscreen(gDisplay.renderer, controlarray);
				e.key.keysym.sym = SDLK_0;
				SDL_PushEvent(&e);
			}
		}

		// move player
		getKeyState(&gControlState);
		getMouseState(&gControlState);

		movePlayer(&p, &gControlState, &gAssets);
		AI_move(ai, P_getPosition(&p));

		if ((check = T_getTicks(&gameTimer)) - lastEnemenySpawn > DEFAULT_SPAWN_INTERVAL) {
			spawnEnemy(&enemyList);
			lastEnemenySpawn = check;
		}
		
		aiaction(ai, &playerBulletList, &enemyList, T_getTicks(&gameTimer), controlarray, &p);

		moveEnemies(&enemyList, P_getPosition(&p));
		enemiesShoot(&enemyList, &enemyBulletList, &p, T_getTicks(&gameTimer));


		if (leftMouseIsDown() && ((check = T_getTicks(&gameTimer)) - lastShooting) > SHOOT_DELAY) {
			double mx = (double)gControlState.mouseX / SCREEN_WIDTH;
    		double my = (double)gControlState.mouseY / SCREEN_HEIGHT;
    		Point origin = P_getPosition(&p);
    		Point destination = {mx, my};
			shootBullet(&playerBulletList, origin, getShotDirection(origin, destination), PLAYER);
			lastShooting = check;
		}

		moveBullets(&playerBulletList);
		moveBullets(&enemyBulletList);

		detectCollision(&playerBulletList, &enemyList, &gAssets);
		detectCollisionPlayer(&enemyBulletList, &p, &gAssets);
		
		/* Update Screen */
		SDL_RenderCopy(gDisplay.renderer, background, NULL, NULL);
		displayhealth(gDisplay.renderer, healthbar, p.health);
		renderBullets(&playerBulletList, &gDisplay, &gAssets, PLAYER);
		renderBullets(&enemyBulletList, &gDisplay, &gAssets, ENEMY);
		renderEnemies(&enemyList, &gDisplay, &gAssets);
		renderPlayer(&gDisplay, &gAssets, &gControlState);
		renderAI(ai, &gDisplay, &gAssets);
		
		// draw screen
		SDL_RenderPresent(gDisplay.renderer);
        delayNextFrame(T_getTicks(&fpsCapTimer));

        if (gameOver(&p)) {
        	printf("GAME OVER\n");
        	quit = staticscreen(gDisplay.renderer, "Assets/gameover.bmp");
			p.health = 100;
        }

	} while (!quit);
	
	/* Memory Cleanup */
	LL_destroyLinkedList(&playerBulletList);
	LL_destroyLinkedList(&enemyBulletList);
	AI_destroyAI(ai);
	SDL_DestroyTexture(background);
	freeAssets(&gAssets);
	closeDisplay(&gDisplay);
}