From 1e90a1c9c8f8ca3cf7e2e760d1b499f45ef2544a Mon Sep 17 00:00:00 2001 From: Andreas Ortmann Date: Wed, 28 Sep 2016 00:13:03 +0200 Subject: [PATCH] adding small stuff to limit traces --- game/state/missile.cpp | 2 +- game/state/missile.hpp | 12 +++++++++++- game/state/planet.hpp | 11 ++++++----- game/state/state.cpp | 13 ++++++++++++- game/state/state.hpp | 1 + 5 files changed, 31 insertions(+), 8 deletions(-) diff --git a/game/state/missile.cpp b/game/state/missile.cpp index 08a04b7..cbc3e58 100644 --- a/game/state/missile.cpp +++ b/game/state/missile.cpp @@ -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, Hit::Planet); + return Missile::Event(position, planet->id); } dist *= 20.0; diff --git a/game/state/missile.hpp b/game/state/missile.hpp index 2763fe7..c7aa1df 100644 --- a/game/state/missile.hpp +++ b/game/state/missile.hpp @@ -22,7 +22,8 @@ namespace game { // stops existing afterwards. class Event { 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(pos, Hit::Ship) { @@ -41,8 +47,12 @@ namespace game { Hit hit; glm::vec2 position; + // if a player was hit, these are valid. int playerIdKiller; int playerIdVictim; + + // if a planet was hit, this is valid + int planetId; }; Missile(Player *player, const glm::vec2 &pos, float angle, float speed); diff --git a/game/state/planet.hpp b/game/state/planet.hpp index 38f02b6..e6ff6e7 100644 --- a/game/state/planet.hpp +++ b/game/state/planet.hpp @@ -21,19 +21,20 @@ namespace game { 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) + , id(id) , material(mat) , seed(rand()) { } - // nice for rendering attributes - Material material; - int seed; + int id; + Material material; // for rendering and physics (can fly through sun and outer gas planets) + int seed; // just for rendering variation }; } diff --git a/game/state/state.cpp b/game/state/state.cpp index e76e23e..fd76907 100644 --- a/game/state/state.cpp +++ b/game/state/state.cpp @@ -25,6 +25,7 @@ namespace game { m_maxMissileDistance = 2.0; m_playerRespawnTime = 2.0; m_defaultEnergy = 10.0; + m_maxNumTraces = 10; bool planetsOnCircle = false; @@ -45,7 +46,7 @@ namespace game { } } 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) { + //int count = 0; + //for (Trace *old : traces) { + // if (old->playerId == trace->playerId) { + // count++; + // } + //} + + //if (count > m_maxNumTraces) { + //} + traces.push_back(trace); } diff --git a/game/state/state.hpp b/game/state/state.hpp index 7128966..88718cb 100644 --- a/game/state/state.hpp +++ b/game/state/state.hpp @@ -111,5 +111,6 @@ namespace game { float m_playerRespawnTime; float m_shipRadius; float m_defaultEnergy; + int m_maxNumTraces; }; };