Exemple #1
0
int main(int argc __attribute__((unused)), char *argv[])
{

    /* init allegro library */
    ALLEGRO_TIMER *timer = NULL;
    al_init();

    /* prepare random number generator */
    srand(time(NULL));

    /* activate all engine subsystems using the startup macro */
    resetCollisionTable();
    STARTUP(videoInit())
    STARTUP(init_datafile(argv))
    STARTUP(al_install_keyboard())
    STARTUP(al_install_joystick())
    STARTUP(fontInit())
    STARTUP(setupSound())
    timer = al_create_timer(1.0 / 60);
    al_start_timer(timer);
    initMediaLib();
    initBuffers();

    /* prepare game */
    startGame();

    /* begin game loop */
    while(!state.terminate) {
        runState(timer);
    }

    /* finish, return control to os */
    al_destroy_timer(timer);
    shutdownState();
    shutdownGame();
    videoKill();
    shutdownSound();
    al_uninstall_system();
    PHYSFS_deinit();

    /* no problems, exit false */
    return EXIT_SUCCESS;

}
Exemple #2
0
int Controller::checkKeyboard(sf::Event event){
    if(checkInputs == true){
        sf::Time ElapsedTime = graphics.clock.restart();
        b2Body* lPlayer = player.getPlayerBody();
        if(lPlayer == NULL){
            std::cout << "Warning: player (input) is null!";
            return 0;
        }
        //Handle input
        switch(event.type){
        case sf::Event::KeyPressed:
            if(event.key.code == sf::Keyboard::Up){
                //lPlayer->move(0, (-player.getMoveSpeed() * ElapsedTime.asSeconds()));
                float impulse = lPlayer->GetMass() * -(player.getMoveSpeed(true));
                lPlayer->ApplyLinearImpulse(b2Vec2(0, impulse), lPlayer->GetWorldCenter(), true);
            } else if(event.key.code == sf::Keyboard::Right){
                //lPlayer->move((player.getMoveSpeed() * ElapsedTime.asSeconds()), 0);
                float impulse = lPlayer->GetMass() * (player.getMoveSpeed(false));
                lPlayer->ApplyLinearImpulse(b2Vec2(impulse, 0), lPlayer->GetWorldCenter(), true);
                player.source.y = player.Right;
                player.animate();
            } else if(event.key.code == sf::Keyboard::Left){
                //lPlayer->move((-player.getMoveSpeed() * ElapsedTime.asSeconds()), 0);
                float impulse = lPlayer->GetMass() * -(player.getMoveSpeed(false));
                lPlayer->ApplyLinearImpulse(b2Vec2(impulse, 0), lPlayer->GetWorldCenter(), true);
                player.source.y = player.Left;
                player.animate();
            } else if(event.key.code == sf::Keyboard::Escape){
                shutdownGame();
            }
        }
        return 1;
    } else {
        return 0;
    }
}