int run_game(GameData *data) { int cur_shot = 0; while(cur_shot < data->num_shots) { Pacman *cur_pac_shot = (data->shots + cur_shot); draw_pacman(cur_pac_shot); draw_pebbles(data->pebbles, data->num_pebbles); *cur_pac_shot->velocity = *(data->old_velocity); Velocity *velocity = cur_pac_shot->velocity; while(!KEY_PRESSED(START)) { update_velocities(velocity); wait_for_vblank(); draw_user_velocities(data->velocity_frame_x, data->velocity_frame_y, velocity); draw_pacman(cur_pac_shot); } *(data->old_velocity ) = *cur_pac_shot->velocity;//MUST save old shot erase_frame(data->velocity_frame_x, data->bg_color); erase_frame(data->velocity_frame_y, data->bg_color); //now we run simulation fill_frame(data->indicator, GREEN); int i = 0; while(!off_screen(cur_pac_shot->frame)) { for (i = 0; i < data->num_pebbles; i++) { PacmanPebble *cur_pebble = (data->pebbles + i); check_collision(cur_pac_shot, cur_pebble); } wait_for_vblank(); erase_frame(cur_pac_shot->frame, data->bg_color); move_shot(cur_pac_shot); draw_pebbles(data->pebbles, data->num_pebbles); draw_pacman(cur_pac_shot); } erase_frame(cur_pac_shot->frame, data->bg_color); cur_shot++; } fill_frame(data->indicator, RED); return 0; }
void draw_scene() { glClearColor(0.0, 0.0, 0.0, 0.0); glClear(GL_COLOR_BUFFER_BIT); if (firstdraw == true || reset == true) { if (firstdraw == true) { timer = SDL_AddTimer(timer_speed, game_timer, 0); setfield("ghostmap.txt", ghostfield); setfield("pacmap-inversion.txt", ghostrun); pacman.next_x = pacman.x + 1; } setfield("pacmap.txt", playfield); //initialize ghosts g_blinky.status = ST_BLINKY; g_pinky.status = ST_PINKY; g_inky.status = ST_INKY; g_clyde.status = ST_CLYDE; g_blinky.direction = ST_LEFT; g_pinky.direction = ST_LEFT; g_inky.direction = ST_LEFT; g_clyde.direction = ST_LEFT; g_blinky.has_los = false; g_pinky.has_los = false; g_inky.has_los = false; g_clyde.has_los = false; g_blinky.x = 43; g_blinky.y = 8; g_pinky.x = 53; g_pinky.y = 15; g_inky.x = 51; g_inky.y = 22; g_clyde.x = 57; g_clyde.y = 22; } Ai::encompassing(); //displayfield(ghostfield); draw_playfield(); draw_pacman(); draw_ghosts(); draw_score(); SDL_GL_SwapBuffers(); int error = glGetError(); if (error != 0) { fileout << "Error: " << error << endl << flush; cout << "Error: " << error << endl << flush; } }