aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorClyne Sullivan <tullivan99@gmail.com>2017-01-06 08:51:53 -0500
committerClyne Sullivan <tullivan99@gmail.com>2017-01-06 08:51:53 -0500
commitefcf1a88cd0d0bee3973705b5975827be97f5a3a (patch)
treef458ac0c456e09ed236c7c93379a371617325ead /include
parentcbd154a4834f56146dbe744ee2d2c6dccc04c5cb (diff)
particles, rain
Diffstat (limited to 'include')
-rw-r--r--include/common.hpp4
-rw-r--r--include/particle.hpp42
-rw-r--r--include/texture.hpp1
-rw-r--r--include/weather.hpp67
-rw-r--r--include/world.hpp39
5 files changed, 116 insertions, 37 deletions
diff --git a/include/common.hpp b/include/common.hpp
index 19af420..71039c7 100644
--- a/include/common.hpp
+++ b/include/common.hpp
@@ -91,11 +91,11 @@ struct vec2 {
}
template<typename T>
- const vec2 operator+(const T &n) {
+ vec2 operator+(T n) const {
return vec2 (x + n, y + n);
}
- const vec2 operator+(const vec2 &v) {
+ vec2 operator+(const vec2 &v) {
return vec2 (x + v.x, y + v.y);
}
diff --git a/include/particle.hpp b/include/particle.hpp
new file mode 100644
index 0000000..d9aa29f
--- /dev/null
+++ b/include/particle.hpp
@@ -0,0 +1,42 @@
+#ifndef PARTICLE_HPP_
+#define PARTICLE_HPP_
+
+#include <common.hpp>
+
+#include <list>
+
+#include <entityx/entityx.h>
+
+enum class ParticleType : char {
+ Drop,
+ Confetti
+};
+
+struct Particle {
+ vec2 location;
+ vec2 velocity;
+ ParticleType type;
+ int timeLeft;
+
+ Particle(vec2 p, ParticleType t = ParticleType::Drop)
+ : location(p), type(t), timeLeft(3000) {} // TODO times
+} __attribute__ ((packed));
+
+class ParticleSystem : public entityx::System<ParticleSystem> {
+private:
+ std::vector<Particle> parts;
+ bool max;
+
+public:
+ ParticleSystem(int count = 1024, bool m = false);
+
+ void add(const vec2& pos, const ParticleType& type);
+ void addMultiple(const int& count, const ParticleType& type, std::function<vec2(void)> f);
+
+ void render(void) const;
+ void update(entityx::EntityManager &en, entityx::EventManager &ev, entityx::TimeDelta dt) override;
+
+ int getCount(void) const;
+};
+
+#endif // PARTICLE_HPP_
diff --git a/include/texture.hpp b/include/texture.hpp
index e9082b3..878955e 100644
--- a/include/texture.hpp
+++ b/include/texture.hpp
@@ -91,6 +91,7 @@ namespace Colors {
extern ColorTex white; /**< A solid white texture. */
extern ColorTex black; /**< A solid black texture. */
extern ColorTex red; /**< A solid red texture. */
+ extern ColorTex blue; /**< A solid blue texture. */
/**
* Creates the colors.
diff --git a/include/weather.hpp b/include/weather.hpp
new file mode 100644
index 0000000..f7b53f1
--- /dev/null
+++ b/include/weather.hpp
@@ -0,0 +1,67 @@
+#ifndef WEATHER_HPP_
+#define WEATHER_HPP_
+
+#include <entityx/entityx.h>
+
+#include <common.hpp>
+#include <particle.hpp>
+
+/**
+ * The weather type enum.
+ * This enum contains every type of weather currently implemented in the game.
+ * Weather is set by the world somewhere.
+ */
+enum class Weather : unsigned char {
+ Sunny = 0, /**< Sunny */
+ Rainy, /**< Rain */
+ Snowy, /**< Snow */
+ count
+};
+
+constexpr const char *weatherStrings[] = {
+ "Sunny",
+ "Rainy",
+ "Snowy"
+};
+
+class WeatherSystem : public entityx::System<WeatherSystem> {
+private:
+ Weather weather;
+
+public:
+ WeatherSystem(Weather w = Weather::Sunny)
+ : weather(w) {}
+
+ void update(entityx::EntityManager &en, entityx::EventManager &ev, entityx::TimeDelta dt) override {
+ (void)en;
+ (void)ev;
+ (void)dt;
+
+ static auto& partSystem = *game::engine.getSystem<ParticleSystem>();
+
+ switch (weather) {
+ case Weather::Sunny:
+ break;
+ case Weather::Rainy:
+ partSystem.add(vec2(offset.x - game::SCREEN_WIDTH / 2 + randGet() % game::SCREEN_WIDTH,
+ offset.y + game::SCREEN_HEIGHT / 2 + 100),
+ ParticleType::Drop);
+ break; // TODO
+ case Weather::Snowy:
+ break; // TODO
+ default:
+ break;
+ }
+ }
+
+ inline void 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;
+ }
+ }
+ }
+};
+
+#endif // WEATHER_HPP_
diff --git a/include/world.hpp b/include/world.hpp
index 8864d30..14c64d0 100644
--- a/include/world.hpp
+++ b/include/world.hpp
@@ -28,36 +28,16 @@ enum class WorldBGType : unsigned int {
};
/**
- * The weather type enum.
- * This enum contains every type of weather currently implemented in the game.
- * Weather is set by the world somewhere.
- */
-enum class WorldWeather : unsigned char {
- None = 0, /**< None (sunny) */
- Rain, /**< Rain */
- Snowy /**< Snow */
-};
-
-/**
- * Strings to represent each type of weather.
- */
-constexpr const char* WorldWeatherString[3] = {
- "None",
- "Rainy",
- "Snowy"
-};
-
-/**
* The line structure.
* This structure is used to store the world's ground, stored in vertical
* lines. Dirt color and grass properties are also kept track of here.
*/
-typedef struct {
+struct WorldData {
bool grassUnpressed; /**< squishes grass if false */
float grassHeight[2]; /**< height of the two grass blades */
float groundHeight; /**< height of the 'line' */
unsigned char groundColor; /**< a value that affects the ground's color */
-} WorldData;
+} __attribute__ ((packed));
/**
* Defines how many game ticks it takes to go from day to night or vice versa.
@@ -130,11 +110,6 @@ private:
WorldData2 world;
/**
- * The current state of weather in the world.
- */
- WorldWeather weather;
-
- /**
* SDL's object for handling the background music.
*/
Mix_Music *bgmObj;
@@ -176,22 +151,16 @@ public:
inline float getWidth(void) const
{ return world.startX * -2.0f; }
+ float isAboveGround(const vec2& p) const;
+
void receive(const BGMToggleEvent &bte);
void update(entityx::EntityManager &en, entityx::EventManager &ev, entityx::TimeDelta dt) override;
void render(void);
- inline const std::string getWeatherStr(void) const
- { return WorldWeatherString[static_cast<int>(weather)]; }
-
- inline const WorldWeather& getWeatherId(void) const
- { return weather; }
-
inline const std::string& getXMLFile(void) const
{ return currentXMLFile; }
- void setWeather(const std::string &s);
-
void detect(entityx::TimeDelta dt);
void goWorldLeft(Position& p);