]> git.localhorst.tv Git - space.git/blob - src/world/Universe.cpp
some cleanup
[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 Entity *Universe::AddEntity(const Entity &e) {
22         entities.emplace_back(e);
23         return &entities.back();
24 }
25
26
27 void Universe::Update(float delta) {
28         for (Entity &e : entities) {
29                 e.Update(delta);
30                 while (e.pos.x > areaSize.x) {
31                         e.pos.x -= areaSize.x;
32                         ++e.area.x;
33                 }
34                 while (e.pos.x < 0) {
35                         e.pos.x += areaSize.x;
36                         --e.area.x;
37                 }
38                 while (e.pos.y > areaSize.y) {
39                         e.pos.y -= areaSize.y;
40                         ++e.area.y;
41                 }
42                 while (e.pos.y < 0) {
43                         e.pos.y += areaSize.y;
44                         --e.area.y;
45                 }
46         }
47 }
48
49 }