implementing trace class.

This commit is contained in:
Andreas Ortmann 2016-09-27 19:32:12 +02:00
parent 56ccdfb1fd
commit 64428d2068
3 changed files with 53 additions and 23 deletions

View file

@ -15,6 +15,8 @@ set(GAME_SRC
util.cpp util.cpp
game.cpp game.cpp
state/object.cpp state/object.cpp
state/explosion.cpp
state/trace.cpp
state/state.cpp state/state.cpp
state/player.cpp state/player.cpp
state/planet.cpp state/planet.cpp

View file

@ -1,28 +1,32 @@
#pragma once #pragma once
/** #include <glm/vec2.hpp>
* Explosion: just an effect which looks good.
*/ namespace game {
class Explosion { /**
public: * Explosion: just an effect which looks good.
enum class Kind { */
MissileExplodesInSpace, // missile explode in free space class Explosion {
MissileAgainstPlanet, // explosion of missile when it hits a planet public:
MissileAgainstShip // bigger explosion: missile hits a ship which explodes with it 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 #endif

View file

@ -0,0 +1,24 @@
#pragma once
#include <glm/vec2.hpp>
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<glm::vec2> points;
};
}