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
45
46
47
|
#include "GameScreen.h"
#include <memory>
#include <utility>
#include <raylib.h>
#include "Globals.h"
#include "OverScreen.h"
#include "Stage.h"
static constexpr Color INTERFACE {0, 0, 0, 230};
static constexpr float BAR_WIDTH {160};
GameScreen::GameScreen(std::unique_ptr<Stage> stage) :
m_stage {std::move(stage)},
m_stats {std::make_shared<Stats>()}
{
m_stage->m_player.m_playground = Rectangle{
BAR_WIDTH, 0, GetScreenWidth() - 2 * BAR_WIDTH, static_cast<float>(GetScreenHeight())};
m_stage->m_stats = m_stats;
}
void
GameScreen::update(const float dt)
{
m_stage->update(dt);
m_stats->points += 100 * dt;
if (m_stats->lifes < 0)
g_game.set(std::make_unique<OverScreen>(m_stats));
}
void
GameScreen::draw()
{
m_stage->draw();
DrawRectangle(0, 0, BAR_WIDTH, 600, INTERFACE);
DrawRectangle(800 - BAR_WIDTH, 0, BAR_WIDTH, 600, INTERFACE);
DrawText(TextFormat("%d", m_stats->total_bullets), 5, 25, 20, DARKGRAY);
DrawText(TextFormat("%d", m_stats->lifes), 5, 45, 20, DARKGREEN);
DrawText(TextFormat("%d", m_stats->points), 5, 65, 20, GOLD);
DrawFPS(5, 5);
}
|