summaryrefslogtreecommitdiffhomepage
path: root/SpiralGenerator.cpp
blob: ea3268f7d4ec1bbbeadec95f41681dcfef942c82 (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
#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.08f},
    m_cone {0.4f},
    m_angle {1.0f},
    m_redirect {0.1f},
    float timer {0f},
    float redirect_time {1f},
    float redirect_decrease {0.2f},
    m_direction {-1.f},
    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 + cos * m_shift;
            bullet.position.y = m_position->y + sin * m_shift;
            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;
        }
    }
}