blob: 636a6b2b29dfd488f13f8775511e456b4d0015fc (
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
|
#include "Spiral.h"
#include <raylib.h>
#include <cmath>
SpiralSystem::SpiralSystem()
{
m_bullets.reserve(RESERVED);
}
void
SpiralSystem::update(const float dt)
{
const int min_height = 0 - 3 * MARGIN;
const int max_height = GetScreenHeight() + MARGIN;
const int min_width = 0 - MARGIN;
const int max_width = GetScreenWidth() + MARGIN;
auto it = m_bullets.begin();
while (it != m_bullets.end()) {
auto& bullet = *it;
bullet.timer += dt;
if (bullet.timer > bullet.redirect_time) {
bullet.timer -= bullet.redirect_time;
bullet.angle = bullet.angle + bullet.redirect;
if (bullet.angle > 2.0)
bullet.angle -= 2.0;
bullet.redirect *= bullet.redirect_decrease;
}
float velovity_x = std::cos(angle * M_PI);
float velovity_y = std::sin(angle * M_PI);
bullet.position.x += velocity_x * dt;
bullet.position.y += velocity_y * dt;
const bool y_exceeded = bullet.position.y < min_height || bullet.position.y > max_height;
const bool x_exceeded = bullet.position.x < min_width || bullet.position.x > max_width;
if (y_exceeded || x_exceeded)
it = m_bullets.erase(it);
else
++it;
}
}
void
SpiralSystem::draw()
{
for (const auto& bullet : m_bullets)
DrawCircle(bullet.position.x, bullet.position.y, bullet.radius, bullet.color);
}
|