summaryrefslogtreecommitdiffhomepage
path: root/SpiralGenerator.cpp
blob: 5c39dfb350e05e5d6dc0adea8e9bc1a6abf48a88 (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
#include "SpiralGenerator.h"

#include <cmath>
#include <memory>
#include <utility>

#include <raylib.h>

#include "Spiral.h"


SpiralGenerator::SpiralGenerator(std::shared_ptr<Vector2> position, SpiralBullet::Vector& bullets) :
    m_position {position},
    m_bullets {bullets},
    m_delay {0},
    m_interval {0.80f},
    m_angle {1.0f},
    m_redirect {0.125f},
    m_timer {0.0f},
    m_redirect_time {0.05f},
    m_redirect_decrease {0.99f},
    m_speed {80},
    m_shift {10},
    m_segments {1},
    m_color {240, 0, 0, 255}
{
}


void
SpiralGenerator::update(const float dt)
{
    if (!m_enabled)
        return;
    m_delay += dt;
    if (m_delay > m_interval) {
        m_delay -= m_interval;
        m_color.g = 0;
        for (float i = 0; i <= m_segments; ++i) {
            SpiralBullet bullet;
            bullet.color = m_color;
            bullet.radius = 3;
            bullet.velocity = m_speed;
            bullet.position.x = m_position->x;
            bullet.position.y = m_position->y;
            bullet.angle = m_angle;
            bullet.redirect = m_redirect;
            bullet.timer = m_timer;
            bullet.redirect_time = m_redirect_time;
            bullet.redirect_decrease = m_redirect_decrease;
            m_bullets.push_back(std::move(bullet));
            m_color.g += 20;
        }
    }
}