diff --git a/extra/docker/Dockerfile b/extra/docker/Dockerfile index 78a11d2..27e1dac 100644 --- a/extra/docker/Dockerfile +++ b/extra/docker/Dockerfile @@ -1,6 +1,6 @@ FROM ubuntu:16.04 -RUN apt-get update && apt-get install -y build-essential libphysfs-dev libboost-dev cmake libsdl2-dev libsdl2-image-dev \ +RUN apt-get update && apt-get install --no-install-recommends -y build-essential libphysfs-dev libboost-dev cmake libsdl2-dev libsdl2-image-dev \ libsdl2-gfx-dev libsdl2-mixer-dev libsdl2-ttf-dev libboost-program-options-dev libutfcpp-dev libbox2d-dev zip gettext RUN mkdir -p /staging/saland diff --git a/src/saland/Game.cpp b/src/saland/Game.cpp index 700b2f7..1dd49bb 100644 --- a/src/saland/Game.cpp +++ b/src/saland/Game.cpp @@ -43,6 +43,7 @@ public: float directionX = 1; float directionY = 1; float velocity = 1.0f; + float timeToLive = 2000.0; std::shared_ptr fired_by; }; @@ -360,6 +361,13 @@ static void UpdateMonster(Monster *entity, float fDeltaTime) { entity->Y = place.y*pixel2unit; } +static void UpdateProjectile(Projectile *entity, float fDeltaTime) { + entity->timeToLive -= fDeltaTime; + if (entity->timeToLive < 0.0f) { + entity->removeMe = true; + } +} + void Game::Update() { Uint32 nowTime = SDL_GetTicks(); Uint32 deltaTime = nowTime - data->lastUpdate; @@ -381,12 +389,21 @@ void Game::Update() { data->human->moveX = deltaX; data->human->moveY = deltaY; UpdateHuman(data->human.get(), deltaTime); - for (auto& entity : data->placeables) { + for (std::shared_ptr& entity : data->placeables) { + if (entity->removeMe) { + continue; + } + Projectile* projectile = dynamic_cast (entity.get()); + if (projectile) { + UpdateProjectile(projectile, deltaTime); + } Monster* monster = dynamic_cast (entity.get()); if (monster) { UpdateMonster(monster, deltaTime); } } + auto& vp = data->placeables; + vp.erase(std::remove_if(std::begin(vp), std::end(vp), [](std::shared_ptr p) { return p->removeMe; }), std::end(vp)); data->center_x = std::round(data->human->X); data->center_y = std::round(data->human->Y); int mousex; diff --git a/src/saland/model/placeables.hpp b/src/saland/model/placeables.hpp index d50ae49..5e588af 100644 --- a/src/saland/model/placeables.hpp +++ b/src/saland/model/placeables.hpp @@ -34,6 +34,7 @@ public: float X = 20.0; float Y = 20.0; float Radius = 16.0; + bool removeMe = false; b2Body* body = nullptr; virtual bool isStatic() {return true; } };