summaryrefslogtreecommitdiffhomepage
path: root/TestStage.cpp
blob: 19703d295707fbb0430c8602cd22f3df6fa478b0 (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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include "TestStage.h"

#include <cstdint>

#include <raylib.h>

#include "EnemyFactory.h"
#include "Globals.h"
#include "OverScreen.h"


static constexpr Color DEEPSPACE {3, 5, 22, 255};


TestStage::TestStage() :
    m_const {}
{
    m_enemies.reserve(17);
    m_enemies.push_back(EnemyFactory::make_small(m_const.m_bullets, 300, -10, 0));
    m_enemies.push_back(EnemyFactory::make_small(m_const.m_bullets, 500, -10, 0, true));
    m_enemies.push_back(EnemyFactory::make_thick(m_const.m_bullets, 400, -10, 10));
    m_enemies.push_back(EnemyFactory::make_small(m_const.m_bullets, 550, -10, 20));
    m_enemies.push_back(EnemyFactory::make_small(m_const.m_bullets, 250, -10, 20, true));
    m_enemies.push_back(EnemyFactory::make_thick(m_const.m_bullets, 200, -20, 26, -0.2));
    m_enemies.push_back(EnemyFactory::make_thick(m_const.m_bullets, 600, -10, 26, 0.7));
    m_enemies.push_back(EnemyFactory::make_small(m_const.m_bullets, 400, -10, 32));
    m_enemies.push_back(EnemyFactory::make_rotator(m_const.m_bullets, 260, -10, 44));
    m_enemies.push_back(EnemyFactory::make_rotator(m_const.m_bullets, 540, -10, 44, true));
    m_enemies.push_back(EnemyFactory::make_rotator(m_const.m_bullets, 300, -10, 49, true));
    m_enemies.push_back(EnemyFactory::make_rotator(m_const.m_bullets, 500, -10, 50));
    m_enemies.push_back(EnemyFactory::make_small(m_const.m_bullets, 360, -10, 56));
    m_enemies.push_back(EnemyFactory::make_small(m_const.m_bullets, 440, -10, 56, true));
    m_enemies.push_back(EnemyFactory::make_small(m_const.m_bullets, 365, -10, 62, true));
    m_enemies.push_back(EnemyFactory::make_small(m_const.m_bullets, 435, -10, 62));
    m_enemies.push_back(EnemyFactory::make_rotator(m_const.m_bullets, 400, -10, 66));
}


void
TestStage::update(const float dt)
{
    m_flash.update(dt);
    m_player.update(dt);
    for (auto& enemy : m_enemies)
        enemy.update(dt);
    m_const.update(dt);
    bool collided = m_player.collide(m_const.m_bullets);
    if (collided) m_flash.start();
    if (m_stats) {
        m_stats->total_bullets = m_const.m_bullets.size();
        if (collided) m_stats->lifes--;
    }
    bool all_done = true;
    for (const auto& enemy : m_enemies) {
        if (!enemy.gone()) {
	    all_done = false;
	    break;
	}
    }
    if (all_done)
        g_game.set(std::make_unique<OverScreen>(m_stats));
}


void
TestStage::draw()
{
    ClearBackground(DEEPSPACE);
    m_const.draw();
    for (auto& enemy : m_enemies)
        enemy.draw();
    m_player.draw();
    m_flash.draw();
}