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

#include <cmath>
#include <memory>

#include <raylib.h>


Oscillating::Oscillating(std::shared_ptr<Vector2> position) :
    m_phase {0},
    m_shift {1.6f},
    m_position {position}
{
}


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