aboutsummaryrefslogtreecommitdiffstats
path: root/src/weather.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/weather.cpp')
-rw-r--r--src/weather.cpp61
1 files changed, 61 insertions, 0 deletions
diff --git a/src/weather.cpp b/src/weather.cpp
new file mode 100644
index 0000000..59396d8
--- /dev/null
+++ b/src/weather.cpp
@@ -0,0 +1,61 @@
+#include <weather.hpp>
+
+#include <config.hpp>
+#include <random.hpp>
+#include <particle.hpp>
+
+constexpr const char *weatherStrings[] = {
+ "Sunny",
+ "Rainy",
+ "Snowy"
+};
+
+Weather WeatherSystem::weather;
+
+WeatherSystem::WeatherSystem(Weather w)
+{
+ weather = w;
+}
+
+void WeatherSystem::update(entityx::EntityManager &en, entityx::EventManager &ev, entityx::TimeDelta dt)
+{
+ (void)en;
+ (void)ev;
+ (void)dt;
+
+ static int newPartDelay = 0; // TODO no
+
+ switch (weather) {
+ case Weather::Sunny:
+ break;
+ case Weather::Rainy:
+ if (newPartDelay++ == 4) {
+ newPartDelay = 0;
+ ParticleSystem::add(vec2(offset.x - game::SCREEN_WIDTH / 2 + randGet() % game::SCREEN_WIDTH,
+ offset.y + game::SCREEN_HEIGHT / 2 + 100),
+ ParticleType::Drop, 3000, 3);
+ }
+ break;
+ case Weather::Snowy:
+ if (newPartDelay++ == 6) {
+ newPartDelay = 0;
+ ParticleSystem::add(vec2(offset.x - game::SCREEN_WIDTH + randGet() % game::SCREEN_WIDTH * 2,
+ offset.y + game::SCREEN_HEIGHT / 2 + 50),
+ ParticleType::Confetti, 10000, 0);
+ }
+ break;
+ default:
+ break;
+ }
+}
+
+void WeatherSystem::setWeather(const std::string& w)
+{
+ for (int i = 0; i < static_cast<int>(Weather::count); i++) {
+ if (w == weatherStrings[i]) {
+ weather = static_cast<Weather>(i);
+ return;
+ }
+ }
+}
+