adding small stuff to limit traces

This commit is contained in:
Andreas Ortmann 2016-09-28 00:13:03 +02:00
parent bfa7be68a9
commit 1e90a1c9c8
5 changed files with 31 additions and 8 deletions

View file

@ -49,7 +49,7 @@ namespace game {
if (dist <= planet->radius) { if (dist <= planet->radius) {
// TODO: collect all hits and return the first one only // TODO: collect all hits and return the first one only
// TODO: find exact hit position! // TODO: find exact hit position!
return Missile::Event(position, Hit::Planet); return Missile::Event(position, planet->id);
} }
dist *= 20.0; dist *= 20.0;

View file

@ -22,7 +22,8 @@ namespace game {
// stops existing afterwards. // stops existing afterwards.
class Event { class Event {
public: public:
Event(const glm::vec2 &pos) : Event(pos, Hit::Nothing) Event(const glm::vec2 &pos)
: Event(pos, Hit::Nothing)
{ {
} }
@ -31,6 +32,11 @@ namespace game {
{ {
} }
Event(const glm::vec2 &pos, int planetId) : Event(pos, Hit::Planet)
{
this->planetId = planetId;
}
Event(const glm::vec2 &pos, int playerIdKiller, int playerIdVictim) Event(const glm::vec2 &pos, int playerIdKiller, int playerIdVictim)
: Event(pos, Hit::Ship) : Event(pos, Hit::Ship)
{ {
@ -41,8 +47,12 @@ namespace game {
Hit hit; Hit hit;
glm::vec2 position; glm::vec2 position;
// if a player was hit, these are valid.
int playerIdKiller; int playerIdKiller;
int playerIdVictim; int playerIdVictim;
// if a planet was hit, this is valid
int planetId;
}; };
Missile(Player *player, const glm::vec2 &pos, float angle, float speed); Missile(Player *player, const glm::vec2 &pos, float angle, float speed);

View file

@ -21,19 +21,20 @@ namespace game {
Sun Sun
}; };
Planet(const glm::vec2 &pos, float r) : Planet(pos, r, Material::Rock) Planet(const glm::vec2 &pos, int id, float r) : Planet(pos, id, r, Material::Rock)
{ {
} }
Planet(const glm::vec2 &pos, float r, Material mat) Planet(const glm::vec2 &pos, int id, float r, Material mat)
: Object(pos, r) : Object(pos, r)
, id(id)
, material(mat) , material(mat)
, seed(rand()) , seed(rand())
{ {
} }
// nice for rendering attributes int id;
Material material; Material material; // for rendering and physics (can fly through sun and outer gas planets)
int seed; int seed; // just for rendering variation
}; };
} }

View file

@ -25,6 +25,7 @@ namespace game {
m_maxMissileDistance = 2.0; m_maxMissileDistance = 2.0;
m_playerRespawnTime = 2.0; m_playerRespawnTime = 2.0;
m_defaultEnergy = 10.0; m_defaultEnergy = 10.0;
m_maxNumTraces = 10;
bool planetsOnCircle = false; bool planetsOnCircle = false;
@ -45,7 +46,7 @@ namespace game {
} }
} while(glm::length(pos) < 0.2 && tries++ < 1000); } while(glm::length(pos) < 0.2 && tries++ < 1000);
planets.push_back(new Planet(pos, 0.03 + 0.07*util::randf_0_1())); planets.push_back(new Planet(pos, i, 0.03 + 0.07*util::randf_0_1()));
} }
} }
@ -290,6 +291,16 @@ namespace game {
void State::addTrace(Trace *trace) void State::addTrace(Trace *trace)
{ {
//int count = 0;
//for (Trace *old : traces) {
// if (old->playerId == trace->playerId) {
// count++;
// }
//}
//if (count > m_maxNumTraces) {
//}
traces.push_back(trace); traces.push_back(trace);
} }

View file

@ -111,5 +111,6 @@ namespace game {
float m_playerRespawnTime; float m_playerRespawnTime;
float m_shipRadius; float m_shipRadius;
float m_defaultEnergy; float m_defaultEnergy;
int m_maxNumTraces;
}; };
}; };