int progress_play(struct level *l) { if (l && (level_opened(l) || config_cheat())) { level = l; next = NULL; status = GAME_NONE; coins = 0; timer = 0; goal = goal_i = level_goal(level); if (same_goal_e) same_goal_e = 0; else goal_e = (mode != MODE_CHALLENGE && level_completed(level) && config_get_d(CONFIG_LOCK_GOALS) == 0) || goal == 0; prev = curr; time_rank = RANK_LAST; goal_rank = RANK_LAST; coin_rank = RANK_LAST; return init_level(); } return 0; }
/* create a one level game context for testing a level */ int client_game_init_testing( Level *level ) { local_game = game_create( GT_LOCAL, config.diff, 100 ); game_set_current( local_game ); game_set_convex_paddle( config.convex ); game_set_ball_auto_return( !config.return_on_click ); game_set_ball_random_angle( config.random_angle ); game_set_ball_accelerated_speed( config.maxballspeed_float ); local_game->localServerGame = 1; game = game_create( GT_LOCAL, config.diff, 100 ); game_set_current( game ); players_clear(); player_add( config.player_names[0], game->diff->lives, level ); cur_player = players_get_first(); bkgnd_ids[0] = 0; init_level( cur_player, PADDLE_BOTTOM ); client_state = CS_NONE; set_state( CS_PLAY ); return 1; }
bool load_level(level_t *l, FILE *f) { int y, x; char str[5]; printf("starting load_level\n"); fread(str, sizeof(char), 5, f); if(strcmp(str, "LEVEL")) { fprintf(stderr, "DEBUG: %s:%d - LEVEL header not where it's supposed to be!\n", __FILE__, __LINE__); return false; } fread(&l->xsize, sizeof(short), 1, f); fread(&l->ysize, sizeof(short), 1, f); if(!l->c) init_level(l); for(y = 0; y < l->ysize; y++) for(x = 0; x < l->xsize; x++) if(!load_cell(&l->c[y][x], l, f)) { fprintf(stderr, "DEBUG: %s:%d - load_cell failed!\n", __FILE__, __LINE__); return false; } printf("loaded level!\n"); return true; }
int main (int argc, char *argv[]) { int rval, r; /* Parse command line arguments */ init_startup_options (); if (argc > 1) { for (r = 1; r < argc; r++) { if (strcmp (argv[r], "--help") == 0) { print_help (); return 0; } else if (strcmp (argv[r], "--version") == 0) show_version (); else if ((r = parse_argument (r, argc, argv)) == 0) return 0; } } /* Check if luola's home directory exists and create it if necessary */ check_homedir (); /* Seed the random number generator */ srand (time (NULL)); /* Initialize */ init_sdl (); init_video (); if (luola_options.sounds) init_audio (); if(init_font()) return 1; if(load_data()) return 1; scan_levels(0); scan_levels(1); if (game_settings.levels == NULL) no_levels_found (); init_level(); init_hotseat(); if (luola_options.mbg_anim) init_demos (); /* Set sound effect volume */ audio_setsndvolume(game_settings.sound_vol); /* Enable key repeat (useful in menus. Will be disabled during game) */ SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY,SDL_DEFAULT_REPEAT_INTERVAL); /* Enter game loop */ while (1) { /* Intro screen */ rval = game_menu_screen (); if (rval == INTRO_RVAL_EXIT) break; /* Play ! */ if (rval == INTRO_RVAL_STARTGAME) hotseat_game (); } return 0; }
void keyboard(unsigned char key, int x, int y) { switch(key) { case 27: exit(0); break; case ' ': if(failed) { failed=0; level=0; score=0; init_level(); } else { finish_level(); if(!failed) init_level(); } break; } }
int second_tree(int inU[7], int inS[7], int inZ[7], struct node **head, solution *US) { int late_index[7], outZ[7]; //zero case variables int i[7]; //index variable int u[7], v[7], s[7]; getLateIndices(late_index, inZ, 17); int matrix[7][4]; solution *VS = malloc(sizeof(solution)); init_level(VS); int branches = 0; int vc = 0, l2c = 0, pc = 0; for (i[0] = 0; i[0] < 5; i[0]++) {//open loop 0 tree2(0, i[0], matrix, inZ, outZ, inU, inS, u, s, v); for (i[1] = 0; i[1] < 5; i[1]++) {//open loop 1 tree2(1, i[1], matrix, inZ, outZ, inU, inS, u, s, v); for (i[2] = 0; i[2] < 5; i[2]++) {//open loop 2 tree2(2, i[2], matrix, inZ, outZ, inU, inS, u, s, v); for (i[3] = 0; i[3] < 5; i[3]++) {//open loop 3 tree2(3, i[3], matrix, inZ, outZ, inU, inS, u, s, v); for (i[4] = 0; i[4] < late_index[4]; i[4]++) {//open loop 3 tree2(4, i[4], matrix, inZ, outZ, inU, inS, u, s, v); for (i[5] = getLowerIndex(i[4], inZ, 5); i[5] < late_index[5]; i[5]++) {//open loop 3 tree2(5, i[5], matrix, inZ, outZ, inU, inS, u, s, v); for (i[6] = getLowerIndex(i[5], inZ, 6); i[6] < late_index[6]; i[6]++) {//open loop 3 tree2(6, i[6], matrix, inZ, outZ, inU, inS, u, s, v); vc = vCheck(v); l2c = levelTWOcheck(matrix); if (l2c) { pc = prunecheck(US, VS, matrix, 1); if (pc) { branches++; third_tree(u, v, s, outZ, VS, US, head); } } }//close loop 6 }//close loop 5 }//close loop 4 }//close loop 3 }//close loop 2 }//close loop 1 }//close loop 0 free(VS); return branches; }
void start_level(int l) { init_level(l); /* Initalize the snake */ game_state = SNAKE_PLAYING; if(global_snake.score < 60) game_speed = start_speed + 10; nibble.active = 0; nibble.x = 0; nibble.y = 0; draw_score(); }
/*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); }
/* init next network game round by displaying a message and switching * to GET_READY. */ void init_next_round( void ) { game_round++; set_state( CS_GET_READY ); init_level( cur_player, cur_player->paddle_id ); display_text( font, "***** Round %i *****###You control the %s paddle in this level!#" "To fire a ball keep the mouse button PRESSED.#Don't just click.###" "Press any key when you are ready...###(You can pause the game with 'p' any time.)" "###NOTE: Due to latency, bonuses on the server are closer than they " "appear! I'll try to work on that.", game_round, cur_player->paddle_id==0?"BOTTOM":"TOP" ); }
/*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); }
int main(int argc, char **argv) { glutInitDisplayMode(GLUT_RGBA|GLUT_DOUBLE); glutInit(&argc, argv); glutCreateWindow("redgate"); glutKeyboardFunc(&keyboard); glutDisplayFunc(&display); glutIdleFunc(&idle); init_level(); level=0; score=0; failed=0; glutMainLoop(); }
/** * Creates the game world and sets up initial contents. */ World::World(const CL_DisplayWindow &display_window) : ApplicationModule(display_window) { DEBUG_MSG("World::World(CL_DisplayWindow &) - Called.") //Set object pointers to null music = 0x0; active_scene = 0x0; plot = 0x0; mouse_dragging = false; left_mouse_button_down = false; //Get the resource manager rm = CL_ResourceManager("data/game-resources.xml"); //Setup sound output sound_output = CL_SoundOutput(44100); //Load objects into the world. init_level(); }
/* create local game context and initiate game state * as given from slot 'slot_id'. */ int client_game_resume_local( int slot_id ) { int i; GameSlot gs; /* load saved game */ if ( !slot_load( slot_id, &gs ) ) return 0; /* FIXME: config settings are overwritten for this */ config.diff = gs.diff; config.player_count = gs.player_count; for ( i = 0; i < config.player_count; i++ ) strcpy( config.player_names[i], gs.player_names[i] ); gameSeed = gs.gameSeed; /* create local game where all players have full lives */ if ( !client_game_init_local( gs.setname ) ) return 0; /* re-initiate players */ players_clear(); for ( i = 0; i < config.player_count; i++ ) { /* name + lives */ player_add( config.player_names[i], gs.player_lives[i], levelset_get_first( game_set ) ); /* level */ player_init_level( &players[i], game_set->levels[gs.player_cur_level_id[i]], gs.player_cur_level_id[i] ); /* score */ players[i].stats.total_score = gs.player_scores[i]; } cur_player = players_set_current( gs.cur_player ); /* init first level */ init_level( cur_player, PADDLE_BOTTOM ); return 1; }
void load_levels(t_level *levels[]) { int fd[N_LEVELS]; int i; char *path; char *level_index; i = 0; if (N_LEVELS == 0) handle_errors(__func__, "N_LEVELS is null!", TRUE); while (i < N_LEVELS) { level_index = ft_itoa(i); path = ft_strjoin(LEVEL_PATH, level_index); ft_printf("loading %s ..\n", path); if ((fd[i] = open(path, O_RDONLY)) == -1) handle_errors(__func__, "level not found!", TRUE); levels[i] = init_level(); parse_level(fd[i], levels[i]); ft_strdel(&path); ft_strdel(&level_index); i++; } }
void game_loop(void) { int playing = 1; counter = 0; do { if (player[0].link_toggle_delay > 0) player[0].link_toggle_delay --; if (player[1].link_toggle_delay > 0) player[1].link_toggle_delay --; reset_lights(); get_input(); enact_commands(); run_actors(); run_bullets(); // should be between actors and enemies for orbitals to work arena.waver_on_level = 0; run_clouds(); // run_stars(); run_enemies(); run_pickups(); play_beats(); if (counter % 35 == 0) run_level(); if (arena.game_over > 0) { arena.game_over --; if (arena.game_over == 1) { playing = 0; kill_gameover_loop(); } if (arena.game_over == 120) play_gameover_loop(1000); } else { if (arena.new_level_sign > 0) arena.new_level_sign --; if (arena.time_left > 0) { if (game.type != GAME_DUEL || (game.duel_mode != DUEL_10_POINTS && game.duel_mode != DUEL_30_POINTS)) arena.time_left --; if (game.type == GAME_TIME_ATTACK || game.type == GAME_TIME_ATTACK_COOP) game.ta_total_time ++; } else { if (game.type == GAME_TIME_ATTACK || game.type == GAME_TIME_ATTACK_COOP) { arena.game_over = 132; hurt_actor(0, 0, 100000); hurt_actor(1, 0, 100000); // it's okay to call hurt_actor on non-existent actors. } if (game.type == GAME_DUEL) { if (arena.game_over == 0) { arena.game_over = 132; game.duel_winner = -1; if (player[0].duel_score > player[1].duel_score) game.duel_winner = 0; if (player[1].duel_score > player[0].duel_score) game.duel_winner = 1; } } else { if (arena.level_finished == 1) { if (arena.level == 15) { arena.level = 16; // play_gameover_loop(2200); // play_wavf(NWAV_SWARBLE, 1500); playing = 0; break; } init_level(); if (actor[0].in_play == 1) actor_new_level(0); if (actor[1].in_play == 1) actor_new_level(1); ticked = 0; } else { if (arena.hostile == 0) { make_arena_hostile(); } else { if (arena.hostile < 10000) arena.hostile ++; run_hostile_level(); } } } } /* if (arena.time_left == 334) { send_message(0, "Hurry} Up}!", STYLE_HURRY); send_message(1, "Hurry} Up}!", STYLE_HURRY); }*/ if (arena.time_left == 330 && (game.type != GAME_DUEL || (game.duel_mode != DUEL_10_POINTS && game.duel_mode != DUEL_30_POINTS))) play_wavf(NWAV_ALARM, 900); if (arena.hostile == 10 || arena.hostile == 40 || arena.hostile == 70) play_wavf(NWAV_ALARM, 700); } if (ticked == 0) { run_display(); framecounter++; } init_effects(); slacktime = 0; do { slacktime ++; } while(ticked == 0); ticked --; counter ++; if (counter % 32 == 0) { long_slacktime_store = long_slacktime; long_slacktime = 0; } long_slacktime += slacktime / 100; if (key [KEY_ESC]) quit_query(); } while(playing == 1); }
void begin_game(void) { int i; counter = 0; init_structs_etc(); for (i = 0; i < NO_ACTORS; i ++) { actor[i].in_play = 0; } player[0].score = 0; player[1].score = 0; if (game.type == GAME_SINGLE || game.type == GAME_TIME_ATTACK) { game.users = 1; actor[0].in_play = 0; player[game.single_player].actor_controlled = 0; // player[0].ships_left = 3; game.ships_left = 3; actor[0].controller = game.single_player; init_actor(0, player[game.single_player].ship); //ACTORTYPE_SHIP); } if (game.type == GAME_COOP || game.type == GAME_DUEL || game.type == GAME_TIME_ATTACK_COOP) { game.users = 2; actor[0].in_play = 0; player[0].actor_controlled = 0; // player[0].ships_left = 3; actor[0].controller = 0; init_actor(0, player[0].ship); //ACTORTYPE_SHIP); actor[1].in_play = 0; player[1].actor_controlled = 1; // player[1].ships_left = 3; actor[1].controller = 1; init_actor(1, player[1].ship); //ACTORTYPE_SHIP); game.ships_left = 6; } init_bullets(); init_clouds(); // init_stars(); init_enemies(); prepare_display(); game.drag = 0.013;//955;//9999; /* arena.max_x = 894000; arena.max_y = 895000; */ arena.level = 0; game.symbols_given = 0; init_level(); long_slacktime = 0; arena.waver_on_level = 0; }
/** * Hauptfunktion. Wird als erstes aufgerufen. * Struktogramm: * <img src="../../Spielablauf_Struktogramm.png"> * @return gibt 0 zurück */ int main() { init_graphics(); //Function um Grafik Lib zu initialisieren, gibt evtl später mal Errorcode zurück... init_counter(); /** * \todo UART Interrupts funktionieren noch nicht. * Als Workaround wird nun alle 1ms im Timer-Interrupt-Handler die UART1 Schnittstelle gepollt. <br> */ init_uart(); init_genrand(GUI_GetTime()); while(1) { init_game(); init_level(); // warten bis eine taste gedrückt wird, welche den initialen Zustand von snake_direction ändert snake_direction = '?'; while(snake_direction == '?'); // jetzt food zeichnen food = randomize_food(); draw_food(food); enable_interrupts(); do { switch(step_forward(check_initial_state())) { case COLLISION: game_over = 1; disable_interrupts(); //write_byte(score); FFLCR &= ~(1<<7); // DLAB löschen für zugriff while (!(FFLSR & (1<<5))); // Solange UART Busy FFTHR = score; enable_interrupts(); break; case FOOD: score++; if(size >= 15) { // wenn Länge = 15: Level-Up score += 10; level++; init_level(); } food = randomize_food(); disable_interrupts(); draw_food(food); enable_interrupts(); break; case NOTHING: break; } delay(delay_time); } while(game_over != 1); } return 0; }
static void game_init(state_st *state) { log_func_enter; int i; // set up windows state->game = init_gamew(); state->help = init_helpw(); state->inventory = init_inventoryw(); if (!state->game || !state->help || !state->inventory) { endwin(); fprintf(stderr, "%s:%d - %s() - Failed to create window!\n", __FILE__, __LINE__, __func__); log_error("Window creation failed, aborting"); logger_stop(); free_state(state); exit(EXIT_FAILURE); } if (LINES < MIN_ROW || COLS < MIN_COL) { endwin(); fprintf(stderr, "Your terminal is too small. Minimum supported dimensions are %dx%d\n", MIN_COL, MIN_ROW); log_error("Terminal size too small, aborting"); logger_stop(); free_state(state); exit(EXIT_FAILURE); } curs_set(0); if(has_colors() == false) { endwin(); fprintf(stderr, "Your terminal does not support color\n"); log_error("Terminal colors not supported, aborting"); logger_stop(); free_state(state); exit(EXIT_FAILURE); } start_color(); init_colors(); // allow us to catch the arrow keys keypad(state->game, TRUE); // generate random names for items for (i = 0; i < NUM_SCROLLS; ++i) { state->scroll_names[i] = calloc(ITEM_NAME_MAX, sizeof(char)); if (!state->scroll_names[i]) { endwin(); fprintf(stderr, "%s:%d - %s() - out of memory\n", __FILE__, __LINE__, __func__); log_error("malloc failed"); logger_stop(); free_state(state); exit(EXIT_FAILURE); } random_string(state->scroll_names[i], ITEM_NAME_MAX-1); } // randomize ring types rings_init(state); // randomize potion names potions_init(state); // randomize wand names wands_init(state); state->running = true; init_level(state); log_func_exit; }
static void setup(){ render_init(1024, 768, fullscreen); init_level(); init_network(); }
void begin_game(void) { int i; counter = 0; init_structs_etc(); for (i = 0; i < NO_ACTORS; i ++) { actor[i].in_play = 0; } player[0].score = 0; player[1].score = 0; if (game.type == GAME_SINGLE) { game.users = 1; actor[0].in_play = 0; player[game.single_player].actor_controlled = 0; // player[0].ships_left = 3; game.ships_left = 3; actor[0].controller = game.single_player; init_actor(0, player[game.single_player].ship); //ACTORTYPE_SHIP); } else { game.users = 2; actor[0].in_play = 0; player[0].actor_controlled = 0; // player[0].ships_left = 3; actor[0].controller = 0; init_actor(0, player[0].ship); //ACTORTYPE_SHIP); actor[1].in_play = 0; player[1].actor_controlled = 1; // player[1].ships_left = 3; actor[1].controller = 1; init_actor(1, player[1].ship); //ACTORTYPE_SHIP); game.ships_left = 6; } init_bullets(); init_clouds(); init_enemies(); prepare_display(); game.drag = 0.013;//955;//9999; /* arena.max_x = 894000; arena.max_y = 895000; */ arena.level = 0; init_level(); }
/*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); }
void game_loop(void) { int playing = 1; counter = 0; do { if (player[0].link_toggle_delay > 0) player[0].link_toggle_delay --; if (player[1].link_toggle_delay > 0) player[1].link_toggle_delay --; get_input(); enact_commands(); run_actors(); run_bullets(); // should be between actors and enemies for orbitals to work run_clouds(); run_enemies(); run_pickups(); play_ambience(); if (counter % 35 == 0) run_level(); if (arena.game_over > 0) { arena.game_over --; if (arena.game_over == 1) playing = 0; if (arena.game_over == 120) play_sound(WAV_GAME_OVER); } else { if (arena.time_left > 0) { if (game.type != GAME_DUEL || (game.duel_mode != DUEL_10_POINTS && game.duel_mode != DUEL_30_POINTS)) arena.time_left --; } else { if (game.type == GAME_DUEL) { if (arena.game_over == 0) { arena.game_over = 132; game.duel_winner = -1; if (player[0].duel_score > player[1].duel_score) game.duel_winner = 0; if (player[1].duel_score > player[0].duel_score) game.duel_winner = 1; } } else { if (arena.level_finished == 1) { if (arena.level == 16) { arena.level = 17; play_soundf(WAV_LEVEL_END, 1500); playing = 0; break; } init_level(); if (actor[0].in_play == 1) actor_new_level(0); if (actor[1].in_play == 1) actor_new_level(1); ticked = 0; } else { if (arena.hostile == 0) { make_arena_hostile(); } else { if (arena.hostile < 10000) arena.hostile ++; run_hostile_level(); } } } } /* if (arena.time_left == 334) { send_message(0, "Hurry} Up}!", STYLE_HURRY); send_message(1, "Hurry} Up}!", STYLE_HURRY); }*/ if (arena.time_left == 330 && (game.type != GAME_DUEL || (game.duel_mode != DUEL_10_POINTS && game.duel_mode != DUEL_30_POINTS))) play_soundf(WAV_ALARM, 800); if (arena.hostile == 10 || arena.hostile == 40 || arena.hostile == 70) play_sound(WAV_ALARM); } if (ticked == 0) { run_display(); // framecounter++; } slacktime = 0; do { slacktime ++; } while(ticked == 0); ticked --; counter ++; if (key [KEY_ESC]) quit_query(); } while(playing == 1); }
void update_game(struct Anim* anims, struct Image* images, uint32_t dt) { if(pacman_dead == 1) { pacman_dead = isPacmanDying(); if(pacman_dead == 0) { end_kill_pacman(); } return; } level_time += dt; if(bonus_spawned == 1) bonus_timer -= dt; blinky_update(&blinky,&pacman,&my_grid); pinky_update(&pinky,&pacman,&my_grid); inky_update(&inky,&blinky, &pacman,&my_grid); clyde_update(&clyde,&pacman,&my_grid); pacman_update(&pacman,&my_grid); if(frightened_ == 1) { fright_timer -= dt; if(fright_timer < 0) { set_frightened(0); } } else { if(stage < 7) { stage_times[stage] -= dt; if(stage_times[stage] < 0) { if(behaviour_ == 1) set_behaviour(2); else set_behaviour(1); printf("Level: %i Level Time: %i Stage: %i Stage Time: %i\n",effective_level,level_time,stage,stage_times[stage]); printf("Behaviour: %i\n",behaviour_); ++stage; } } } if(get_remaining_dots() == 0) { inc_level(); init_level(); grid_reload(&my_grid); pacman_reset(&pacman); blinky_init(&blinky,anims,images); pinky_init(&pinky,anims,images); inky_init(&inky,anims,images); clyde_init(&clyde,anims,images); } else if(get_remaining_dots() == 170) { spawn_bonus(); bonus_timer = (rand() % 1000) + 9000; } else if(get_remaining_dots() == 70) { spawn_bonus(); bonus_timer = (rand() % 1000) + 9000; } if(bonus_timer <= 0 && bonus_spawned == 1) { kill_bonus(); } }
void init_game(struct Anim* anims, struct Image* images) { int i; grid_load("level.txt", &my_grid); high_score = get_high_score(); pacman_init(&pacman,anims); blinky_init(&blinky,anims,images); pinky_init(&pinky,anims,images); inky_init(&inky,anims,images); clyde_init(&clyde,anims,images); exit_house[0] = &(pinky.exit_house); exit_house[1] = &(inky.exit_house); exit_house[2] = &(clyde.exit_house); { level_bonus[0] = CHERRY_IMG; bonus_points[0] = 100; level_bonus[1] = STRAWBERRY_IMG; bonus_points[1] = 300; level_bonus[2] = level_bonus[3] = ORANGE_IMG; bonus_points[2] = bonus_points[3] = 500; level_bonus[4] = level_bonus[5] = APPLE_IMG; bonus_points[4] = bonus_points[5] = 700; level_bonus[6] = level_bonus[7] = GRAPES_IMG; bonus_points[6] = bonus_points[7] = 1000; level_bonus[8] = level_bonus[9] = GAX_IMG; bonus_points[8] = bonus_points[9] = 2000; level_bonus[10] = level_bonus[11] = BELL_IMG; bonus_points[10] = bonus_points[11] = 3000; for(i = 12; i != 21; ++i) { level_bonus[i] = KEY_IMG; bonus_points[i] = 5000; } } { /* Set the speed of pacman. */ pacman_speed[0] = 0.8f; pacman_speed[1] = pacman_speed[2] = pacman_speed[3] = 0.9f; for(i = 4; i != 20; ++i) pacman_speed[i] = 1.0f; pacman_speed[20] = 0.9f; } { ghost_speed[0] = 0.75f; ghost_speed[1] = ghost_speed[2] = ghost_speed[3] = 0.85f; for(i = 4; i != 21; ++i) ghost_speed[i] = 0.95f; } { tunnel_speed[0] = 0.40f; tunnel_speed[1] = tunnel_speed[2] = tunnel_speed[3] = 0.45f; for(i = 4; i != 21; ++i) tunnel_speed[i] = 0.5f; } { fright_time[0] = 6000; fright_time[1] = 5000; fright_time[2] = 4000; fright_time[3] = 3000; fright_time[4] = 2000; fright_time[5] = 5000; fright_time[6] = 2000; fright_time[7] = 2000; fright_time[8] = 1000; fright_time[9] = 5000; fright_time[10] = 2000; fright_time[11] = 1000; fright_time[12] = 1000; fright_time[13] = 3000; fright_time[14] = 1000; fright_time[15] = 1000; fright_time[17] = 1000; fright_time[16] = fright_time[18] = fright_time[19] = fright_time[20] = 0; } { pacman_fright_speed[0] = 0.9f; pacman_fright_speed[1] = pacman_fright_speed[2] = pacman_fright_speed[3] = 0.95f; for(i = 4; i != 21; ++i) { pacman_fright_speed[i] = 1.0f; } } { ghost_fright_speed[0] = 0.5f; ghost_fright_speed[1] = ghost_fright_speed[2] = ghost_fright_speed[3] = 0.55f; for(i = 4; i != 21; ++i) { ghost_fright_speed[i] = 0.6f; } } { elroy1_speed[0] = 0.8f; elroy1_speed[1] = elroy1_speed[2] = elroy1_speed[3] = 0.9f; for(i = 4; i != 21; ++i) { elroy1_speed[i] = 1.0f; } } { elroy1_dots[0] = 20; elroy1_dots[1] = 30; elroy1_dots[2] = 40; elroy1_dots[3] = 40; elroy1_dots[4] = 40; elroy1_dots[5] = 50; elroy1_dots[6] = 50; elroy1_dots[7] = 50; elroy1_dots[8] = 60; elroy1_dots[9] = 60; elroy1_dots[10] = 60; elroy1_dots[11] = 80; elroy1_dots[12] = 80; elroy1_dots[13] = 80; elroy1_dots[14] = elroy1_dots[15] = elroy1_dots[16] = elroy1_dots[17] = 100; elroy1_dots[18] = elroy1_dots[19] = elroy1_dots[20] = 120; } { elroy2_speed[0] = 0.85f; elroy2_speed[1] = elroy2_speed[2] = elroy2_speed[3] = 0.95f; for(i = 4; i != 21; ++i) { elroy2_speed[i] = 1.05f; } } { elroy2_dots[0] = 10; elroy2_dots[1] = 15; elroy2_dots[2] = 20; elroy2_dots[3] = 20; elroy2_dots[4] = 20; elroy2_dots[5] = 25; elroy2_dots[6] = 25; elroy2_dots[7] = 25; elroy2_dots[8] = 30; elroy2_dots[9] = 30; elroy2_dots[10] = 30; elroy2_dots[11] = 40; elroy2_dots[12] = 40; elroy2_dots[13] = 40; elroy2_dots[14] = elroy2_dots[15] = elroy2_dots[16] = elroy2_dots[17] = 50; elroy2_dots[18] = elroy2_dots[19] = elroy2_dots[20] = 60; } { for(i = 0; i != 21; ++i) { dot_limit[0][i] = 0; } dot_limit[1][0] = 30; for(i = 1; i != 21; ++i) { dot_limit[1][i] = 0; } dot_limit[2][0] = 60; dot_limit[2][1] = 50; for(i = 2; i != 21; ++i) { dot_limit[2][i] = 0; } } level = 0; frightened_ = 0; remaining_lives = 3; bonus_spawned = 0; init_level(); /*uint8_t elroy1_dots[21]; float elroy1_speed[21]; uint8_t elroy2_dots[21]; float elroy2_speed[21];*/ }
/* run the state driven loop until game is broken up or finished */ void client_game_run( void ) { int ms, frame_delay = config.fps?10:1; int button_clicked, key_pressed; SDL_Event event; int abort = 0, i, j, penalty; /* frame rate */ int frames = 0; int frame_time = SDL_GetTicks(); event_clear_sdl_queue(); stk_display_fade( STK_FADE_IN, STK_FADE_DEFAULT_TIME ); stats_received = 0; stk_timer_reset(); ms = 1; while ( !abort && !stk_quit_request ) { /* check wether an event occured */ button_clicked = key_pressed = 0; if ( SDL_PollEvent( &event ) ) { if ( client_state == CS_PAUSE && game->game_type == GT_NETWORK ) gui_dispatch_event( &event, ms ); else if ( event.type == SDL_MOUSEBUTTONDOWN ) button_clicked = event.button.button; else if ( event.type == SDL_KEYDOWN ) { key_pressed = event.key.keysym.sym; if ( handle_default_key( key_pressed, &abort ) ) key_pressed = 0; } else if (event.type == SDL_ACTIVEEVENT) { if (event.active.state == SDL_APPINPUTFOCUS || event.active.state == SDL_APPACTIVE ) if (event.active.gain == 0 ) client_set_pause(1); } } else if ( client_state == CS_PAUSE && game->game_type == GT_NETWORK ) gui_dispatch_event( 0, ms ); /* check whether Shift is pressed to switch between own and highest score */ if (game->game_type == GT_LOCAL) handle_display_switch(); /* let server know we're still alive except * in CS_PLAY as we send paddle updates there */ if ( game->game_type == GT_NETWORK ) comm_send_heartbeat(); /* handle client */ switch ( client_state ) { case CS_FINAL_STATS: if ( key_pressed==SDLK_SPACE ) abort = 1; break; case CS_FATAL_ERROR: /* after game was violently broken up the server * may still send the stats of the game so far */ if ( button_clicked || key_pressed ) { SDL_Delay(250); /* give time to release button */ set_state( CS_RECV_STATS ); display_text( font, "Receiving final stats..." ); } break; case CS_FINAL_TABLE: if ( button_clicked || key_pressed ) { check_highscores(); select_chart( game_set->name, 0 ); /* remove saved game */ slot_delete( 0 ); slot_update_hint( 0, item_resume_0->hint ); /* quit local game */ abort = 1; } break; case CS_SCORE_TABLE: /* show who's next player and scores in local game */ display_score_table( "Next Player: %s", cur_player->name ); set_state( CS_GET_READY ); break; case CS_BONUS_LEVEL_SCORE: /* display total score from this level for player */ display_bonus_level_score(); set_state( CS_GET_READY_FOR_NEXT_LEVEL ); break; case CS_FINAL_PLAYER_INFO: if ( button_clicked || key_pressed ) { SDL_Delay(250); /* give time to release button */ set_state( CS_NEXT_PLAYER ); } break; case CS_RECV_LEVEL: comm_recv(); if ( cur_player->next_level_received ) { cur_player->next_level_received = 0; cur_player->paddle_id = cur_player->next_paddle_id; init_next_round(); } break; case CS_RECV_STATS: comm_recv(); if ( stats_received ) { set_state( CS_FINAL_STATS ); display_final_stats(); } break; case CS_ROUND_RESULT: if ( button_clicked || key_pressed ) { SDL_Delay(250); /* give time to release button */ if ( game_over ) { set_state( CS_RECV_STATS ); display_text( font, "Receiving final stats..." ); } else { set_state( CS_RECV_LEVEL ); display_text( font, "Receiving level data..." ); } } break; case CS_GET_READY: if ( button_clicked || key_pressed ) { SDL_Delay(250); /* give time to release button */ comm_send_short( MSG_READY ); set_state( CS_PLAY ); } break; case CS_GET_READY_FOR_NEXT_LEVEL: if ( button_clicked || key_pressed ) { SDL_Delay(250); /* give time to release button */ set_state( CS_NEXT_LEVEL ); } break; case CS_PAUSE: if ( game->game_type == GT_LOCAL ) break; /* check wether pause chatroom has been closed * either by client or remote */ comm_recv(); break; case CS_PLAY: /* hide objects */ begin_frame(); /* apply events to local paddle */ paddle_handle_events( l_paddle, ms ); /* update local objects and communicate if * comm_delay ms have passed */ update_game( ms ); /* show objects */ end_frame(); /* handle local level over */ if ( game->level_over ) { if ( game->game_type == GT_LOCAL ) { if ( game_set == 0 ) { abort = 1; /* was a test level */ grab_input(0); break; } if ( game->winner == PADDLE_BOTTOM ) { if (local_game->isBonusLevel) set_state( CS_BONUS_LEVEL_SCORE ); else set_state( CS_NEXT_LEVEL ); } else set_state( CS_LOOSE_LIFE ); } else { finalize_round(); } } break; case CS_NEXT_LEVEL: /* apply paddle stats to player */ game_set_current( local_game ); game_update_stats( PADDLE_BOTTOM, &cur_player->stats ); game_set_current( game ); /* init next level for player in local game */ cur_player->level_id++; if ( cur_player->level_id >= game_set->count ) { /* deactivate player */ cur_player->lives = 0; display_text( font, "You've cleared all levels...#Congratulations!!!" ); set_state( CS_FINAL_PLAYER_INFO ); break; } /* get snapshot for next init */ cur_player->snapshot = *game_set->levels[cur_player->level_id]; /* cycle players */ set_state( CS_NEXT_PLAYER ); break; case CS_RESTART_LEVEL: /* apply paddle stats to player */ game_set_current( local_game ); game_update_stats( PADDLE_BOTTOM, &cur_player->stats ); game_set_current( game ); /* reset level for next turn */ cur_player->snapshot = *game_set->levels[cur_player->level_id]; /* decrease lives (is checked that this wasn't the last one) */ cur_player->lives--; /* cycle players */ set_state( CS_NEXT_PLAYER ); break; case CS_LOOSE_LIFE: /* apply paddle stats to player */ game_set_current( local_game ); game_update_stats( PADDLE_BOTTOM, &cur_player->stats ); game_set_current( game ); /* remember level for next turn */ game_get_level_snapshot( &cur_player->snapshot ); /* decrease lives */ cur_player->lives--; if ( cur_player->lives == 0 ) { display_text( font, "You've lost all lives...#Do you want to buy a continue#for 100%% of your score? y/n" ); set_state( CS_CONFIRM_CONTINUE ); //set_state( CS_FINAL_PLAYER_INFO ); break; } set_state( CS_NEXT_PLAYER ); break; case CS_NEXT_PLAYER: /* game over? */ if ( players_count() == 0 ) { display_score_table( "Game Over!" ); set_state( CS_FINAL_TABLE ); break; } /* speak and fade */ play_speech(); fade_anims(); /* finalize current game context */ finalize_level(); /* set next player */ cur_player = players_get_next(); init_level( cur_player, PADDLE_BOTTOM ); if ( player_count > 1 ) set_state( CS_SCORE_TABLE ); else { set_state( CS_PLAY ); /* one player starts immediately */ stk_display_update( STK_UPDATE_ALL ); } break; case CS_CONFIRM_CONTINUE: case CS_CONFIRM_QUIT: case CS_CONFIRM_WARP: case CS_CONFIRM_RESTART: if ( key_pressed == 0 ) break; if ( key_pressed==SDLK_n||key_pressed==SDLK_ESCAPE ) { /* if denying continue... DIE!!! */ if ( client_state == CS_CONFIRM_CONTINUE ) { SDL_Delay(250); /* give time to release button */ set_state( CS_NEXT_PLAYER ); //set_state( CS_FINAL_PLAYER_INFO ); } else set_state( CS_PLAY ); break; } if ( key_pressed != SDLK_y && key_pressed != SDLK_z ) break; /* handle confirmed action */ SDL_Delay(250); /* give time to release button */ switch( client_state ) { case CS_CONFIRM_CONTINUE: /* clear score and give full lives again */ cur_player->lives = game->diff->lives; cur_player->stats.total_score = 0; set_state( CS_NEXT_PLAYER ); break; case CS_CONFIRM_QUIT: comm_send_short( MSG_QUIT_GAME ); if ( game->game_type == GT_LOCAL ) { /* apply paddle stats to player */ game_set_current( local_game ); game_update_stats( PADDLE_BOTTOM, &cur_player->stats ); game_set_current( game ); /* no higscore check anymore as game is supposed to * be resumed until normal game over */ /* testing levels don't got for * high scores *** if ( game_set ) { check_highscores(); select_chart( game_set->name, 0 ); }*/ /* save local game */ if ( game_set != 0 /*not testing a level*/ ) save_local_game( 0 ); abort = 1; } else { /* await game stats */ set_state( CS_RECV_STATS ); display_text( font, "Receiving final stats..." ); } break; case CS_CONFIRM_WARP: game->winner = -1; /* no speech */ local_game->winner = -1; /* not counted as win */ /* substract doubled score of remaining bricks */ penalty = 0; for ( i = 0; i < MAP_WIDTH; i++ ) for ( j = 0; j < MAP_HEIGHT; j++ ) if ( local_game->bricks[i][j].dur != -1 ) penalty += local_game->bricks[i][j].score; printf( "warp penalty: -%d\n", penalty ); local_game->paddles[0]->score -= penalty; set_state( CS_NEXT_LEVEL ); break; case CS_CONFIRM_RESTART: game->winner = -1; /* no speech */ local_game->winner = -1; /* not counted as win */ local_game->level_over = 1; set_state( CS_RESTART_LEVEL ); break; } break; } /* update anything that was changed */ stk_display_update( STK_UPDATE_RECTS ); /* get time since last call and delay if below frame_delay */ ms = stk_timer_get_time(); if ( ms < frame_delay ) { SDL_Delay( frame_delay - ms ); ms += stk_timer_get_time(); } frames++; } finalize_level(); client_state = CLIENT_NONE; stk_display_fade( STK_FADE_OUT, STK_FADE_DEFAULT_TIME ); if ( stk_quit_request ) comm_send_short( MSG_DISCONNECT ); else comm_send_short( MSG_UNHIDE ); /* frame rate */ frame_time = SDL_GetTicks() - frame_time; printf( "Time: %.2f, Frames: %i -> FPS: %.2f\n", (double)frame_time / 1000, frames, 1000.0*frames/frame_time ); event_clear_sdl_queue(); /* update the selected user and the user list in network as * we received ADD/REMOVE_USER messages */ gui_list_update( list_users, client_users->count ); /* re-select current entry */ if ( client_user ) { i = list_check( client_users, client_user ); if ( i != -1 ) gui_list_select( list_users, 0, i, 1 ); } }
/* create network/local game context and initiate game state: * network needs to receive the level data and a local game * has to load the next level */ int client_game_init_local( char *setname ) { Set_Chart *chart; int i, warp_limit; warp_limit = config.rel_warp_limit; allow_disintegrate = 1; /* the original levelsets do not need these workarounds */ if ( STRCMP( setname, "LBreakout2" ) || STRCMP( setname, "LBreakout1" ) ) { warp_limit = 100; allow_disintegrate = 0; } /* the approach for a local game is to use the same * settings as a network game. the receiving of packets * is simply faked by a local_game context that * runs the game locally. but to use only one game loop * we do not use it directly but apply its modificiations * to game which is visualized */ local_game = game_create( GT_LOCAL, config.diff, warp_limit ); game_set_current( local_game ); game_set_convex_paddle( config.convex ); game_set_ball_auto_return( !config.return_on_click ); game_set_ball_random_angle( config.random_angle ); game_set_ball_accelerated_speed( config.maxballspeed_float ); local_game->localServerGame = 1; /* load levels: * only required for local games. in network both players * just require a single level that can store the incoming * data that is send by the server via the net. */ if ( !strcmp( setname, TOURNAMENT ) ) game_set = levelset_load_all( levelset_names, gameSeed, config.addBonusLevels ); else game_set = levelset_load( setname, ((config.addBonusLevels)?gameSeed:0) ); if ( game_set == 0 ) return 0; /* load highest score so far if any */ chart = chart_set_query(setname); strcpy(best_name,"nobody"); best_score = 0; if (chart) { strcpy(best_name,chart->entries[0].name); best_score = chart->entries[0].score; } /* create client game context */ game = game_create( GT_LOCAL, config.diff, warp_limit ); game_set_current( game ); /* a local game is not limited in its communication */ client_comm_delay = 0; no_comm_since = 0; /* prepare warp icon at frame */ warp_blinks = 4; warp_blink = 1; /* set list of level background ids */ for ( i = 0; i < MAX_LEVELS; i++ ) bkgnd_ids[i] = rand() % bkgnd_count; /* initiate players */ players_clear(); for ( i = 0; i < config.player_count; i++ ) player_add( config.player_names[i], game->diff->lives, levelset_get_first( game_set ) ); cur_player = players_get_first(); /* init first level */ init_level( cur_player, PADDLE_BOTTOM ); /* if only one player don't show score table */ client_state = CS_NONE; if ( player_count > 1 ) set_state( CS_SCORE_TABLE ); else set_state( CS_PLAY ); /* one player starts immediately */ return 1; }