From 78097b5496209b56cef9d7fc8d6c13e4c87e0eb1 Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 18 Apr 2022 23:50:31 +0200 Subject: Added simple behaviours for enemies I don't quite like FallingAndOscillating approach. Perhaps it will be better to just make it a list/vector in the enemy to allow for composition. --- Oscillating.cpp | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 Oscillating.cpp (limited to 'Oscillating.cpp') diff --git a/Oscillating.cpp b/Oscillating.cpp new file mode 100644 index 0000000..4839282 --- /dev/null +++ b/Oscillating.cpp @@ -0,0 +1,33 @@ +#include "Oscillating.h" + +#include + +#include + +#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; +} -- cgit v1.1