From: Daniel Karbach Date: Sun, 5 Jan 2014 17:36:45 +0000 (+0100) Subject: added resources X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=7bf949b332c410c6909fe80d9fc0ba2200f4ef19;p=space.git added resources --- diff --git a/src/app/Application.cpp b/src/app/Application.cpp index b69cc85..9f78eae 100644 --- a/src/app/Application.cpp +++ b/src/app/Application.cpp @@ -31,7 +31,9 @@ Application::Application(Canvas &c) , last(SDL_GetTicks()) , running(false) , paused(false) { - + univ.AddResource(Resource("Liquid Hydrogen", 70)); + univ.AddResource(Resource("Liquid Qxygen", 1141)); + univ.AddResource(Resource("Water", 999)); } diff --git a/src/world/Resource.cpp b/src/world/Resource.cpp index ca2440c..24cc28b 100644 --- a/src/world/Resource.cpp +++ b/src/world/Resource.cpp @@ -4,14 +4,14 @@ namespace space { Resource::Resource() -: id(-1) -, name(nullptr) { +: Resource("Nullpointerium", 1) { } -Resource::Resource(int id, const char *name) -: id(id) -, name(name) { +Resource::Resource(const char *name, float dens) +: id(-1) +, name(name) +, density(dens) { } diff --git a/src/world/Resource.h b/src/world/Resource.h index 45de344..29d7d15 100644 --- a/src/world/Resource.h +++ b/src/world/Resource.h @@ -7,15 +7,12 @@ class Resource { public: Resource(); - Resource(int id, const char *name); + Resource(const char *name, float density); public: - int ID() const { return id; } - const char *Name() const { return name; } - -private: int id; const char *name; + float density; }; diff --git a/src/world/Universe.cpp b/src/world/Universe.cpp index c5bb915..0866af3 100644 --- a/src/world/Universe.cpp +++ b/src/world/Universe.cpp @@ -23,6 +23,12 @@ Ship *Universe::AddShip(const Ship &s) { return &ships.back(); } +int Universe::AddResource(const Resource &r) { + resources.emplace_back(r); + resources.back().id = resources.size(); + return resources.back(); +} + void Universe::Update(float delta) { for (Ship &s : ships) { diff --git a/src/world/Universe.h b/src/world/Universe.h index 18db4dc..5b3fcca 100644 --- a/src/world/Universe.h +++ b/src/world/Universe.h @@ -5,6 +5,7 @@ #include "../graphics/Vector.h" #include +#include namespace space { @@ -70,11 +71,15 @@ public: Ship *AddShip(const Ship &); const std::list &Ships() const { return ships; } + int AddResource(const Resource &); + const Resource &GetResource(int id) const { return resources[id]; } + public: void Update(float deltaT); private: std::list ships; + std::vector resources; };