]> git.localhorst.tv Git - space.git/blob - src/world/Universe.cpp
force based movement
[space.git] / src / world / Universe.cpp
1 #include "Universe.h"
2
3 #include <cstring>
4 #include <memory>
5
6
7 namespace space {
8
9 Universe::Universe(Vector<int> size, Vector<int> secSize, Vector<int> areaSize)
10 : size(size)
11 , secSize(secSize)
12 , areaSize(areaSize) {
13
14 }
15
16 Universe::~Universe() {
17
18 }
19
20
21 Ship *Universe::AddShip(const Ship &s) {
22         ships.emplace_back(s);
23         return &ships.back();
24 }
25
26
27 void Universe::Update(float delta) {
28         for (Ship &s : ships) {
29                 s.Update(delta);
30                 while (s.pos.x > areaSize.x) {
31                         s.pos.x -= areaSize.x;
32                         ++s.area.x;
33                 }
34                 while (s.pos.x < 0) {
35                         s.pos.x += areaSize.x;
36                         --s.area.x;
37                 }
38                 while (s.pos.y > areaSize.y) {
39                         s.pos.y -= areaSize.y;
40                         ++s.area.y;
41                 }
42                 while (s.pos.y < 0) {
43                         s.pos.y += areaSize.y;
44                         --s.area.y;
45                 }
46         }
47 }
48
49 }