Example #1
0
void RenderF()
{
    g_Render.clear({ 0.1f, 0.1f, 0.0f });

   // glLoadIdentity();

    UpdateEyePositionFromMouse();

    g_Render.updateCamera(g_Camera);    

    g_Render.renderScene(&g_Scene);

    TwDraw();

    g_Render.swapBuffers();
}
Example #2
0
int main() {
    _CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );

    // direction for player auto-moving
    int direction = ObjectWay::undefined;

    // init logic configuration
    Config config;
    initConfig(&config);

    // init render object
    Render* render = new Render(config.screen_width, config.screen_height);
    if(!render->init()) {
        delete render;
        return EXIT_FAILURE;
    }

    // init logic object
    Logic* logic = new Logic();
    logic->flush(config);
    logic->init(config);

    sf::Clock clock;
    sf::Event event;

    while (render->getWindow()->isOpen()) {
        sf::Int32 msec = clock.getElapsedTime().asMilliseconds();
        logic->setTime(msec);

        // check in loop for events
        while(render->getWindow()->pollEvent(event)) {
            if(event.type == sf::Event::Closed || sf::Keyboard::isKeyPressed(sf::Keyboard::Escape))
                render->close();

            if(event.type == sf::Event::KeyReleased) 
                if (event.key.code == sf::Keyboard::Right || event.key.code == sf::Keyboard::Left)
                    direction = ObjectWay::undefined;
            
            if (sf::Keyboard::isKeyPressed(sf::Keyboard::Space))
                logic->spawnRocket(); // launch rocket
            
            if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
                direction = ObjectWay::right;
            if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
                direction = ObjectWay::left;

            if(direction != ObjectWay::undefined) {
                ObjectPosition pos = logic->getPlayer().position;
                if(direction == ObjectWay::right)
                    pos.x += config.speed_player;
                else
                    pos.x -= config.speed_player;

                if(pos.x > 0 && pos.x < (float)config.screen_width-25.0f)
                    logic->setPlayerPosition(pos);
            }

            if (sf::Keyboard::isKeyPressed(sf::Keyboard::Return) && logic->getLifes() <= 0) {
                logic->clearObjects();
                logic->flush(config);
            }
        }

        // clear screen
        render->clear();
        
        if(logic->getLifes() > 0) {
            if(logic->getEnemiesCount() == 0) {
                // set new round and respawn enemies
                logic->setNewRound();
                logic->spawnEnemies(0.0f, 40.f, 10, 3);
            }

            logic->spawnBomb();       // fire bomb randomly

            logic->moveEnemies();     // move enemies
            logic->moveRockets();     // move rockets
            logic->moveBombs();       // move bombs

            logic->collideEnemies();  // collide with enemies
            logic->collideRockets();  // collide with rockets
            logic->collideBombs();    // collide with bombs

            // draw logic objects
            drawObjects(logic, render);
        } else {
            // logic is over, draw score
            render->drawFarewell(logic->getScore());
            logic->clearObjects();
        }

        // render screen
        render->display();
    }


    delete logic;
    delete render;
    return EXIT_SUCCESS;
}