Esempio n. 1
0
void Game_draw(void* context, SDL_Renderer* renderer) {
	Game* this = context;
	Scene_draw(this->leftScene, renderer);
	Scene_draw(this->rightScene, renderer);
	Player_draw(this->leftPlayer, renderer);
	Player_draw(this->rightPlayer, renderer);
	Hourglass_draw(this->hourglass, renderer);
}
Esempio n. 2
0
EnumContext InGame_run(Context* context)
{
	SDL_SetRenderDrawColor(globalVar_window->renderer, 0x93, 0xbb, 0xec, 0xff);
	InGame* self = (InGame*)context;

	//If we haven't the map, we recreate it
	if(self->map == NULL)
	{
		InGame_loadMap(self, "Resources/Tile.xml");
		if(self->map == NULL || globalVar_window == NULL)
			return NOTHING;
		SDL_Point start = Map_getStartCoords(self->map);
		const SDL_Rect* playerRect = Drawable_getRect((Drawable*)self->player);
		((Drawable*)self->player)->setPosition((Drawable*)self->player, start.x, start.y + self->map->caseSizeX - playerRect->h-1);
	}

	//If the game continues
	if(!self->hasDied && !self->hasWon)
	{
		//Update it
		InGame_updatePlayer(self);
		InGame_updateTime(self);
		InGame_updateCamera(self);
	}

	//Look is we are outside the map
	const SDL_Rect* rect = Drawable_getRect((Drawable*)self->player);
	if(Map_isOutside(self->map, rect->x, rect->y + rect->h) && Map_isOutside(self->map, rect->x + rect->w, rect->y + rect->h) || TIMEOUT-(self->currentTime - self->initTime)/1000 == 0)
    {
		//Then we die
		self->hasDied = true;
		Player_stop(self->player);
    }

	//Then we display them;
	Map_draw(self->map, globalVar_window);
	Player_draw((Drawable*)(self->player), globalVar_window);
	InGame_drawUI(self);

	//We we have validate the game over
	if(self->hasActivedGameOver)
	{
		//We look about our current life
		self->nbLifes--;
		InGame_setLifeLabel(self);
		if(self->nbLifes == 0)
			return START; //And call the Start context if we loose
		//Or we redo the game
		else
		{
			self->hasActivedGameOver = false;
			self->hasDied = false;
			InGame_addScore(self, -self->score);
		}
	}

	if(self->hasActivedWin)
		return START;
	return NOTHING;
}
Esempio n. 3
0
/**
 * draw_objects
 * Draws all physical objects, but not HUD text.
 */
void draw_objects(Game* game) {

    // Setup projection/camera
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glViewport(0.0, 0.0, window_width, window_width);
    glOrtho(-view_width/2, view_width/2, -view_width/2, view_width/2, 0.0, 4000);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    gluLookAt(
        0.0, 0, 10,
        0.0, 0.0, 0.0,
        0.0, 1.0, 0.0);

    // Draw everything 9 times
    // This creates the screen wrapping effect.  When something moves off of
    // the screen in one direction, another drawing enters on the opposite
    // side.  When updating x and y for each item, they have to add or subtract
    // their screen width at some point, but it isn't sensitive exactly when.
    for (int x_offset=-1; x_offset<=1; x_offset++) {
        for (int y_offset=-1; y_offset<=1; y_offset++) {

            glMatrixMode( GL_MODELVIEW );
            glPushMatrix();
            glTranslatef(
                game->screen_width*x_offset,
                game->screen_width*y_offset,
                0
            );

            // Actual Drawing
            Asteroid_draw_list(game->asteroids);
            Bullet_draw_list(game->bullets, game->screen_width);
            Crystal_draw_list(game->crystals);
            Explosions_draw(game->particles);
            Player_draw(game->player);

            glPopMatrix();

        }
    }

    // Non wrapping objects
    Alien_draw_list(game->aliens);

}