added test script to lauch rockets, nicer explosions.
This commit is contained in:
parent
4712926be2
commit
9ce106c179
11 changed files with 127 additions and 35 deletions
|
|
@ -0,0 +1,17 @@
|
|||
#include "explosion.hpp"
|
||||
|
||||
namespace game {
|
||||
size_t s_id_counter = 0;
|
||||
|
||||
Explosion::Explosion(size_t id, const glm::vec2 &pos, const glm::vec2 &missileVelocity, Hit hit, float maxAge)
|
||||
: id(id)
|
||||
, hit(hit)
|
||||
, position(pos)
|
||||
, missileVelocity(missileVelocity)
|
||||
, age(0.0)
|
||||
, maxAge(maxAge * (1.0 + 0.1*util::randf_0_1()))
|
||||
, maxRadius(0.05)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -12,26 +12,17 @@ namespace game {
|
|||
*/
|
||||
class Explosion {
|
||||
public:
|
||||
Explosion(const glm::vec2 &pos, Hit hit, float maxAge=1.0)
|
||||
: hit(hit)
|
||||
, position(pos)
|
||||
, age(0.0)
|
||||
, maxAge(maxAge * (1.0 + 0.1*util::randf_0_1()))
|
||||
, maxRadius(0.05)
|
||||
{
|
||||
static size_t id_counter = 0;
|
||||
id = id_counter++;
|
||||
}
|
||||
Explosion(size_t id, const glm::vec2 &pos, const glm::vec2 &missileVelocity, Hit hit, float maxAge=1.0);
|
||||
|
||||
const size_t id;
|
||||
const Hit hit; // kind of the explosion depends on the hit type
|
||||
const glm::vec2 position; // position where it starts
|
||||
const glm::vec2 missileVelocity; // impact velocity of the missile
|
||||
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;
|
||||
const float maxRadius; // current radius depends on time.
|
||||
|
||||
size_t id;
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ namespace game {
|
|||
if (dist <= other->ship->radius) {
|
||||
// TODO: collect all hits and return the first one only
|
||||
// TODO: find exact hit position!
|
||||
return Missile::Event(position, player->id, other->id);
|
||||
return Missile::Event(position, velocity, player->id, other->id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -49,7 +49,7 @@ namespace game {
|
|||
if (dist <= planet->radius) {
|
||||
// TODO: collect all hits and return the first one only
|
||||
// TODO: find exact hit position!
|
||||
return Missile::Event(position, planet->id);
|
||||
return Missile::Event(position, velocity, planet->id);
|
||||
}
|
||||
|
||||
dist *= 20.0;
|
||||
|
|
@ -77,9 +77,9 @@ namespace game {
|
|||
// check if distance to center of the universe is getting too big
|
||||
float distToCenter = glm::length(position);
|
||||
if (distToCenter > state->maxMissileDistance()) {
|
||||
return Missile::Event(position, Hit::BorderOfUniverse);
|
||||
return Missile::Event(position, velocity, Hit::BorderOfUniverse);
|
||||
}
|
||||
|
||||
return Missile::Event(position);
|
||||
return Missile::Event(position, velocity);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,23 +22,24 @@ namespace game {
|
|||
// stops existing afterwards.
|
||||
class Event {
|
||||
public:
|
||||
Event(const glm::vec2 &pos)
|
||||
: Event(pos, Hit::Nothing)
|
||||
Event(const glm::vec2 &pos, const glm::vec2 &missileVelocity)
|
||||
: Event(pos, missileVelocity, Hit::Nothing)
|
||||
{
|
||||
}
|
||||
|
||||
Event(const glm::vec2 &pos, Hit hit)
|
||||
: hit(hit), position(pos)
|
||||
Event(const glm::vec2 &pos, const glm::vec2 &missileVelocity, Hit hit)
|
||||
: hit(hit), position(pos), missileVelocity(missileVelocity)
|
||||
{
|
||||
}
|
||||
|
||||
Event(const glm::vec2 &pos, int planetId) : Event(pos, Hit::Planet)
|
||||
Event(const glm::vec2 &pos, const glm::vec2 &missileVelocity, int planetId)
|
||||
: Event(pos, missileVelocity, Hit::Planet)
|
||||
{
|
||||
this->planetId = planetId;
|
||||
}
|
||||
|
||||
Event(const glm::vec2 &pos, int playerIdKiller, int playerIdVictim)
|
||||
: Event(pos, Hit::Ship)
|
||||
Event(const glm::vec2 &pos, const glm::vec2 &missileVelocity, int playerIdKiller, int playerIdVictim)
|
||||
: Event(pos, missileVelocity, Hit::Ship)
|
||||
{
|
||||
this->playerIdKiller = playerIdKiller;
|
||||
this->playerIdVictim = playerIdVictim;
|
||||
|
|
@ -46,6 +47,7 @@ namespace game {
|
|||
|
||||
Hit hit;
|
||||
glm::vec2 position;
|
||||
glm::vec2 missileVelocity;
|
||||
|
||||
// if a player was hit, these are valid.
|
||||
int playerIdKiller;
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@ namespace game {
|
|||
m_defaultEnergy = 10.0;
|
||||
m_maxNumTraces = 10;
|
||||
m_developerMode = devMode;
|
||||
m_nextExplosionId = 0;
|
||||
|
||||
setPlayingFieldCenter(0, 0);
|
||||
|
||||
|
|
@ -441,7 +442,7 @@ namespace game {
|
|||
return;
|
||||
}
|
||||
|
||||
explosions.push_back(new Explosion(evt->position, evt->hit));
|
||||
explosions.push_back(new Explosion(m_nextExplosionId++, evt->position, evt->missileVelocity, evt->hit));
|
||||
}
|
||||
|
||||
void State::advanceTraceAges(float dt)
|
||||
|
|
|
|||
|
|
@ -141,6 +141,7 @@ namespace game {
|
|||
float m_defaultEnergy;
|
||||
int m_nextId;
|
||||
int m_maxNumTraces;
|
||||
size_t m_nextExplosionId;
|
||||
float m_time;
|
||||
bool m_developerMode;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue