int main (int argc, char *argv[]) { int ghost[3],pacman[3],target[2], number_ghost=0; char maze[L][C]; char ch,path[20] = "maze.txt"; int i=0,j=0; while (number_ghost != 9) { //clear_screen(); load_maze(maze,path); //print_maze(maze); printf ( "\t>>> GHOSTS <<<\n" ); printf ( "1.BLINK 2.PINK 3.INKY 4.CLYDE 9.SAIR \n" ); do { printf ( "Qual o numero do Ghost? = " ); scanf ("%d", &number_ghost); }while(number_ghost > 4 || number_ghost < 1 || number_ghost == 9 ); //Lendo cordenadas para o ghost if (number_ghost != 9) { print_maze(maze); read_player(maze,ghost,'3'); read_player(maze,pacman,'5'); switch (number_ghost) { case 1: //void blink(maze,ghost,pacman,target); position(maze,pacman,'8'); target[0] = pacman[0]; target[1] = pacman[1]; break; case 2: // void pink(maze,ghost,pacman,target); // position(maze,target,'T'); break; case 3: ink(red,pacman,target); position(maze,target,'8'); break; case 4: // void clyde(maze,ghost,pacman,target); // position(maze,target,'8'); break; } walking(maze,ghost,target);//mudar os parametros print_maze (maze); } } return 0; }
void update_and_render(Memory *memory, GameState *game_state, FrameBuffer *frame_buffer, Keys *keys, Mouse *mouse, u64 time_us, u32 last_frame_dt, u32 fps , u32 argc, char *argv[]) { if (!game_state->init) { init_render_segments(memory, game_state, frame_buffer); init_game(memory, game_state, keys, time_us, argc, argv); load_maze(memory, game_state, argc, argv); reset_zoom(game_state); } update_inputs(keys, &game_state->inputs, time_us); if (game_state->inputs.maps[SAVE].active) { serialize_maze(&game_state->maze, &game_state->functions, game_state->filename); } if (game_state->inputs.maps[RELOAD].active) { strcpy(game_state->persistent_str, "Reload!"); load_maze(memory, game_state, argc, argv); } if (game_state->inputs.maps[RESET].active) { strcpy(game_state->persistent_str, "Reset!"); reset_zoom(game_state); } if (game_state->inputs.maps[RESTART].active) { strcpy(game_state->persistent_str, "Restart!"); delete_all_cars(&game_state->cars); reset_car_inputs(&game_state->ui); game_state->finish_sim_step_move = false; game_state->last_sim_tick = 0; game_state->sim_steps = 0; } if (game_state->inputs.maps[STEP_MODE_TOGGLE].active) { game_state->single_step = !game_state->single_step; log(L_GameLoop, "Changing stepping mode"); } // // UPDATE VIEW // update_pan_and_zoom(game_state, mouse); RenderBasis render_basis; render_basis.world_per_pixel = game_state->world_per_pixel; render_basis.scale = squared(game_state->zoom / 30.0f); render_basis.scale_focus = game_state->scale_focus; render_basis.origin = game_state->maze_pos * game_state->world_per_pixel; render_basis.clip_region = game_state->world_render_region * game_state->world_per_pixel; RenderBasis orthographic_basis; get_orthographic_basis(&orthographic_basis, game_state->screen_render_region); // // UPDATE WORLD // ui_consume_mouse_clicks(game_state, &orthographic_basis, &game_state->ui, mouse, time_us); if (game_state->inputs.maps[SIM_TICKS_INC].active) { game_state->sim_ticks_per_s += .5f; } if (game_state->inputs.maps[SIM_TICKS_DEC].active) { game_state->sim_ticks_per_s -= .5f; } game_state->sim_ticks_per_s = clamp(.5, game_state->sim_ticks_per_s, 20); update_cells_ui_state(game_state, &render_basis, mouse, time_us); b32 sim = sim_tick(game_state, time_us); if (sim && game_state->ui.car_inputs == 0 && !game_state->finish_sim_step_move) { perform_cells_sim_tick(memory, game_state, &(game_state->maze.tree), time_us); perform_cars_sim_tick(memory, game_state, time_us); } if (sim && game_state->ui.car_inputs == 0) { move_cars(game_state); game_state->finish_sim_step_move = false; ++game_state->sim_steps; } annimate_cars(game_state, last_frame_dt); step_particles(&(game_state->particles), time_us); update_ui(game_state, &orthographic_basis, &game_state->ui, mouse, &game_state->inputs, time_us); // // RENDER // // Add render operations to queue game_state->render_operations.next_free = 0; add_fast_box_to_render_list(&game_state->render_operations, &orthographic_basis, (Rectangle) { (V2) {0,0},size(game_state->screen_render_region) }, (PixelColor) { 255, 255, 255 }); draw_cells(game_state, &game_state->render_operations, &render_basis, &(game_state->maze.tree), time_us); draw_cars(game_state, &game_state->render_operations, &render_basis, &(game_state->cars), time_us); // render_particles(&(game_state->particles), &game_state->render_operations, &render_basis); r32 text_scale = 0.3; draw_string(&game_state->render_operations, &orthographic_basis, &game_state->bitmaps.font, size(game_state->screen_render_region) - CHAR_SIZE*text_scale*(V2) { strlen(game_state->persistent_str), 1 }, game_state->persistent_str, text_scale, (V4) { 1, 0, 0, 0 }); draw_ui(&game_state->render_operations, &orthographic_basis, &render_basis, &game_state->bitmaps.font, &game_state->cell_bitmaps, &game_state->ui, time_us); char str[4]; fmted_str(str, 4, "%d", fps); draw_string(&game_state->render_operations, &orthographic_basis, &game_state->bitmaps.font, (V2) { 0, 0 }, str, 0.3, (V4) { 1, 0, 0, 0 }); // Add render segments to render queue V2 ns = game_state->render_segs.n_segments; V2 s; for (s.y = 0; s.y < ns.y; ++s.y) { for (s.x = 0; s.x < ns.x; ++s.x) { RenderQueueData render_data; Rectangle *segment = game_state->render_segs.segments + (u32)s.y + (u32)ns.y*(u32)s.x; render_data.clip_region = *segment; render_data.frame_buffer = frame_buffer; render_data.render_operations = &game_state->render_operations; #ifdef THREADED_RENDERING pthread_mutex_lock(&game_state->render_queue.mut); while (game_state->render_queue.full) { log(L_RenderQueue, "producer: queue FULL."); pthread_cond_wait(&game_state->render_queue.not_full, &game_state->render_queue.mut); } log(L_RenderQueue, "producer: Adding."); queue_add(&game_state->render_queue, render_data); pthread_mutex_unlock(&game_state->render_queue.mut); pthread_cond_signal(&game_state->render_queue.not_empty); #else consume_render_operations(render_data.frame_buffer, render_data.render_operations, render_data.clip_region); #endif } } // TODO: Wait for frame rendering to finish // TODO: Get rid of this game_state->last_render_basis = render_basis; }