예제 #1
0
void Game_init(void* context) {
	Game* this = context;

	// f**k this lua setup it's just stupid
	// I screwed this up
	this->leftScene = Scene_create(this->engine, "scenes/initRed.lua", NULL);
	this->rightScene = Scene_create(this->engine, "scenes/initBlue.lua", NULL);
	this->leftScene = Scene_create(this->engine, "scenes/stage1.lua", this->leftScene);
	this->rightScene = Scene_create(this->engine, "scenes/stage1.lua", this->rightScene);

	Game_setupPlayer(this, 0, this->leftScene);
	Game_setupPlayer(this, 1, this->rightScene);

	this->leftPlayer->opponent = this->rightPlayer;
	this->rightPlayer->opponent = this->leftPlayer;

	Player_switchMode(this->leftPlayer);

	this->hourglass = Hourglass_create(this->engine);
	this->hourglass->sprite->bounds.x = SCENE_WIDTH;
	this->hourglass->sprite->bounds.y = (SCENE_HEIGHT/2) - (this->hourglass->sprite->bounds.h/2);
	this->hourglass->data = this;
	this->hourglass->onSpin = Game_onHourglassSpin;

	SDL_Point p1 = {.x=SCENE_WIDTH, .y=1};
	this->leftPlayer->sidebarUi = PlayerSidebarUi_create(this->leftPlayer, p1);

	SDL_Point p2 = {.x=SCENE_WIDTH, .y=(SCENE_HEIGHT/2) + (this->hourglass->sprite->bounds.h/2)};
	this->rightPlayer->sidebarUi = PlayerSidebarUi_create(this->rightPlayer, p2);
}

void Game_setupPlayer(Game* this, int i, Scene* scene) {

	if (i == 0) {
		scene->colorPrefix = "red";
		this->leftPlayer = Player_create(scene, this->engine->input[i]);
	} else if (i == 1) {
		scene->colorPrefix = "blue";
		scene->camera->translation.x = SCENE_WIDTH + SCENE_SPACER_WIDTH;
		scene->camera->translation.y = 0;
		scene->mirrorTiles = true;

		this->rightPlayer = Player_create(scene, this->engine->input[i]);

	}
	Scene_setBounds(scene, 0, 0, SCENE_WIDTH, SCENE_HEIGHT);
}

void Game_onStartButton(UiNode* button) {
	printf("OH NO SOMEBODY REALLY WANT'S TO PLAY THIS SHIT");
}

void Game_update(void* context, RawTime dt) {
	Game* this = context;
	Scene_update(this->leftScene, dt);
	Scene_update(this->rightScene, dt);
	Player_update(this->leftPlayer, dt);
	Player_update(this->rightPlayer, dt);
	Hourglass_update(this->hourglass, dt);
}
int main(int argc, char* argv[])
{
    if(SDL_Init(SDL_INIT_EVERYTHING) == -1) {
        throw_SDLerror();
    }
    if(TTF_Init() == -1) {
        throw_SDLerror();
    }

    window = SDL_CreateWindow(GAME_TITLE, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, GAME_WIDTH, GAME_HEIGHT, SDL_WINDOW_RESIZABLE);
    renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
    SDL_RenderSetLogicalSize(renderer, GAME_WIDTH, GAME_HEIGHT);

    // TODO: black loading screen is boring.
    screen_clear();
    screen_display();

    asset_init();
    Player_create();
    Map_init();

    run();

    asset_quit();

    TTF_Quit();
    SDL_Quit();

    return 0;
}
예제 #3
0
void InGame_init(InGame* self)
{
	//Initialise all the variables
	self->map        = NULL;
	SDL_Rect scoreRect;
	scoreRect.x = 10;
	scoreRect.y = 20;

	//All the text
	self->scoreLabel       = Text_create(&scoreRect, globalVar_window, &WHITE, (TTF_Font*)ResourcesManager_getData(globalVar_fonts, "dejavu"), "00000000");
	((Drawable*)(self->scoreLabel))->setStatic((Drawable*)(self->scoreLabel), true);
	
	self->timeLabel       = Text_create(&scoreRect, globalVar_window, &WHITE, (TTF_Font*)ResourcesManager_getData(globalVar_fonts, "dejavu"), "000");
	((Drawable*)(self->timeLabel))->setStatic((Drawable*)(self->timeLabel), true);

	self->gameOver        = Text_create(&scoreRect, globalVar_window, &WHITE, (TTF_Font*)ResourcesManager_getData(globalVar_fonts, "dejavu"), "Game Over");
	self->winLabel        = Text_create(&scoreRect, globalVar_window, &WHITE, (TTF_Font*)ResourcesManager_getData(globalVar_fonts, "dejavu"), "Win");
	((Drawable*)(self->gameOver))->setStatic((Drawable*)(self->gameOver), true);
	((Drawable*)(self->winLabel))->setStatic((Drawable*)(self->winLabel), true);

	self->lifeText        = Text_create(&scoreRect, globalVar_window, &WHITE, (TTF_Font*)ResourcesManager_getData(globalVar_fonts, "dejavu"), "Life x3");
	((Drawable*)(self->lifeText))->setStatic((Drawable*)(self->lifeText), true);

	const SDL_Rect* timeLabelRect = Drawable_getRect((Drawable*)(self->timeLabel));
	((Drawable*)(self->timeLabel))->setPosition((Drawable*)(self->timeLabel), SCREEN_WIDTH - 10 - timeLabelRect->w, SCREEN_HEIGHT - 20 - timeLabelRect->h);
	((Drawable*)(self->gameOver))->setPosition((Drawable*)(self->gameOver), 360, 290);
	((Drawable*)(self->winLabel))->setPosition((Drawable*)(self->winLabel), 360, 290);
	((Drawable*)(self->lifeText))->setPosition((Drawable*)(self->lifeText), 380, 20);

	//The player
	self->player             = Player_create(0, 0);

	//Use reinit for not redo the work twice
	InGame_reinit((Context*)self);
	if(self->player == NULL)
	{
		perror("Error while loading the player \n");
		return;
	}

	//Set polymorphisme functions
	((Context*)self)->run         = &InGame_run;
	((Context*)self)->updateEvent = &InGame_updateEvent;
	((Context*)self)->reinit      = &InGame_reinit;
}