Esempio n. 1
0
void render_game(GameData* data, DrawConfig* config){
    /*
     * Clear the window prior to any rendering
     */
    render_clear(config); 

    /*
     * Draw all componenets of the came
     */
    render_background(data,config);
    render_all_pipes(data,config);
    render_score(data,config);
    render_bird(data,config);

    /*
     * Render GameOver message if the user has lost
     */
    if(is_gameover(data)){
        render_gameover_message(data,config);
    }

    /*
     * Update the users view to reflect changes 
     */
    SDL_RenderPresent(config->renderer);
}
void render() {
	if (nvidia_3dv) {
		GLD3DBuffers_activate_left(&gl_d3d_buffers);
		render_clear();
		render_scene(EYE_LEFT);
		GLD3DBuffers_activate_right(&gl_d3d_buffers);
		render_clear();
		render_scene(EYE_RIGHT);
		GLD3DBuffers_deactivate(&gl_d3d_buffers);
		GLD3DBuffers_flush(&gl_d3d_buffers);
	}
	else {
		render_clear();
		render_scene(EYE_CENTER);
		SDL_GL_SwapWindow(window);
	}
}
Esempio n. 3
0
//---------------------------------------------------------------------------
//  clearChannel
//---------------------------------------------------------------------------
void clearChannel( MPKChannel *c, void *data )
{
//    FrameData *framedata = (FrameData *)data;

    mpkChannelApplyBuffer( c );
    mpkChannelApplyViewport( c );

    render_clear();
}
Esempio n. 4
0
void seal_draw() {
    struct render* R = GAME->render;
    render_clear(R, C4B_COLOR(0, 0, 255, 255));
    
    sprite_visit(GAME->root, GAME->global_dt);
    
    nk_draw();
    
    CHECK_GL_ERROR
}
Esempio n. 5
0
static void fb_helper_fill_rect(struct fb_t * fb, struct color_t * c, u32_t x, u32_t y, u32_t w, u32_t h)
{
	struct rect_t rect;

	rect.x = x;
	rect.y = y;
	rect.w = w;
	rect.h = h;

	render_clear(fb->alone, &rect, c);
}
Esempio n. 6
0
static GlyphSet create_glyphs(Display *dpy, int format_id)
{
#define N_GLYPHS 4
	XRenderPictFormat *format;
	XGlyphInfo glyph = { 8, 8, 0, 0, 8, 0 };
	char image[4*8*8];
	GlyphSet glyphset;
	Glyph gid;
	int image_size;
	int bpp;
	int n;

	format = XRenderFindStandardFormat(dpy, format_id);
	if (format == NULL)
		return 0;

	switch (format_id) {
	case PictStandardARGB32:
	case PictStandardRGB24:
		image_size = 4 * 8 * 8;
		bpp = 4;
		break;
	case PictStandardA8:
	case PictStandardA4:
		image_size = 8 * 8;
		bpp = 1;
		break;
	case PictStandardA1:
		image_size = 8;
		bpp = 0;
		break;
	default:
		return 0;
	}

	glyphset = XRenderCreateGlyphSet(dpy, format);
	for (n = 0; n < N_GLYPHS; n++) {
		gid = n;

		switch (n) {
		case 0: render_clear(image, image_size, bpp); break;
		case 1: render_black(image, image_size, bpp); break;
		case 2: render_green(image, image_size, bpp); break;
		case 3: render_white(image, image_size, bpp); break;
		}

		XRenderAddGlyphs(dpy, glyphset,
				 &gid, &glyph, 1, image, image_size);
	}

	return glyphset;
}
Esempio n. 7
0
void
run_game(lua_State *L)
{
        uint32_t now = SDL_GetTicks();   /* Current real time. */
        
        /*
         * Compute how much time has passed since last time. Watch out for time
         * wrap-around.
         */
        uint32_t delta_time = (now >= before) ? now - before :
        (uint32_t)-1 - before + now;
        before = now;
        
        /*
         * If there was some huge lag, don't make worlds catch
         * up. Instead, assume last frame took 50ms.
         */
        if (delta_time > 50)
                delta_time = 50;
        
        /* Game speed always normal. */
        uint32_t game_delta_time = delta_time;
        game_time += game_delta_time;	/* Advance game time. */
        
        /* Calculate frames per second. */
        fps_count++;
        if (now - fps_time >= config.FPSUpdateInterval && config.debug) {
                frames_per_second = fps_count*1000.0 / (now - fps_time);
                fps_time = now;
                fps_count = 0;
		extern int total_tile_count;
                log_msg("FPS: %.2f, tiles=%d", 
			frames_per_second,
			total_tile_count);
        }
        
        process_events(L);
        
#if ENABLE_AUDIO
        /* Dynamically adjust volume. */
        audio_adjust_volume();
#endif
        
        /* Step worlds. */
        extern mem_pool mp_world;
        for (World *world = mp_first(&mp_world); world != NULL;
             world = mp_next(world)) {
                if (world->killme)
                        continue;       /* We deal with these below. */
                
                /* Bring world up to present game time. */
                while (game_time >= world->next_step_time) {
                        world->next_step_time += world->step_ms;
                        
                        /*
                         * Step world -- execute body step functions, timers,
                         * collision handlers.
                         */
                        world_step(world, L);
                        
                        /*
                         * Handle user input. To be more responsive, we do this
                         * here between steps too.
                         */
                        process_events(L);
                        
                        if (world->killme)
                                break;	/* No need to keep going. */
                }
        }
        
        /*
         * Deal with worlds that have either been destroyed or created in the
         * loop above. Must do this here so scripts get a chance to set
         * everything up before a frame is rendered.
         */
        for (World *world = mp_first(&mp_world); world != NULL;) {
                if (world->killme) {
                        /*
                         * Remove dying worlds. Take care to get next world
                         * pointer before destruction.
                         */
                        World *tmp = world;
                        world = mp_next(world);
                        world_free(tmp);
                        continue;
                }
                
                /* Perform the initial step on recently created worlds. */
                if (world->static_body.step == 0) {
                        /*
                         * We must give scripts control over what the contents
                         * of the world look like before drawing it. Otherwise
                         * we get such artifacts as camera centered on origin
                         * even though it should be tracking a player character.
                         */
                        world_step(world, L);
                }
                world = mp_next(world);
        }
        
        /*
         * Draw what each camera sees.
         */
        render_clear();
        for (Camera *cam = cam_list; cam != NULL; cam = cam->next) {
                if (!cam->disabled)
                        render(cam);
        }
        
#ifndef NDEBUG
        /* Debug stuff is drawn over normal stuff. */
        if (debug_cam != NULL && debug_cam->objtype == OBJTYPE_CAMERA)
                render_debug(debug_cam);
#endif
}
Esempio n. 8
0
void 
shader_clear(unsigned long argb) {
	render_clear(RS->R, MASKC, argb);
}
Esempio n. 9
0
int main_mainmenu()
{
	SDL_Event e;

	SDL_ShowCursor(SDL_ENABLE);

	g_current_level = level_load("mainmenuconfig");
	render_set_background(g_current_level->background->image);

	player_initialize_list();

	ui_initialize_mainmenu(rtn_renderer());

	do
	{
		render_update(0);
		render_clear();
		while(SDL_PollEvent(&e))
		{
			if(e.type == SDL_KEYDOWN)
			{
				if(e.type == SDL_QUIT)
					exit(0);
				if(e.key.keysym.sym == SDLK_ESCAPE)
				{
					currentstate = EXIT;
					exit(0);
				}
			}
			if(e.type == SDL_MOUSEBUTTONDOWN)
			{
				if(e.button.button == SDL_BUTTON_LEFT)
				{
					click = 1;
				}
			}
			if(e.type == SDL_MOUSEBUTTONUP)
			{
				if(e.button.button == SDL_BUTTON_LEFT)
				{
					click = 0;
				}
			}
			
			if(playclicked == 1)
			{
				slog("Changed to Deathmatch");
				currentstate = DEATHMATCH;
			}
			else if(editorclicked == 1)
			{
				slog("Changed to LevelEditor");
				currentstate = LEVELEDITOR;
			}
			else if(quitclicked == 1)
			{
				exit(0);
			}
		}
	} while(currentstate == MAINMENU);
}
Esempio n. 10
0
int main_deathmatch()
{
	SDL_Event e;

	SDL_ShowCursor(SDL_DISABLE);

	entity_initialize_list(1024);
	tank_initialize_list(15);

	g_current_level = level_load("leveloneconfig");
	render_set_background(g_current_level->background->image);

	g_music = audio_load_music("sounds/music/backgroundmusic.wav");
	g_sound = audio_load_sound("sounds/digital/digital.wav");
	if(g_music->file.music != NULL)
	{
		slog("Playing Music");
		//audio_play_music(g_music->file.music);
	}
	else
		slog("Could not load music file");

	player = player_spawn("Player", PLAYER);
	v2d_set(player->tank->tracks->body->position, SCREEN_WIDTH/2, SCREEN_HEIGHT/2);
	v2d_set(player->tank->turret->body->position, SCREEN_WIDTH/2, SCREEN_HEIGHT/2);

	g_now = SDL_GetTicks();

	ui_initialize_deathmatch(rtn_renderer());

	do
	{
		//calculate deltatime
		g_last = g_now;
		g_now = SDL_GetTicks();
		g_deltatime = g_now - g_last;

		render_update(1);
		render_clear();
		entity_all_think();
		entity_all_update();
		player_move(player);
		while(SDL_PollEvent(&e))
		{
			if(e.type == SDL_KEYDOWN)
			{
				if(e.type == SDL_QUIT)
					SDL_Quit();
				if(e.key.keysym.sym == SDLK_w)
					player->keysHeld.W = 1;
				if(e.key.keysym.sym == SDLK_s)
					player->keysHeld.S = 1;
				if(e.key.keysym.sym == SDLK_a)
					player->keysHeld.A = 1;
				if(e.key.keysym.sym == SDLK_d)
					player->keysHeld.D = 1;
				if(e.key.keysym.sym == SDLK_e)
				{
					tank_weapon_change(player->tank);
					slog("Current weapon: %s", player->tank->currentweapon->name);
				}
				if(e.key.keysym.sym == SDLK_p)
				{
					audio_play_sound(g_sound->file.sound);
				}
				if(e.key.keysym.sym == SDLK_f)
				{
					Entity *sonar;
					sonar = sonar_new(sonar = entity_new(SONAR, NULL), 3.0, player->tank);
				}
				if(e.key.keysym.sym == SDLK_g)
				{
					tank_weapon_fire(player->tank);
				}
				if(e.key.keysym.sym == SDLK_h)
					player->tank->health -= 5;
				if(e.key.keysym.sym == SDLK_j)
					player->tank->armour -= 5;
				if(e.key.keysym.sym == SDLK_SPACE)
				{
					if(player->tank->is_hidden)
						player->tank->is_hidden = 0;
					else
						player->tank->is_hidden = 1;

					tank_sprite_change(player->tank);
				}
				if(e.key.keysym.sym == SDLK_ESCAPE)
				{
					playclicked = 0;
					entity_close_list();
					tank_close_list();
					player_close_list();
					currentstate = MAINMENU;
				}
			}
			if(e.type == SDL_KEYUP)
			{
				if(e.key.keysym.sym == SDLK_w)
					player->keysHeld.W = 0;
				if(e.key.keysym.sym == SDLK_s)
					player->keysHeld.S = 0;
				if(e.key.keysym.sym == SDLK_a)
					player->keysHeld.A = 0;
				if(e.key.keysym.sym == SDLK_d)
					player->keysHeld.D = 0;
			}
		}
		if(g_deltatime < 32)
			SDL_Delay(32-g_deltatime);
	} while(currentstate == DEATHMATCH);

	return 0;
}
Esempio n. 11
0
int main_leveleditor()
{
	SDL_Event e;

	SDL_ShowCursor(SDL_ENABLE);

	entity_initialize_list(1024);
	tank_initialize_list(15);

	//im a fuckboi
	editorclicked = 0;
	ui_initialize_leveleditor(rtn_renderer());

	do
	{
		render_update(1);
		render_clear();
		while(SDL_PollEvent(&e))
		{
			if(e.type == SDL_KEYDOWN)
			{
				if(e.type == SDL_QUIT)
					exit(0);
				if(e.key.keysym.sym == SDLK_ESCAPE)
				{
					editorclicked = 0;
					currentstate = MAINMENU;
				}
			}
			if(e.type == SDL_MOUSEBUTTONDOWN)
			{
				if(e.button.button == SDL_BUTTON_LEFT)
				{
					click = 1;
				}
			}
			if(e.type == SDL_MOUSEBUTTONUP)
			{
				if(e.button.button == SDL_BUTTON_LEFT)
				{
					click = 0;
				}
			}
			if(saveclicked == 1)
			{
				saveclicked = 0;
				slog("save clicked");
			}
			else if(loadclicked == 1)
			{
				loadclicked = 0;
				slog("load clicked");
			}
			else if(backclicked == 1)
			{
				backclicked = 0;
				currentstate = MAINMENU;
			}
		}
	} while(currentstate == LEVELEDITOR);
}
Esempio n. 12
0
/**  Role : prepare frame rendering depending on status
  *  Output : - */
void render_setRendering(
    CONFIG *pstParams,    //parameters : status, timers, level, bonus
    float fPercentUpdate, //interpolation
    BALL *pstBall,        //ball information : coord, speed
    PLAYER *astPlayers    //players information: coord, offset, speed, score, bonus
)
{
    /* display in-game frame */
    if( pstParams->status == -2 )
    {
        render_drawFrame( 0x0133, fPercentUpdate, pstParams, pstBall, astPlayers );
    }
    /* display special frame (message, animation, pause) */
    else
    {
        HANDLE hConsole = GetStdHandle( STD_OUTPUT_HANDLE );
        COORD coord = { 0 };
        switch( pstParams->status )
        {
            /* NEW ROUND -> animation and reset */
            case -7:
                render_drawFrame( 0x1113, fPercentUpdate, pstParams, pstBall, astPlayers );

                /* start round if animation is over */
                if( pstParams->bonus[0] >= 40 )
                {
                    pstParams->status = -2;
                    pstParams->bonus[0] = 0;
                    pstParams->clock[1] = 0;
                }
                break;

            /* NEW GAME -> instructions and wait */
            case -1:
                coord.X = 6;
                coord.Y = 38;
                SetConsoleCursorPosition( hConsole, coord );
                render_drawFrame( 0x0001, fPercentUpdate, pstParams, NULL, astPlayers );

                /* message : useable commands */
                if( pstParams->level != 4 ) //single player
                {
                    SetConsoleTextAttribute( hConsole, 0x0F );
                    printf( "  \x18\x19  " );
                    SetConsoleTextAttribute( hConsole, 0x07 );
                    printf( "D\x82placer        " );
                    SetConsoleTextAttribute( hConsole, 0x0F );
                    printf( "ESC  " );
                    SetConsoleTextAttribute( hConsole, 0x07 );
                    printf( "Afficher menu        " );
                    SetConsoleTextAttribute( hConsole, 0x0F );
                    printf( "P  " );
                    SetConsoleTextAttribute( hConsole, 0x07 );
                    printf( "Mettre en pause" );
                }
                else //2 players
                {
                    SetConsoleTextAttribute( hConsole, 0x0F );
                    printf( "ZS  " );
                    SetConsoleTextAttribute( hConsole, 0x07 );
                    printf( "D\x82placer         " );
                    SetConsoleTextAttribute( hConsole, 0x0F );
                    printf( "ESC  " );
                    SetConsoleTextAttribute( hConsole, 0x07 );
                    printf( "Menu         " );
                    SetConsoleTextAttribute( hConsole, 0x0F );
                    printf( "P  " );
                    SetConsoleTextAttribute( hConsole, 0x07 );
                    printf( "Pause         " );
                    SetConsoleTextAttribute( hConsole, 0x0F );
                    printf( "\x18\x19  " );
                    SetConsoleTextAttribute( hConsole, 0x07 );
                    printf( "D\x82placer" );
                }
                /* message : instructions */
                coord.X = 24;
                coord.Y = 19;
                SetConsoleCursorPosition( hConsole, coord );
                printf( "Appuyez sur ENTER pour commencer." );
                Sleep( 28 );
                break;

            /* PAUSE -> animation */
            case -3:
                coord.X = 35;
                coord.Y = 20;
                SetConsoleCursorPosition( hConsole, coord );
                render_drawFrame( 0x0001, 0, pstParams, pstBall, astPlayers );

                /* pause message */
                if( pstParams->clock[0]%2 == 0 )
                {
                    SetConsoleTextAttribute( hConsole, 0x0F );
                    printf( "P A U S E" );
                    SetConsoleTextAttribute( hConsole, 0x07 );
                }
                else
                {
                    printf( "P A U S E" );
                }
                Sleep( 28 );
                break;

            /* ROUND END -> message and latence */
            case -4:
            case -5:
                coord.X = 31;
                coord.Y = 19;
                SetConsoleCursorPosition( hConsole, coord );
                render_drawFrame( 0x0103, 0, pstParams, NULL, astPlayers );

                /* round message */
                if( pstParams->level != 4 )
                {
                    if( pstParams->status == -4 )
                        printf( "   Vous gagnez." );
                    else
                        printf( "   Vous perdez." );
                }
                else
                {
                    if( pstParams->status == -4 )
                        printf( "Le joueur 1 gagne." );
                    else
                        printf( "Le joueur 2 gagne." );
                }
                /* wait for one second */
                if( pstParams->clock[1] > 1 )
                {
                    pstParams->status = -6;
                }
                Sleep( 28 );
                break;

            /* GAME END -> message, latence and wait */
            case -8:
            case -9:
                render_drawFrame( 0x0301, 0, pstParams, NULL, astPlayers );

                /* message : results */
                coord.X = 27;
                if( pstParams->level != 4 ) //single player
                {
                    short sScore = 0;
                    coord.Y = 17;
                    SetConsoleCursorPosition( hConsole, coord );
                    if( pstParams->status == -8 )
                        printf( " Vous remportez la partie." );
                    else
                        printf( " Vous avec perdu la partie." );
                    /* display details : difficulty */
                    coord.X = 31;
                    coord.Y = 20;
                    SetConsoleCursorPosition( hConsole, coord );
                    printf( "Difficult\x82  : " );
                    switch( pstParams->level )
                    {
                        case 1: printf( "facile" );
                            break;
                        case 3: printf( "expert" );
                            break;
                        default: printf( "v\x82t\x82ran" );
                    }
                    /* display details : time */
                    coord.X = 31;
                    coord.Y = 21;
                    SetConsoleCursorPosition( hConsole, coord );
                    printf( "Dur\x82\x65 jeu   : %02hu:%02hu", pstParams->clock[0]/60, pstParams->clock[0]%60 );
                    /* display details : score */
                    coord.X = 31;
                    coord.Y = 22;
                    SetConsoleCursorPosition( hConsole, coord );
                    sScore = ( 2*astPlayers[0].score - astPlayers[1].score )*pstParams->level;
                    if( sScore < 0 )
                        sScore = 0;
                    printf( "Score moyen : %hd", sScore );
                    coord.Y = 25;
                }
                else //2 players
                {
                    coord.Y = 19;
                    SetConsoleCursorPosition( hConsole, coord );
                    if( pstParams->status == -8 )
                        printf( "Le joueur 1 gagne la partie." );
                    else
                        printf( "Le joueur 2 gagne la partie." );
                    /* display details : time */
                    coord.X = 31;
                    coord.Y = 21;
                    SetConsoleCursorPosition( hConsole, coord );
                    printf( "Dur\x82\x65 partie : %02hu:%02hu", pstParams->clock[0]/60, pstParams->clock[0]%60 );
                    coord.Y = 23;
                }

                /* message : instructions */
                Sleep( 800 );
                coord.X = 19;
                SetConsoleCursorPosition( hConsole, coord );
                printf( "Appuyez sur une touche pour revenir au menu." );
                /* empty buffer and wait for reaction */
                while( _kbhit() != 0 )
                {
                    _getch();
                }
                do
                {
                    _getch();
                }
                while( _kbhit() != 0 );
                pstParams->status = 1;
                render_clear();
                break;
        }//switch
    }//else
}//render_setRendering