summaryrefslogtreecommitdiffhomepage
path: root/TitleScreen.cpp
blob: 3994fe93df318c82adff2a968926c066c7f33044 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include "TitleScreen.h"

#include <memory>

#include <raylib.h>

#include "Game.h"
#include "GameScreen.h"
#include "Globals.h"


static constexpr const char* TITLE {"Generic Bullet HELL"};
static constexpr const char* PRESS {"Press SPACE to start"};


TitleScreen::TitleScreen() :
    m_blink {0}
{
    const int screen_width = GetScreenWidth();
    const int title_width = MeasureText(TITLE, FONT_SIZE);
    const int press_width = MeasureText(PRESS, FONT_SIZE);
    m_title_x = (screen_width - title_width) / 2;
    m_press_x = (screen_width - press_width) / 2;
}


void
TitleScreen::update(const float dt)
{
    m_blink += dt;
    if (m_blink > 2 * INTERVAL)
        m_blink -= 2 * INTERVAL;
    if (IsKeyPressed(KEY_SPACE))
        g_game.set(std::make_unique<GameScreen>());
}


void
TitleScreen::draw()
{
    DrawText(TITLE, m_title_x, 160, FONT_SIZE, LIGHTGRAY);
    if (m_blink < INTERVAL)
        DrawText(PRESS, m_press_x, 180, FONT_SIZE, GRAY);
}