-
Notifications
You must be signed in to change notification settings - Fork 0
/
world.cpp
38 lines (33 loc) · 945 Bytes
/
world.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include "world.h"
#include <algorithm>
World::World() {
// setup world
}
void World::tick(double dt) {
// tick entities
for (Entity *ent : m_entities) {
ent->tick(dt);
}
// collision detection
for (Entity *ent1 : m_entities) {
for (Entity *ent2 : m_entities) {
if (ent1 == ent2) {
continue;
}
bool colliding = ent1->aabb().collides(ent2->aabb(), 5);
bool collidedAlready = std::find(ent1->collisions().begin(), ent1->collisions().end(), ent2)
!= ent1->collisions().end();
if (!colliding && collidedAlready) {
ent1->collisionEnd(ent2);
} else if (colliding && !collidedAlready) {
ent1->collision(ent2);
}
}
}
}
void World::draw() {
// draw entities
for (Entity *ent : m_entities) {
ent->draw();
}
}