/* Our main update function - called every time we go through our main loop */ void UpdateFrame(void) { /* our timing information */ unsigned int fps; float dt; /* force another redraw, so we are always drawing as much as possible */ glutPostRedisplay(); /* adjust our timer, which we might use for transforming our objects */ dt = GetPreviousFrameDeltaInSeconds(); dt = dt * (float) DistPaths; gPacmanTimer += dt; gGhostTimer += ghostRate * dt; // update ghosts current node when timer goes DistPaths pixels if (gGhostTimer > (float) DistPaths) { gGhostTimer = 0.; updateGhosts(); } // update pacmans current node when timer goes DistPaths pixels if (gPacmanTimer > (float) DistPaths) { gPacmanTimer = 0.; refreshPacman(); } // printf("gan: %d\n", (int) gPacmanTimer); /* timing information */ if (ProcessTimer(&fps)) { /* update our frame rate display */ printf("FPS: %d\n", fps); } }
/*Fonction du jeu*/ void jouer(Pacman *pac, Fantome *ftm, Input in, config *cfg, int level, score_message **msg_list) { int i; SDL_Delay(DELAY); set_pac_target(pac); //Cherche l'endroit ou aller pour pacman //Fonction de déplacement de pacman pac->controllerFonction(in, *cfg, pac->controlled_by, &(pac->position), &(pac->cur_direction), &(pac->nb_keys), &(pac->speed), &(pac->num_image), pac->target); for(i=0; i<NB_GHOST; i++) { set_ftm_target(ftm+i, pac->position); ftm[i].controllerFonction(in, *cfg, ftm[i].controlled_by, &(ftm[i].position), &(ftm[i].cur_direction), &(ftm[i].nb_keys), &(ftm[i].speed), &(ftm[i].num_image), ftm[i].target); } updatePacman(pac); updateGhosts(ftm); SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0)); draw_level(); draw_pac_infos(pac); draw_score(pac->score, level); affiche_pacman(pac); affiche_fantomes(ftm); action(pac, ftm, msg_list); display_messages(msg_list); SDL_Flip(screen); }