From 56ccdfb1fdf4f1d9370deac0eee8a6bcf9ffaee1 Mon Sep 17 00:00:00 2001 From: Andreas Ortmann Date: Tue, 27 Sep 2016 19:26:16 +0200 Subject: [PATCH 1/2] adding explosion stuff, adding trace file. --- game/state/explosion.hpp | 23 +++++++++++++++++------ game/state/trace.cpp | 0 game/state/trace.hpp | 0 3 files changed, 17 insertions(+), 6 deletions(-) create mode 100644 game/state/trace.cpp create mode 100644 game/state/trace.hpp diff --git a/game/state/explosion.hpp b/game/state/explosion.hpp index 2cf92ef..9a37296 100644 --- a/game/state/explosion.hpp +++ b/game/state/explosion.hpp @@ -1,17 +1,28 @@ #pragma once -#if 0 +/** + * Explosion: just an effect which looks good. + */ class Explosion { public: enum class Kind { - Normal, - MissileWithShip + MissileExplodesInSpace, // missile explode in free space + MissileAgainstPlanet, // explosion of missile when it hits a planet + MissileAgainstShip // bigger explosion: missile hits a ship which explodes with it }; - glm::vec2 position; + Explosion(const glm::vec2 &pos, Kind kind, float maxAge=1.0) + : position(pos), kind(kind), age(0.0), maxAge(maxAge) + { + } - Explosion(Kind kind); + const Kind kind; // kind of the explosion + const glm::vec2 position; // position where it starts + float age; // age (in seconsd) of the explosion -public: + // age (in seconds) when the explosion is not visible + // anymore and will disappear afterwards + const float maxAge; }; + #endif diff --git a/game/state/trace.cpp b/game/state/trace.cpp new file mode 100644 index 0000000..e69de29 diff --git a/game/state/trace.hpp b/game/state/trace.hpp new file mode 100644 index 0000000..e69de29 From 64428d2068be102fd48fc89c2ab88b16bba0b090 Mon Sep 17 00:00:00 2001 From: Andreas Ortmann Date: Tue, 27 Sep 2016 19:32:12 +0200 Subject: [PATCH 2/2] implementing trace class. --- game/CMakeLists.txt | 2 ++ game/state/explosion.hpp | 50 ++++++++++++++++++++++------------------ game/state/trace.hpp | 24 +++++++++++++++++++ 3 files changed, 53 insertions(+), 23 deletions(-) diff --git a/game/CMakeLists.txt b/game/CMakeLists.txt index c157538..b2f36de 100644 --- a/game/CMakeLists.txt +++ b/game/CMakeLists.txt @@ -15,6 +15,8 @@ set(GAME_SRC util.cpp game.cpp state/object.cpp + state/explosion.cpp + state/trace.cpp state/state.cpp state/player.cpp state/planet.cpp diff --git a/game/state/explosion.hpp b/game/state/explosion.hpp index 9a37296..66c234f 100644 --- a/game/state/explosion.hpp +++ b/game/state/explosion.hpp @@ -1,28 +1,32 @@ #pragma once -/** - * Explosion: just an effect which looks good. - */ -class Explosion { -public: - enum class Kind { - MissileExplodesInSpace, // missile explode in free space - MissileAgainstPlanet, // explosion of missile when it hits a planet - MissileAgainstShip // bigger explosion: missile hits a ship which explodes with it +#include + +namespace game { + /** + * Explosion: just an effect which looks good. + */ + class Explosion { + public: + enum class Kind { + MissileExplodesInSpace, // missile explode in free space + MissileAgainstPlanet, // explosion of missile when it hits a planet + MissileAgainstShip // bigger explosion: missile hits a ship which explodes with it + }; + + Explosion(const glm::vec2 &pos, Kind kind, float maxAge=1.0) + : position(pos), kind(kind), age(0.0), maxAge(maxAge) + { + } + + const Kind kind; // kind of the explosion + const glm::vec2 position; // position where it starts + float age; // age (in seconsd) of the explosion + + // age (in seconds) when the explosion is not visible + // anymore and will disappear afterwards + const float maxAge; }; - - Explosion(const glm::vec2 &pos, Kind kind, float maxAge=1.0) - : position(pos), kind(kind), age(0.0), maxAge(maxAge) - { - } - - const Kind kind; // kind of the explosion - const glm::vec2 position; // position where it starts - float age; // age (in seconsd) of the explosion - - // age (in seconds) when the explosion is not visible - // anymore and will disappear afterwards - const float maxAge; -}; +} #endif diff --git a/game/state/trace.hpp b/game/state/trace.hpp index e69de29..5c7f050 100644 --- a/game/state/trace.hpp +++ b/game/state/trace.hpp @@ -0,0 +1,24 @@ +#pragma once + +#include + +namespace game { + /* + * Trace of a missile through the space. + * Useful for rendering sth. like a smoke trail to follow the rocket. + */ + class Trace { + public: + Trace(const glm::vec2 &startPoint) + { + points.push_back(startPoint); + } + + void addPoint(const glm::vec2 &p) + { + points.push_back(p); + } + + std::vector points; + }; +}