summaryrefslogtreecommitdiffhomepage
path: root/Oscillating.cpp
blob: 48392820190979e3ca1db9a0a08116a65aefcf43 (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
#include "Oscillating.h"

#include <cmath>

#include <raylib.h>

#include "Generator.h"


Oscillating::Oscillating() :
    m_phase {0},
    m_shift {1.6f}
{
}


void
Oscillating::update(const float dt, Vector2& position, Generator& generator)
{
    (void) generator;
    m_phase += dt * 0.8f;
    if (m_phase > 2.f)
        m_phase -= 2.f;
    const float cos = std::cos(m_phase * M_PI);
    position.x += cos * m_shift;
}


void
Oscillating::set_phase(const float phase)
{
    m_phase = phase;
}