void tetris_exit() { run_thread = 0; pthread_join(t_tetris, NULL); free(t_tetris); pthread_mutex_destroy(tetris_draw_mutex); tetris_clear(1); bootmgr_display->bg_img = 1; bootmgr_set_lines_count(0); bootmgr_set_fills_count(0); bootmgr_phase = BOOTMGR_MAIN; bootmgr_draw(); }
void tetris_key(int key) { switch(key) { case KEY_VOLUMEDOWN: { if(state & TETRIS_PAUSED) { bootmgr_erase_text(14); bootmgr_erase_text(15); bootmgr_erase_fill(1); state &= ~(TETRIS_PAUSED); state |= TETRIS_STARTED; } else if(state & TETRIS_STARTED) { bootmgr_print_fill(11, 14*ISO_CHAR_HEIGHT, 219, 32, BLACK, 1); bootmgr_printf(10+((220 - 6*8)/2), 14, WHITE, "Paused"); bootmgr_printf(10+((220 - 25*8)/2), 15, WHITE, "Press \"VolDown\" to resume"); bootmgr_draw_fills(); bootmgr_draw_text(); fb_update(&fb); state &= ~(TETRIS_STARTED); state |= TETRIS_PAUSED; } break; } case KEY_VOLUMEUP: tetris_exit(); bootmgr_set_time_thread(1); break; case KEY_HOME: { if(!(state & TETRIS_STARTED)) { if(state & TETRIS_FINISHED) { tetris_clear(0); tetris_set_defaults(); bootmgr_erase_text(14); bootmgr_erase_fill(1); tetris_print_score(); } bootmgr_erase_text(15); state = (TETRIS_STARTED | TETRIS_SPAWN_NEW); } else { pthread_mutex_lock(tetris_draw_mutex); tetris_move_piece(TETRIS_DOWN_FAST); tetris_draw(0); pthread_mutex_unlock(tetris_draw_mutex); } break; } case KEY_BACK: { if(state & TETRIS_STARTED) { pthread_mutex_lock(tetris_draw_mutex); tetris_rotate_piece(); tetris_draw(0); pthread_mutex_unlock(tetris_draw_mutex); } break; } case KEY_MENU: case KEY_SEARCH: { if(state & TETRIS_STARTED) { pthread_mutex_lock(tetris_draw_mutex); if(tetris_can_move_piece(key == KEY_MENU ? TETRIS_LEFT : TETRIS_RIGHT)) tetris_move_piece(key == KEY_MENU ? TETRIS_LEFT : TETRIS_RIGHT); tetris_draw(0); pthread_mutex_unlock(tetris_draw_mutex); } break; } } }
int main(int argc, char *argv[]) { int result = ACTION_NONE; int leave = 0; /* i18n */ #ifdef ENABLE_NLS setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); #endif /* ltris info */ printf( "LTris %s\nCopyright 2002-2005 Michael Speck\nPublished under GNU GPL\n---\n", VERSION ); printf( "Looking up data in: %s\n", SRC_DIR ); #ifndef SOUND printf( "Compiled without sound and music\n" ); #endif set_random_seed(); /* set random seed */ /* game ids - not translated to be fixed independant of language */ strcpy(gametype_ids[0],"demo"); strcpy(gametype_ids[1],"classic"); strcpy(gametype_ids[2],"figures"); strcpy(gametype_ids[3],"vshuman"); strcpy(gametype_ids[4],"vscpu"); strcpy(gametype_ids[5],"vshumanhuman"); strcpy(gametype_ids[6],"vshumancpu"); strcpy(gametype_ids[7],"vscpucpu"); /* game names - translated for display */ strcpy(gametype_names[0],_("Demo")); strcpy(gametype_names[1],_("Classic")); strcpy(gametype_names[2],_("Figures")); strcpy(gametype_names[3],_("Vs Human")); strcpy(gametype_names[4],_("Vs CPU")); strcpy(gametype_names[5],_("Vs Human&Human")); strcpy(gametype_names[6],_("Vs Human&CPU")); strcpy(gametype_names[7],_("Vs CPU&CPU")); config_load(); init_sdl( SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER ); set_video_mode( std_video_mode( config.fullscreen ) ); SDL_WM_SetCaption( "LTris", 0 ); sdl.fade = config.fade; SDL_SetEventFilter( event_filter ); #ifdef SOUND audio_open(); sound_enable( config.sound ); sound_volume( config.volume * 16 ); #endif /* create */ hint_load_res(); manager_create(); tetris_create(); chart_load(); /* run game */ manager_fade( FADE_IN ); while( !leave && !term_game ) { result = manager_run(); switch( result ) { case ACTION_QUIT: leave = 1; break; case ACTION_MAKE_STAT: manager_fade( FADE_OUT ); tetris_make_stat(); manager_fade( FADE_IN ); break; case ACTION_PLAY: manager_fade( FADE_OUT ); if ( tetris_init() ) { tetris_run(); tetris_clear(); } manager_fade( FADE_IN ); break; default: break; } } manager_fade( FADE_OUT ); /* delete stuff */ tetris_delete(); manager_delete(); chart_save(); chart_delete(); hint_delete_res(); #ifdef SOUND audio_close(); #endif config_save(); return EXIT_SUCCESS; }