//Core class body

#include"core.h"

void Core::init(){
	SDL_Init(SDL_INIT_VIDEO);
	gWindow = SDL_CreateWindow("Platform Test!",SDL_WINDOWPOS_CENTERED,SDL_WINDOWPOS_CENTERED,SCREEN_WIDTH,SCREEN_HEIGHT,SDL_WINDOW_SHOWN);
	gRenderer = SDL_CreateRenderer(gWindow,-1,SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
	SDL_SetRenderDrawColor(gRenderer,0xFF,0xFF,0xFF,0xFF);

	sz = SCREEN_WIDTH/16;
}

void Core::close(){
	SDL_DestroyRenderer(gRenderer);
	SDL_DestroyWindow(gWindow);
	gWindow = NULL;
	gRenderer = NULL;

	SDL_Quit();
}

int Core::coreInit(){
	init();

	/*bool quit = false;
	SDL_Event e;

	while(!quit){
		while(SDL_PollEvent(&e)!=0){
			if(e.type == SDL_QUIT){
				quit = true;
			}
		}
		SDL_SetRenderDrawColor(gRenderer,0,0,100,0xFF);
		SDL_RenderClear(gRenderer);


		SDL_RenderPresent(gRenderer);
	}*/

	if(menu(gRenderer) == 1){
        map1();
	}

	close();
	return 0;
};

void Core::map1(){
	Player posweg(&gRenderer);

	bool quit = false;
	SDL_Event e;

	while(quit == false){
		while(SDL_PollEvent(&e)!=0){
			if(e.type == SDL_QUIT){
				quit = true;
			}
		}
		SDL_SetRenderDrawColor(gRenderer,0,0,100,0xFF);
		SDL_RenderClear(gRenderer);

		Camera camera(36*sz,SCREEN_WIDTH);

		posweg.print(40,8*sz ,camera.getPosX());

		camera.update(posweg.getRectangle().x,posweg.getRectangle().y);
		Block wallA(8*sz,7*sz,sz*2,sz*2,&gRenderer,&posweg,camera.getPosX());
		Block wallB(4*sz,9*sz,sz,sz*2,&gRenderer,&posweg,camera.getPosX());
		Block wallC(6*sz,9*sz,sz,sz*2,&gRenderer,&posweg,camera.getPosX());
		Block ground(0,11*sz,16*sz,sz,&gRenderer,&posweg,camera.getPosX());
		Block ground2(sz*20,sz*11,sz*16,sz,&gRenderer,&posweg,camera.getPosX());
		Powerup powerup(13*sz,8*sz,&gRenderer,&posweg,camera.getPosX());


		SDL_RenderPresent(gRenderer);
	}

};
