Example #1
0
int main(int argc, char **argv)
{
    if (argc > 1) {
        Time_Seed = atoi(argv[1]);
    }

    init_path();

    srand(Time_Seed);
    std::string config_file;
    if (!search_path(CONFIG_FILE, config_file)) {
        DEBUG_ERROR("error loading config file " << CONFIG_FILE);
    }
    loadConfig(config_file, &Config_Info);

    if (glfwInit() != true) {
        std::cerr << "glfwInit() fail!" << std::endl;
        return 1;
    }
    if (glfwOpenWindow(1000, 600, 8, 8, 8, 8, 8, 8, GLFW_WINDOW) != GL_TRUE) {
        /* 1000 because the player big timer doesn't show if 800 */
        std::cerr << "glfwOpenWindow() fail!" << std::endl;
    }

    generalStartup(&Resources_Manager);

    gameInitialize();
    newMatch();

    glfwSetWindowTitle("maze rush");

    glfwSetWindowSizeCallback(reshape);
    glfwSetWindowCloseCallback(closeCallback);
    glfwSetMousePosCallback(mouseMotion);
    glfwSetMouseButtonCallback(mouseButton);
    glfwSetKeyCallback(keypressCallback);
    const double fps = 1/30.0;
    double lastTime = 0.0;
    double fpsCountTime = 0.0f;
    int framesThisSecond = 0;
    Quit = false;
    while (!Quit) {
        pollKeyboard();
        double timeNow = glfwGetTime();
        if ((timeNow - lastTime) >= fps) { // one "time tick between frames"
            update();
            display();

            Quit = (Quit || !glfwGetWindowParam(GLFW_OPENED));

            ++framesThisSecond;
            lastTime = timeNow;
        }
        if (timeNow - fpsCountTime >= 1.0) { // one second
            Current_FPS = framesThisSecond; // global containing the Current_FPS;
            fpsCountTime = timeNow;
            framesThisSecond = 0;
        }
    }

    return 0;
}
Example #2
0
void playGame(void)
{
    bool gameLoaded = false;
    uint8_t ch;
    
    gScoreBar = 0;
    gShouldSave = false;
    
    printf("\n\nChecking for a saved game...");
    
    if (loadGame()) {
        bool gotAnswer = false;
        
        printf("\n\nYou have a saved game!\n    Would you like to continue it (Y/N)");
        
        while (!gotAnswer) {
            ch = cgetc();
            switch (ch) {
                case 'y':
                case 'Y':
                    printf("\n\nLoading your saved puzzle");
                    gotAnswer = true;
                    gShouldSave = true;
                    gameLoaded = true;
                    break;
                    
                case 'n':
                case 'N':
                    gotAnswer = true;
                    break;
                    
                default:
                    badThingHappened();
                    break;
            }
        }
    }
    
    showAndClearDblLoRes();
    if (!gameLoaded) {
        startNewGame();
    }
    drawBoard();
    speakGo();
    while (true) {
        resetStarAnim();
        
        while (true) {
            doStarAnim();
            
            if (pollKeyboard()) {
                break;
            }
            
            if ((gGameOptions.enableJoystick) &&
                (pollJoystick())) {
                break;
            }
            
            if ((gGameOptions.enableMouse) &&
                (pollMouse())) {
                break;
            }
        }
        
        if (gameIsOver()) {
            endGame();
            showAndClearDblLoRes();
            refreshScore(0);
            startNewGame();
            gShouldSave = false;
        }
    }
}