Ejemplo n.º 1
0
void onIdle() {
    int elapsedTime = glutGet(GLUT_ELAPSED_TIME) - lastUpdate;
    //elapsedTime = (int) (elapsedTime * 0.5f); //slow down
    //if (elapsedTime < 5) return;
    if (!paused) {
        // FPS COUNTER //
        fpsCounter[0] += elapsedTime;
        fpsCounter[1]++;
        if (fpsCounter[0] > 1000) {
            //system("cls");
            cout << "FPS: " << 1000 / (fpsCounter[0] / fpsCounter[1]) << endl;
            fpsCounter[0] = fpsCounter[1] = 0;
        }
        // FPS COUNTER //
        cams.update(elapsedTime, &pacman);
        int pacmanDeathTime = maze.getPacmanDeathTime();
        if (!pacmanDeathTime) { //pacman is alive
            pacmanIsAlive = 1;
            pacman.update(elapsedTime, &maze);
            maze.eatBallAt(pacman.getPosX(), pacman.getPosY());
            ghosts.update(elapsedTime, pacman.getPosX(), pacman.getPosY(), &maze);
        }
        else {
            if (pacmanDeathTime + 6000 <  glutGet(GLUT_ELAPSED_TIME)) {
                //pacman.onBirth();
                pacman = Pacman();
                ghosts = Ghosts();
                maze.onPacmanBirth();
            }
            else {
                if (pacmanIsAlive) {
                    pacmanIsAlive = 0;
                    particles.start(pacman.getPosX(), pacman.getPosY());
                }
                particles.update(elapsedTime);
            }
        }
        glutPostRedisplay();
    }
    lastUpdate = glutGet(GLUT_ELAPSED_TIME);
}
Ejemplo n.º 2
0
void onDisplay(void) {
    // cams.projection(winW, winH);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    cams.look();
    lights.display(&pacman);

    //draw stuff
    maze.draw();
    if (!maze.getPacmanDeathTime()) { //pacman is alive
        pacman.draw();
    }
    else particles.draw();
    mazeFloor.draw();
    ghosts.draw();
    hud.draw(winW, winH, &maze);
    glFlush();
}