int gamemenu() { int i = 0; #ifdef TWOPLAYER int y = 7; while (1) { if (!TWOPLAYER_MODE) { if (term_height >= 23) show_hiscorelist5(5, GAMEMENU_LENGTH+9, 0); } else if (term_height < 23) { setcurs(1, 4); cleartoeol(); y = 5; } i = game_menu(0, 1, y); if (i != 4) break; wclrtobot(window); inputsetup_box(0, 1, 7); } if (!i) { setcurs(1, 4); wclrtobot(window); print_vitetris_ver(19, 4); } #else while (1) { printmenuhelp(19); i = game_menu(i, 1, 7); if (!i) break; clearbox(0, 7, 0, GAMEMENU_LENGTH); if (i != 4 && i < GAMEMENU_LENGTH-1) break; wclrtobot(window); switch (i) { case 4: inputsetup_box(0, 1, 7); i = 0; continue; case GAMEMENU_LENGTH-1: optionsmenu(); break; default: hiscorelist(); } i--; } #endif return i; }
int gamemenu() { int i = 1; #ifdef TWOPLAYER int h; if (!TWOPLAYER_MODE || game->mode & MODE_NETWORK) h = GAMEMENU_LENGTH+4; else { h = 17; while (menuheight < h) newln(2); } while (1) { i = game_menu(0, 1, 4); if (i==4) inputsetup_box(0, 1, 4); else break; } if (!i) clearbox(0, 4, 0, h-4); #else while (1) { i = game_menu(i-1, 1, 4); if (i==4) { setcurs(0, 13); printf("\033[K"); inputsetup_box(0, 1, 4); i = 1; } else if (i < GAMEMENU_LENGTH-1) break; else { clearbox(0, 4, 0, GAMEMENU_LENGTH); if (i == GAMEMENU_LENGTH-1) optionsmenu(); else hiscorelist(); } } #endif return i; }
int gamemenu() { int i = 0; #ifdef TWOPLAYER while (1) { if (!TWOPLAYER_MODE) show_hiscorelist5(5, GAMEMENU_LENGTH+9, 0); i = game_menu(0, 1, 7); if (i != 4) break; clearbox(5, GAMEMENU_LENGTH+9, 0, 5); inputsetup_box(0, 1, 7); } if (!i) clearbox(0, 7, 0, 14); #else while (1) { printmenuhelp(19); i = game_menu(i, 1, 7); if (!i) break; clearbox(0, 7, 0, GAMEMENU_LENGTH); if (i != 4 && i < GAMEMENU_LENGTH-1) break; clearbox(0, 19, 0, 3); switch (i) { case 4: inputsetup_box(0, 1, 7); i = 0; continue; case GAMEMENU_LENGTH-1: optionsmenu(); break; default: hiscorelist(); } i--; } #endif return i; }
/*Ici les fantomes accélèrent de plus en plus * et le but est de tenir le plus longtemps * sans se faire dévorer*/ void survivor(int level, config *cfg) { if(level>=NB_LEVEL) return; int selection, counter=SDL_GetTicks(), tmp=counter, elapsed; SAVE_ENABLE=0; play_menu(level); Pacman pac; Fantome ftm[NB_MAX_GHOSTS]; score_message *msg_list = NULL; Input in; init_pacman(&pac, cfg); init_level(); init_blocks(); load_level(level); pac_restart(&pac); pac.nb_lives=1; init_ghosts(ftm, cfg); memset(&in,0,sizeof(in)); DELAY = 40; while(pac.nb_lives && POINTS) { elapsed = SDL_GetTicks()-tmp; if(elapsed > 10000) { //On accélere les fantomes speed_up(ftm, 1); tmp=SDL_GetTicks(); } UpdateEvents(&in); if(in.quit) //Si clique sur croix { delete(&pac, ftm); exit(EXIT_SUCCESS); } while(in.key[SDLK_ESCAPE]) { selection=game_menu(); if(selection==0) in.key[SDLK_ESCAPE]=0; else if(selection==2) //Retour menu principal { delete(&pac, ftm); return; } } jouer(&pac, ftm, in, cfg, level, &msg_list); } counter = SDL_GetTicks() - counter; fprintf(stderr, "Wouaw tu as tenu %d ms!\n", counter); if(pacmanIsHuman(cfg)) draw_result("data/survivor.txt", counter); delete(&pac, ftm); }
/*Permet de jouer un seul niveau * choisi dans la liste des niveaux * disponibles*/ void one_level(int level, config *cfg) { if(level>=NB_LEVEL) return; int selection; SAVE_ENABLE=0; play_menu(level); Pacman pac; Fantome ftm[NB_MAX_GHOSTS]; score_message *msg_list = NULL; Input in; init_pacman(&pac, cfg); init_level(); init_blocks(); load_level(level); pac_restart(&pac); init_ghosts(ftm, cfg); memset(&in,0,sizeof(in)); DELAY = 40-level; while(POINTS) //Tant que l'on a pas mangé toutes les pac-gommes { UpdateEvents(&in); if(in.quit) //Si clique sur croix { delete(&pac, ftm); exit(EXIT_SUCCESS); } while(in.key[SDLK_ESCAPE]) { selection=game_menu(); if(selection==0) in.key[SDLK_ESCAPE]=0; else if(selection==2) //Retour menu principal { delete(&pac, ftm); return; } } if (in.key[SDLK_w]) POINTS=0; //cheat code for winning!! else if (in.key[SDLK_l] || !(pac.nb_lives)) //cheat code for loosing!! { lost_menu(); delete(&pac, ftm); if(pacmanIsHuman(cfg)) draw_result("data/results.txt", pac.score); return; } jouer(&pac, ftm, in, cfg, level, &msg_list); } win_menu(); if(pacmanIsHuman(cfg)) draw_result("data/results.txt", pac.score); delete(&pac, ftm); }
void events2(t_window *w, t_music *m, t_list *l, t_text *t, t_font *f, t_image *img) { int next; SDL_Event event; next = 1; refresh(w, l, t, f, img); while (next) { SDL_WaitEvent(&event); switch(event.type) { case SDL_QUIT: clean_exit(w, m, l, t); break; case SDL_MOUSEBUTTONUP: if (event.button.button == SDL_BUTTON_LEFT) pars_scene(w, m, l, t, f); break; case SDL_KEYDOWN: switch (event.key.keysym.sym) { case SDLK_RETURN: pars_scene(w, m, l, t, f); break; case SDLK_SPACE: pars_scene(w, m, l, t, f); break; case SDLK_LEFT: history_navigation(w, m, l, t, f, img); break; case SDLK_m: music_pause(m); break; case SDLK_ESCAPE: game_menu(w, m, l, t, f, img); break; default: break; } break; default: break; } } }
int main(int argc, char* args[]) { bool cont=true; //Initialize if( init() == false ) { return 1; } Window my; my.toggle_fullscreen(); wel_come(); ///WELCOME SCREEN FUNCTION CALL int opt; while(cont) { opt=game_menu(); ///GAME MENU FUNCTION CALL switch(opt) { case 1: play(); ///GAME LOOP break; case 2: ///OPTIONS break; case 3: ///HIGHSCORES break; case 4: ///INSTRUCTIONS break; case 5: ///CREDITS break; case 6: ///QUIT FROM PROGRAM cont=false; break; default: break; } } clean_up(); ///FREES THE MEMORY return 0; }
static boolean game_key(context *ctx, int *key) { struct game_context *game = (struct game_context *)ctx; struct config_info *conf = get_config(); struct world *mzx_world = ctx->world; struct board *cur_board = mzx_world->current_board; char keylbl[] = "KEY?"; int key_status = get_key_status(keycode_internal_wrt_numlock, *key); boolean exit_status = get_exit_status(); boolean confirm_exit = false; if(*key && !exit_status) { // Get the char for the KEY? labels. If there is no relevant unicode // keypress, we want to use the regular code instead. int key_unicode = get_key(keycode_unicode); int key_char = *key; if(key_unicode > 0 && key_unicode < 256) key_char = key_unicode; if(key_char) { if(key_char < 256) { // Send the KEY? label. // Values over 256 have no meaning here. keylbl[3] = key_char; send_robot_all_def(mzx_world, keylbl); } // In pre-port MZX versions key was a board counter if(mzx_world->version < VERSION_PORT) { char keych = toupper(key_char); // <2.60 it only supported 1-9 and A-Z // This is difficult to version check, so apply it to <2.62 if(mzx_world->version >= V262 || (keych >= 'A' && keych <= 'Z') || (keych >= '1' && keych <= '9')) { cur_board->last_key = keych; } } } switch(*key) { case IKEY_F3: { // Save game if(!mzx_world->dead && player_can_save(mzx_world)) { char save_game[MAX_PATH]; strcpy(save_game, curr_sav); if(!new_file(mzx_world, save_ext, ".sav", save_game, "Save game", 1)) { strcpy(curr_sav, save_game); save_world(mzx_world, curr_sav, true, MZX_VERSION); } } return true; } case IKEY_F4: { // ALT+F4 - do nothing. if(get_alt_status(keycode_internal)) break; // Restore saved game if(mzx_world->version < V282 || get_counter(mzx_world, "LOAD_MENU", 0)) { load_savegame_selection(game); } return true; } case IKEY_F5: case IKEY_INSERT: { // Change bomb type if(!mzx_world->dead) player_switch_bomb_type(mzx_world); return true; } // Toggle debug mode case IKEY_F6: { if(edit_world && mzx_world->editing) mzx_world->debug_mode = !(mzx_world->debug_mode); return true; } // Cheat case IKEY_F7: { if(game->allow_cheats || mzx_world->editing) player_cheat_give_all(mzx_world); return true; } // Cheat More case IKEY_F8: { if(game->allow_cheats || mzx_world->editing) player_cheat_zap(mzx_world); return true; } // Quick save case IKEY_F9: { if(!mzx_world->dead) { if(player_can_save(mzx_world)) save_world(mzx_world, curr_sav, true, MZX_VERSION); } return true; } // Quick load saved game case IKEY_F10: { if(mzx_world->version < V282 || get_counter(mzx_world, "LOAD_MENU", 0)) { struct stat file_info; if(!stat(curr_sav, &file_info)) load_savegame(game, curr_sav); } return true; } case IKEY_F11: { if(mzx_world->editing) { // Breakpoint editor if(get_alt_status(keycode_internal)) { if(debug_robot_config) debug_robot_config(mzx_world); } // Counter debugger else { if(debug_counters) debug_counters(ctx); } } return true; } case IKEY_RETURN: { send_robot_all_def(mzx_world, "KeyEnter"); // Ignore if this isn't a fresh press if(key_status != 1) return true; if(mzx_world->version < V260 || get_counter(mzx_world, "ENTER_MENU", 0)) game_menu(ctx); return true; } case IKEY_ESCAPE: { // Ignore if this isn't a fresh press // NOTE: disabled because it breaks the joystick action. //if(key_status != 1) //return true; // ESCAPE_MENU (2.90+) if(mzx_world->version < V290 || get_counter(mzx_world, "ESCAPE_MENU", 0)) confirm_exit = true; break; } } } // Quit if(exit_status || confirm_exit) { // Special behaviour in standalone- only escape exits // ask for confirmation. Exit events instead terminate MegaZeux. if(conf->standalone_mode && !confirm_exit) { core_full_exit(ctx); } else { if(!confirm(mzx_world, "Quit playing- Are you sure?")) destroy_context(ctx); } return true; } return false; }
/*Permet de jouer tout les niveaux * à la suite*/ void campagne(config *cfg, int cmp_level) { int selection=0, level; SAVE_ENABLE=1; Pacman pac; Fantome ftm[NB_MAX_GHOSTS]; score_message *msg_list = NULL; Input in; init_pacman(&pac, cfg); init_blocks(); memset(&in,0,sizeof(in)); while(cmp_level < CAMPAGNE_LEVEL) { level=0; while(strcmp(LEVEL_FILE[level], CAMPAGNE[cmp_level]) && level < NB_LEVEL) { level++; } DELAY = 40-cmp_level; play_menu(cmp_level); init_level(); load_level(level); pac_restart(&pac); init_ghosts(ftm, cfg); while(POINTS) //Tant que l'on a pas mangé toutes les pac-gommes { UpdateEvents(&in); if(in.quit) //Si clique sur croix { delete(&pac, ftm); exit(EXIT_SUCCESS); } while(in.key[SDLK_ESCAPE]) { selection=game_menu(); if(selection==0) in.key[SDLK_ESCAPE]=0; else if(selection==1) save_game(cmp_level); else if(selection==2) //Retour menu principal { delete(&pac, ftm); return; } } if (in.key[SDLK_w]) { in.key[SDLK_w]=0; POINTS=0; //cheat code for winning!! } else if (in.key[SDLK_l] || !(pac.nb_lives)) //cheat code for loosing!! { lost_menu(); draw_result("data/results.txt", pac.score); delete(&pac, ftm); return; } jouer(&pac, ftm, in, cfg, cmp_level, &msg_list); } cmp_level++; win_menu(); } draw_result("data/results.txt", pac.score); delete(&pac, ftm); }
int CBGA::main(int argc, char **argv) { #ifdef _DEBUG // создаём консоль CL_ConsoleWindow console("BGA Console"); console.redirect_stdio(); #endif try { //инициализация CL_SetupCore::init(); CL_SetupDisplay::init(); CL_SetupGL::init(); CL_SetupNetwork::init(); CL_SetupSound::init(); CL_SetupVorbis::init(); CL_SoundOutput output(44100); LOG<<"Bad Guys on Autos\nВерсия "<<VERSION<<endl; LOG<<LOG.Time()<<"Старт игры\n"; LOG<<"Установка графического режима...\n"; //окно #ifdef _DEBUG CL_DisplayWindow window("BGA v"VERSION, SCR_W, SCR_H, false, true); #else CL_DisplayWindow window("BGA v"VERSION, SCR_W, SCR_H, true); #endif window.hide_cursor(); //получаем текущий режим DEVMODE cur_devmode; EnumDisplaySettings(0, ENUM_CURRENT_SETTINGS, &cur_devmode); LOG<<"Установлен графический режим "<<cur_devmode.dmPelsWidth<<"x"<<cur_devmode.dmPelsHeight<<"x"; LOG<<cur_devmode.dmBitsPerPel<<"@"<<cur_devmode.dmDisplayFrequency<<endl; //контекст CL_GraphicContext *gc = window.get_gc(); srand(CL_System::get_time()); CGame Game; #ifndef _DEBUG Intro(Game.GetResman()); CGameMenu game_menu(&Game); game_menu.Intro(); game_menu.MainLoop(); #else //CGameMenu game_menu(&Game); //game_menu.MainLoop(); Game.SetLimits(3,0); Game.SetLocalNames("Tosha","Hitman","Crash","Doom"); Game.NewGame(BGA_GAME_DEATHMATCH,2,"platetown"); Game.MainLoop(); #endif LOG<<LOG.Time()<<"Завершение игры\n"; //деинициализация CL_SetupVorbis::deinit(); CL_SetupSound::deinit(); CL_SetupNetwork::deinit(); CL_SetupCore::deinit(); CL_SetupDisplay::deinit(); CL_SetupGL::deinit(); } catch (CL_Error err) { std::cout << "Exception caught: " << err.message.c_str() << std::endl; LOG<<endl<<LOG.Time()<<"ОШИБКА! "<< err.message.c_str() <<endl; #ifdef _DEBUG // Display console close message and wait for a key console.display_close_message(); #endif } catch (...) { LOG<<endl<<LOG.Time()<<"ОШИБКА! Необработанное исключение!"<<endl; } LOG<<"\n\n\nThe time of Bad Guys will come soon..."; //console.display_close_message(); return 0; }
bool Game::game_loop() { graphics->apply_surface(0, 0, background, screen); graphics->refresh_whole_screen(); bool exit = false; winner = NULL; loser = NULL; while((!exit) && (!winner)) { /* Input handling */ control->updateState(); if ((control->isPressed(KEY_BACK)) && (game_menu(this))) { exit = true; } else { if (players[0]->type != COMPUTER) players[0]->handle_input(); else players[0]->move(balls); if (players[1]->type != COMPUTER) players[1]->handle_input(); else players[1]->move(balls); /* Collision detection */ physics->checkPlayerCollisions(&balls, players, 2); physics->checkBallCollisions(&balls); //printf("%f %f\n", balls[0]->v.module(), balls[1]->v.module()); /* Screen redraw */ graphics->apply_surface(0, 0, background, screen); draw_player_stats(); // Players players[0]->show(); players[1]->show(); /* Checking if there is a winner and drawing balls */ for (Uint8 i=0; i<balls.size(); i++) { if ((balls[i]->p.x + balls[i]->r) <= 0) { // Left players[0]->hurt(); players[0]->combo = CMB_NULL; if (players[0]->life <= 0) { winner = players[1]; loser = players[0]; } graphics->refresh_whole_screen(false); if (i == 0) { balls[i]->resetPosition(); balls[i]->setVelocity(-5, 0); balls[i]->birth(); } else { delete balls[i]; balls.erase(balls.begin()+i); } } else if ((balls[i]->p.x - balls[i]->r) >= SCREEN_WIDTH) { // Right players[1]->hurt(); players[1]->combo = CMB_NULL; if (players[1]->life <= 0) { winner = players[0]; loser = players[1]; } graphics->refresh_whole_screen(false); if (i == 0) { balls[i]->resetPosition(); balls[i]->setVelocity(5, 0); balls[i]->birth(); } else { delete balls[i]; balls.erase(balls.begin()+i); } } else balls[i]->show(); } framerate->tic(); graphics->refresh_screen(); framerate->delay(); } } for (Uint8 i=0; i<balls.size(); i++) { delete balls[i]; } return exit; }