Source

pyGAP / game / src / game / state / state_intro.cpp

Full commit
#include "game/state/state_intro.h"
#include "game/state/state_manager.h"
#include "game/input/command_sample.h"

#include "input/command_manager.h"
#include "input/command.h"
#include "renderer/renderer.h"

#include "common/log.h"

#include <cstdio>

namespace game {


static bool registered = register_state< StateIntro >("intro");


StateIntro::StateIntro() : state::State(), common::Singleton< StateIntro >() {
#if defined(DEBUG)
    log_ = common::Log::get(__FUNCTION__);
#endif
}


void StateIntro::enter()
{
    LOG("Entering state intro\n");

    color_ = 0.0;
    pause_ = false;
}


int StateIntro::translate(input::CommandManager* commands)
{
    input::Command* sw = &(*commands)[CommandSample::SWITCH];
    input::Command* pause = &(*commands)[CommandSample::PAUSE];

    if (!sw->is_triggered()  && sw->has_changed())
        StateManager::instance()->switch_to_state("game");

    if (pause->is_triggered() && pause->has_changed()) // is_triggered and has_changed means "has just been triggered"
        pause_ = !pause_;

    return 0;
}


void StateIntro::update(unsigned int dt)
{
    //if (color_ > 1.0) StateManager::instance()->switch_to_state("game");
    //StateManager::instance()->switch_to_state("game");
    if (color_ == 0.0)
        LOG("Update\n")

    if(pause_)
        return;

    float dtf = (float(dt) / 1000000.0);
    color_ > 1.0 ? color_ = 0.0 : color_ += 1.0 * dtf;
}


void StateIntro::render(renderer::Renderer* renderer) const
{
    renderer->clear(0.0, color_, color_);
}


} // namespace game