aboutsummaryrefslogtreecommitdiffstats
path: root/src/weather.cpp
diff options
context:
space:
mode:
authorClyne Sullivan <tullivan99@gmail.com>2017-04-29 18:28:28 -0400
committerClyne Sullivan <tullivan99@gmail.com>2017-04-29 18:28:28 -0400
commit40d164ea3d8437cd5a06a06d5b89bd938d3dd906 (patch)
treeec22853ca9a18706a3318ea9d16464d9a36a7419 /src/weather.cpp
parent18380eb2e6443c2736b4958b01e7ba2fe2cfa318 (diff)
no more getSystem
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;
+ }
+ }
+}
+