]> git.localhorst.tv Git - space.git/blobdiff - src/world/Universe.cpp
force based movement
[space.git] / src / world / Universe.cpp
index ec307a52eb3fc952e34f2125be6d3250730363d7..6f2e5c18091ff5b4d4cc1c24d1d4e489e6e97ef5 100644 (file)
@@ -1,27 +1,49 @@
 #include "Universe.h"
 
-#include "Sector.h"
-
 #include <cstring>
 #include <memory>
 
 
 namespace space {
 
-Universe::Universe(int w, int h, int sec_w, int sec_h, int numres)
-: w(w)
-, h(h)
-, numres(numres)
-, total(w * h)
-, sec_begin(reinterpret_cast<Sector *>(new char[total * sizeof(Sector)]))
-, sec_end(sec_begin + total) {
-       for (Sector *i = sec_begin; i < sec_end; ++i) {
-               new (i) Sector(sec_w, sec_h, numres);
-       }
+Universe::Universe(Vector<int> size, Vector<int> secSize, Vector<int> areaSize)
+: size(size)
+, secSize(secSize)
+, areaSize(areaSize) {
+
 }
 
 Universe::~Universe() {
-       delete[] reinterpret_cast<char *>(sec_begin);
+
+}
+
+
+Ship *Universe::AddShip(const Ship &s) {
+       ships.emplace_back(s);
+       return &ships.back();
+}
+
+
+void Universe::Update(float delta) {
+       for (Ship &s : ships) {
+               s.Update(delta);
+               while (s.pos.x > areaSize.x) {
+                       s.pos.x -= areaSize.x;
+                       ++s.area.x;
+               }
+               while (s.pos.x < 0) {
+                       s.pos.x += areaSize.x;
+                       --s.area.x;
+               }
+               while (s.pos.y > areaSize.y) {
+                       s.pos.y -= areaSize.y;
+                       ++s.area.y;
+               }
+               while (s.pos.y < 0) {
+                       s.pos.y += areaSize.y;
+                       --s.area.y;
+               }
+       }
 }
 
 }