Exemplo n.º 1
0
static void finalize_level( void )
{
	/* set alpha keys to OPAQUE */
	SDL_SetAlpha( paddle_pic, 0,0 );
	SDL_SetAlpha( weapon_pic, 0,0 );
	SDL_SetAlpha( extra_pic, 0,0 );
	SDL_SetAlpha( ball_pic, 0,0 );
	SDL_SetAlpha( shot_pic, 0,0 );
	SDL_SetAlpha( display_font->surface, 0,0 );

	/* reset ball graphic */
	ball_pic_x_offset = 0;
	
	/* reset shrapnells */
	shrapnells_reset();
	/* reset shine */
	shine_reset();
	/* reset explosions */
	exps_clear();
	exps_set_dark( 0 );

	/* delete offscreen */
	stk_surface_free( &offscreen );

	/* clear credits */
	credit_clear();
	
	/* clear displays */
	displays_clear();
	
	/* clear game contexts */
	if ( game->game_type == GT_LOCAL ) 
		game_finalize( local_game );
	game_finalize( game );
}
Exemplo n.º 2
0
void client_game_delete()
{
	stk_surface_free( &bkgnd );
	
	displays_clear();
	frame_delete();
	shrapnells_delete();
	shine_delete();
}
Exemplo n.º 3
0
void theme_delete()
{
    int i;
    stk_surface_free( &exp_pic );
    stk_surface_free( &exp_dark_pic );
    stk_font_free( &font );
    stk_font_free( &chat_font_normal );
    stk_font_free( &chat_font_error );
    stk_font_free( &chat_font_name );
#ifdef AUDIO_ENABLED
    stk_sound_free( &wav_click );
    stk_sound_free( &wav_damn );
    stk_sound_free( &wav_dammit );
    stk_sound_free( &wav_wontgiveup );
    stk_sound_free( &wav_excellent );
    stk_sound_free( &wav_verygood );
#endif
    stk_surface_free( &brick_pic );
    stk_surface_free( &brick_shadow );
#ifdef AUDIO_ENABLED
    stk_sound_free( &wav_boom );
#endif
    stk_surface_free( &paddle_pic );
    stk_surface_free( &weapon_pic );
    stk_surface_free( &ammo_pic );
    stk_surface_free( &paddle_shadow );
    stk_surface_free( &weapon_shadow );
#ifdef AUDIO_ENABLED
    stk_sound_free( &wav_expand );
    stk_sound_free( &wav_shrink );
    stk_sound_free( &wav_frozen );
#endif
    stk_surface_free( &ball_pic );
    stk_surface_free( &ball_shadow );
#ifdef AUDIO_ENABLED
    stk_sound_free( &wav_reflect_paddle );
    stk_sound_free( &wav_reflect_brick );
    stk_sound_free( &wav_attach );
#endif
    stk_surface_free( &shot_pic );
    stk_surface_free( &shot_shadow );
#ifdef AUDIO_ENABLED
    stk_sound_free( &wav_shot );
#endif
    stk_surface_free( &extra_pic );
    stk_surface_free( &extra_shadow );
    stk_surface_free( &wall_pic );
#ifdef AUDIO_ENABLED
    stk_sound_free( &wav_score );
    stk_sound_free( &wav_metal );
    stk_sound_free( &wav_speedup );
    stk_sound_free( &wav_speeddown );
    stk_sound_free( &wav_std );
    stk_sound_free( &wav_wall );
    stk_sound_free( &wav_joker );
    stk_sound_free( &wav_goldshower );
    stk_sound_free( &wav_chaos );
    stk_sound_free( &wav_darkness );
    stk_sound_free( &wav_ghost );
    stk_sound_free( &wav_timeadd );
    stk_sound_free( &wav_expl_ball );
    stk_sound_free( &wav_weak_ball );
    stk_sound_free( &wav_bonus_magnet );
    stk_sound_free( &wav_malus_magnet );
    stk_sound_free( &wav_disable );
#endif
    stk_surface_free( &shine_pic );
    stk_surface_free( &frame_left );
    stk_surface_free( &frame_right );
    stk_surface_free( &frame_top );
    stk_surface_free( &frame_left_shadow );
    stk_surface_free( &frame_right_shadow );
    stk_surface_free( &frame_top_shadow );
    stk_surface_free( &lamps );
    stk_font_free( &display_font );
    stk_font_free( &display_highlight_font );
#ifdef AUDIO_ENABLED
    stk_sound_free( &wav_life_up );
    stk_sound_free( &wav_life_down );
#endif
    if ( bkgnds ) {
        for ( i = 0; i < bkgnd_count; i++ )
            stk_surface_free( &bkgnds[i] );
        free( bkgnds );
        bkgnds = 0;
        bkgnd_count = 0;
    }
    stk_surface_free( &nuke_bkgnd );
    /* chatroom */
    stk_surface_free( &cr_up );
    stk_surface_free( &cr_down );
    stk_surface_free( &cr_track );
    stk_surface_free( &cr_wallpaper );
    /* frame box */
    stk_surface_free( &fr_vert );
    stk_surface_free( &fr_hori );
    stk_surface_free( &fr_luc );
    stk_surface_free( &fr_llc );
    stk_surface_free( &fr_ruc );
    stk_surface_free( &fr_rlc );
    /* manager */
    stk_surface_free( &mbkgnd );
    stk_font_free( &mfont );
    stk_font_free( &mhfont );
    stk_font_free( &mcfont );
#ifdef AUDIO_ENABLED
    stk_sound_free( &wav_menu_click );
    stk_sound_free( &wav_menu_motion );
#endif
    /* charts */
    stk_font_free( &cfont );
    stk_font_free( &chfont );
    stk_font_free( &ccfont );
    /* warp picture */
    stk_surface_free( &warp_pic );
}
Exemplo n.º 4
0
/*
====================================================================
Load theme by name or delete current theme (is done by load too
so it might be used to change a theme as well.)
====================================================================
*/
void theme_load( char *name )
{
    SDL_Surface *surf;
    struct stat filestat;
    char aux[128];
    int i;
    printf( "Loading theme '%s'\n", name );
    /* clear resources */
    theme_delete();
    /* set theme directory */
    theme_set_dir( name );
    /* load resources */
    /* explosions */
    exp_pic = theme_load_surf( "explosions.png" );
    exp_dark_pic = theme_load_surf( "explosions_dark.png" );
    /* main game font */
    font = theme_load_font_fixed( "f_game.png", 32, 96, 10 );
    font->align = STK_FONT_ALIGN_CENTER_X | STK_FONT_ALIGN_CENTER_Y;
    /* normal chat font (messages by server) */
    chat_font_normal = theme_load_font_fixed( "f_small_yellow.png", 32, 96, 8 );
    /* error font (messages by server) */
    chat_font_error = theme_load_font_fixed( "f_small_red.png", 32, 96, 8 );
    /* username font (also for server) */
    chat_font_name = theme_load_font_fixed( "f_small_white.png", 32, 96, 8 );
    /* main game sounds */
#ifdef AUDIO_ENABLED
    wav_click = theme_load_sound( "click.wav" );
    wav_damn = theme_load_sound( "damn.wav" );
    wav_dammit = theme_load_sound( "dammit.wav" );
    wav_wontgiveup = theme_load_sound( "wontgiveup.wav" );
    wav_excellent = theme_load_sound( "excellent.wav" );
    wav_verygood = theme_load_sound( "verygood.wav" );
#endif
    /* brick pics and shadow template */
    brick_pic = theme_load_surf( "bricks.png" );
    /* default color key is: BLACK but you may specify a special
       key by adding a column of one pixel width at the end of the file */
    if ( brick_pic->w & 1 )
        SDL_SetColorKey( brick_pic, SDL_SRCCOLORKEY, stk_surface_get_pixel( brick_pic, brick_pic->w - 1, 0 ) );
    brick_shadow = create_shadow( brick_pic, 0, 0, brick_pic->w, brick_pic->h );
    /* brick destruction sound */
#ifdef AUDIO_ENABLED
    wav_boom = theme_load_sound( "exp.wav" );
#endif
    /* paddle and weapon */
    paddle_pic = theme_load_surf( "paddle.png" );
    SDL_SetColorKey( paddle_pic, SDL_SRCCOLORKEY, 
        stk_surface_get_pixel( paddle_pic, 0, 0 ) );
    if ( paddle_pic->w < 6 * paddle_cw ) {
        /* no top paddle specified so duplicate first one */
        surf = stk_surface_create( SDL_SWSURFACE, paddle_pic->w*2, paddle_pic->h );
        SDL_SetColorKey( surf, SDL_SRCCOLORKEY, paddle_pic->format->colorkey );
        SDL_FillRect( surf, 0, paddle_pic->format->colorkey );
        stk_surface_blit( paddle_pic, 0,0,-1,-1, surf, 0,0 );
        stk_surface_blit( paddle_pic, 0,0,-1,-1, surf, paddle_pic->w,0 );
        stk_surface_free( &paddle_pic ); paddle_pic = surf;
    }
    weapon_pic = theme_load_surf( "weapon.png" );
    paddle_shadow = create_shadow( paddle_pic, 0, 0, paddle_pic->w, paddle_pic->h );
    weapon_shadow = create_shadow( weapon_pic, 0, 0, weapon_pic->w, weapon_pic->h );
    ammo_pic = theme_load_surf( "ammo.png" );
    SDL_SetColorKey( ammo_pic, SDL_SRCCOLORKEY, 0x0 );
    /* paddle sounds */
#ifdef AUDIO_ENABLED
    wav_expand = theme_load_sound( "expand.wav" );
    wav_shrink = theme_load_sound( "shrink.wav" );
    wav_frozen = theme_load_sound( "freeze.wav" );
#endif
    /* ball gfx */
    ball_pic = theme_load_surf( "ball.png" );
    SDL_SetColorKey( ball_pic, SDL_SRCCOLORKEY, stk_surface_get_pixel( ball_pic, 0, 0 ) );
    ball_shadow = create_shadow( ball_pic, 0, 0, ball_w, ball_h );
    /* ball sounds */
#ifdef AUDIO_ENABLED
    wav_reflect_brick = theme_load_sound( "reflect_brick.wav" );
    wav_reflect_paddle = theme_load_sound( "reflect_paddle.wav" );
    wav_attach = theme_load_sound( "attach.wav" );
#endif
    /* shot gfx */
    shot_pic = theme_load_surf( "shot.png" );
    shot_shadow = create_shadow( shot_pic, 0, 0, shot_w, shot_h );
#ifdef AUDIO_ENABLED
    wav_shot = theme_load_sound( "shot.wav" );
#endif
    /* extra pic */
    extra_pic = theme_load_surf( "extras.png" );
	SDL_SetColorKey( extra_pic, 0, 0 );
    /* default color key is: disabled but you may specify a special
       key by adding a column of one pixel width at the end of the file */
    if ( extra_pic->w & 1 )
        SDL_SetColorKey( extra_pic, SDL_SRCCOLORKEY, stk_surface_get_pixel( extra_pic, extra_pic->w - 1, 0 ) );
    extra_shadow = create_shadow( extra_pic, 0, 0, extra_pic->w, extra_pic->h );
    /* extra sounds */
#ifdef AUDIO_ENABLED
    wav_score = theme_load_sound( "score.wav" );
    wav_metal = theme_load_sound( "metal.wav" );
    wav_speedup = theme_load_sound( "speedup.wav" );
    wav_speeddown = theme_load_sound( "speeddown.wav" );
    wav_std = theme_load_sound( "standard.wav" );
    wav_wall = theme_load_sound( "wall.wav" );
    wav_joker = theme_load_sound( "joker.wav" );
    wav_goldshower = theme_load_sound( "goldshower.wav" );
    wav_chaos = theme_load_sound( "chaos.wav" );
    wav_darkness = theme_load_sound( "darkness.wav" );
    wav_ghost = theme_load_sound( "ghost.wav" );
    wav_timeadd = theme_load_sound( "timeadd.wav" );
    wav_expl_ball = theme_load_sound( "expl_ball.wav" );
    wav_weak_ball = theme_load_sound( "weak_ball.wav" );
    wav_bonus_magnet = theme_load_sound( "bonus_magnet.wav" );
    wav_malus_magnet = theme_load_sound( "malus_magnet.wav" );
    wav_disable = theme_load_sound( "disable.wav" );
#endif
    /* shine pic */
    shine_pic = theme_load_surf( "shine.png" );
    /* chatroom */
    cr_up = theme_load_surf( "scroll_up.png" );
    cr_down = theme_load_surf( "scroll_down.png" );
    cr_track = theme_load_surf( "scroll_track.png" );
    cr_wallpaper = theme_load_surf( "cr_back.png" );
    SDL_SetColorKey( cr_wallpaper, 0,0 );
    /* frame box */
    fr_hori = theme_load_surf( "fr_hori.png" );
    fr_vert = theme_load_surf( "fr_vert.png" );
    fr_luc = theme_load_surf( "fr_luc.png" );
    fr_llc = theme_load_surf( "fr_llc.png" );
    fr_ruc = theme_load_surf( "fr_ruc.png" );
    fr_rlc = theme_load_surf( "fr_rlc.png" );
    /* frame */
    theme_load_frame();
    /* wall */
    sprintf( theme_path, "%s/floor.png", theme_dir );
    if ( stat( theme_path, &filestat ) == -1 ) {
        /* build default floor */
        wall_pic = stk_surface_create( 
            SDL_SWSURFACE, stk_display->w - 2 * BRICK_WIDTH, 
            BRICK_HEIGHT );
        /* bricks must have been loaded at this point! */
        for ( i = 0; i < MAP_WIDTH - 2; i++ )
            stk_surface_blit( brick_pic, 0, 0,
                BRICK_WIDTH, BRICK_HEIGHT, 
                wall_pic, i * BRICK_WIDTH, 0 );
    }
    else {
        /* load floor */
        wall_pic = theme_load_surf( "floor.png" );
    }
    /* backgrounds */
    theme_load_bkgnds();
    /* build nuke bkgnd */
    nuke_bkgnd = stk_surface_create( SDL_SWSURFACE,
        stk_display->w, stk_display->h );
    surf = stk_surface_load( SDL_SWSURFACE, "nukeback.png" );
    stk_surface_apply_wallpaper( nuke_bkgnd, 0,0,-1,-1,
        surf, 128 );
    stk_surface_free( &surf );
    stk_surface_gray( nuke_bkgnd, 0,0,-1,-1, 0 );
    /* manager */
    mbkgnd = theme_load_surf( "menuback.png" );
    SDL_SetColorKey( mbkgnd, 0, 0 );
    mfont = theme_load_font_fixed( "f_small_yellow.png", 32, 96, 8 );
    mhfont = theme_load_font_fixed( "f_white.png", 32, 96, 10 );
    mcfont = theme_load_font_fixed( "f_yellow.png", 32, 96, 10 );
#ifdef AUDIO_ENABLED
    wav_menu_click = theme_load_sound( "menu_click.wav" );
    wav_menu_motion = theme_load_sound( "menu_motion.wav" );
#endif
    /* add version to background */
    mfont->align = STK_FONT_ALIGN_RIGHT | STK_FONT_ALIGN_BOTTOM;
    sprintf( aux, "v%s", VERSION );
    stk_font_write( mfont, mbkgnd, mbkgnd->w - 4, stk_display->h - 4 - mfont->height, STK_OPAQUE, aux );
    stk_font_write( mfont, mbkgnd, mbkgnd->w - 4, stk_display->h - 4, STK_OPAQUE, "http://lgames.sf.net" );
    /* charts */
    /* load resources */
    cfont = theme_load_font_fixed( "f_small_yellow.png", 32, 96, 8 );
    chfont = theme_load_font_fixed( "f_small_white.png", 32, 96, 8 );
    ccfont = theme_load_font_fixed( "f_yellow.png", 32, 96, 10 );
    /* warp picture */
    warp_pic = theme_load_surf( "warp.png" );
}
Exemplo n.º 5
0
int main(int argc, char *argv[])
{
    int result = ACTION_NONE;
    int leave = 0;
    char *editor_file = 0;
    char path[512];
    SDL_Surface *loading;
#ifdef __unix__
    gid_t realgid;

    hi_dir_chart_file = fopen(HI_DIR "/" CHART_FILE_NAME, "r+");

    /* This is where we drop our setuid/setgid privileges.
     */
    realgid = getgid();
    if (setresgid(-1, realgid, realgid) != 0) {
        perror("Could not drop setgid privileges.  Aborting.");
        exit(1);
    }
#endif
   
/* i18n */
#ifdef ENABLE_NLS
    setlocale (LC_ALL, "");
    bindtextdomain (PACKAGE, LOCALEDIR);
    textdomain (PACKAGE);
#endif
    
#ifdef _WIN32    
    /* Get Windows to open files in binary mode instead of default text mode */
    _fmode = _O_BINARY;
#endif    
    
    /* lbreakout info */
    printf( "LBreakout2 %s\nCopyright 2001-2010 Michael Speck\nPublished under GNU GPL\n---\n", VERSION );
    printf( "Looking up data in: %s\n", SRC_DIR );
    printf( "Looking up highscores in: %s\n", HI_DIR );
    printf( "Looking up custom levels in: %s/%s/lbreakout2-levels\n", (getenv( "HOME" )?getenv( "HOME" ):"."), CONFIG_DIR_NAME );
#ifndef AUDIO_ENABLED
    printf( "Compiled without sound and music\n" );
#endif

    set_random_seed(); /* set random seed */

    config_load();
    
    stk_init( SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER | SDL_INIT_JOYSTICK );
    if ( config.fullscreen )
        stk_display_open( SDL_SWSURFACE | SDL_FULLSCREEN, 640, 480, 16 );
    else
        stk_display_open( SDL_SWSURFACE, 640, 480, 16 );
    stk_audio_open( 0,0,0,config.audio_buffer_size );
    SDL_WM_SetCaption( "LBreakout2", 0 );
    SDL_SetEventFilter( event_filter );
    stk_audio_enable_sound( config.sound );
    stk_audio_set_sound_volume( config.volume * 16 );
    
    /* load a little loading pic */
    stk_surface_set_path( SRC_DIR "/gfx" );
    loading = stk_surface_load( SDL_SWSURFACE, "loading.png" );
    stk_surface_blit( loading, 0,0,-1,-1, stk_display, 
                      (stk_display->w-loading->w)/2, 
                      (stk_display->h-loading->h)/2 );
    stk_display_update( STK_UPDATE_ALL );
    
    /* load the GUI graphics from SRC_DIR/gui_theme */
    stk_surface_set_path( SRC_DIR );
    stk_audio_set_path( SRC_DIR );
    gui_init( "gui_theme" );

    stk_surface_set_path( SRC_DIR "/gfx" );
    stk_audio_set_path( SRC_DIR "/sounds" );
    
    /* load resources */
    /* for simplicity all functions are kept but anything
     * that is now themeable is loaded in
     * theme_load instead of the original function
     * (deleting resources works analouge)
     */
    theme_get_list();
    if ( config.theme_count != theme_count ) {
        if ( config.theme_id >= theme_count )
            config.theme_id = 0;
        config.theme_count = theme_count;
    }
    theme_load( theme_names[config.theme_id] );
    /* old functions still with initialzations of
     * lists or variables 
     */
    client_game_create();
    hint_load_res();
    chart_load();
    manager_create();
    client_create();
    exp_load();
    editor_create();
	help_create();
    /* run game */
    manager_fade( STK_FADE_IN );
    while( !leave && !stk_quit_request ) {
        result = manager_run();
        switch( result ) {
            case ACTION_QUIT: leave = 1; break;
            case ACTION_RESUME_0:
                manager_fade( STK_FADE_OUT );
		if ( client_game_resume_local( 0 ) )
			client_game_run();
                client_game_finalize();
                manager_fade( STK_FADE_IN );
                break;
            case ACTION_PLAY_LBR:
                manager_fade( STK_FADE_OUT );
                gameSeed = rand(); /* set random seed for next FREAKOUT/BonusLevels */
		if ( client_game_init_local( "LBreakout2" ) )
			client_game_run();
                client_game_finalize();
                manager_fade( STK_FADE_IN );
                break;
            case ACTION_PLAY_CUSTOM:
                manager_fade( STK_FADE_OUT );
                gameSeed = rand(); /* set random seed for next FREAKOUT/BonusLevels */
                if (gameSeed==0) gameSeed=1; /* not allowed because.... A HACK!!! 0 means to have
                                                no bonus levels to save a parameter */
		if ( client_game_init_local( levelset_names_local[config.levelset_id_local] ) )
			client_game_run();
                client_game_finalize();
                manager_fade( STK_FADE_IN );
                break;
            case ACTION_EDIT:
                /* new set? */
                if ( strequal( NEW_SET, edit_set ) ) {
                    editor_file = calloc( 16, sizeof( char ) );
                    snprintf( path, sizeof(path)-1, "%s/%s/lbreakout2-levels", getenv( "HOME" )? getenv("HOME"):".", CONFIG_DIR_NAME );
                    if ( !enter_string( font, _("Set Name:"), editor_file, 12 ) || !file_check( path, editor_file, "w" ) ) {
                        free( editor_file );
                        break;
                    }
                    else
                        manager_update_set_list();
                }
                else
                    editor_file = strdup( edit_set );
                if ( editor_init( editor_file ) ) {
                    manager_fade( STK_FADE_OUT );
                    editor_run();
                    editor_clear();
                    manager_fade( STK_FADE_IN );
                }
                free( editor_file ); editor_file = 0;
                break;
			case ACTION_QUICK_HELP:
				help_run();
				break;
            case ACTION_CLIENT:
                manager_fade( STK_FADE_OUT );
                client_run();
                manager_fade( STK_FADE_IN );
                break;
            default: break;
        }
    }
    manager_fade( STK_FADE_OUT );
    /* delete stuff */
    help_delete();
	manager_delete();
	chart_save();
    chart_delete();
    editor_delete();
    exp_delete();
    client_game_delete();
    hint_delete_res();
    theme_delete();
    theme_delete_list();
    stk_surface_free( &loading );
    
    config_save();
    
    if (hi_dir_chart_file)
        fclose(hi_dir_chart_file);

    return EXIT_SUCCESS;
}