ICT290 / src / scene / mainMenu / exitScreen.cpp
exitScreen.cpp
Raw
#include "exitScreen.h"

std::shared_ptr<State> exitScreen::m_thisState;

std::shared_ptr<State> exitScreen::init(Resources& engineResources) {
    m_thisState = std::make_shared<State>(draw,
                                          handleEvents,
                                          destroy,
                                          pause,
                                          update,
                                          engineResources);

    std::string name{"banner"};
    glm::vec3 location{0, 0, -1};
    glm::vec3 rotation{0, 90, 0};
    glm::vec3 scale{1};
    auto model = m_thisState->resources.modelManager.getModel(
        "as2/exitScreen.obj");

    Object exitScreen{name, model, location, rotation, scale};

    m_thisState->objects.emplace(name, exitScreen);

    return m_thisState;
}

void exitScreen::destroy() {
    pause(true);
}

void exitScreen::pause(bool pause) {
    if (pause) {
        Light::disableLighting();
    } else {
        glClearColor(0.1f, 0.1f, 0.1f, 10.f);

        setCamera();
    }
}

void exitScreen::handleEvents(SDL_Event& event) {
    // Skip intro
    while (SDL_PollEvent(&event)) {
        if (event.type == SDL_KEYDOWN || event.type == SDL_MOUSEBUTTONDOWN) {
            m_thisState->stop = true;
        }
    }
}

void exitScreen::update(float) {}

void exitScreen::draw() {
    for (auto& obj : m_thisState->objects) {
        obj.second.draw();
    }
}

void exitScreen::setCamera() {
    // Set camera perspective
    m_thisState->camera.setPerspective(45.f, (float)1920 / 1080, 0.1f, 10.f);

    m_thisState->camera.position = glm::vec3{-0.24f, 1, 0.77};

    m_thisState->camera.lockMouse(false);

    m_thisState->camera.update(0.01f);
}