aboutsummaryrefslogtreecommitdiff
path: root/backend/Dungeon.cpp
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-10-31 14:34:01 +0100
committerLoek Le Blansch <loek@pipeframe.xyz>2024-10-31 14:34:01 +0100
commit82dcf9e2dd3596b28ef846f4a217dc19c21cf781 (patch)
treef99f556afa6affeb0fe6a2a1c107862ca76f9e66 /backend/Dungeon.cpp
parentf8d8d7499ba4433678db2a68fb1cae74448ca31e (diff)
more WIP
Diffstat (limited to 'backend/Dungeon.cpp')
-rw-r--r--backend/Dungeon.cpp44
1 files changed, 34 insertions, 10 deletions
diff --git a/backend/Dungeon.cpp b/backend/Dungeon.cpp
index d4df1ef..b1e89ba 100644
--- a/backend/Dungeon.cpp
+++ b/backend/Dungeon.cpp
@@ -1,17 +1,41 @@
#include "Location.h"
#include "Dungeon.h"
#include "RNG.h"
+#include "backend/ListIterator.h"
+#include "print.h"
-void Dungeon::update() {
- // TODO: iterators are broken (!????)
- // for (Location * location : this->locations) {
- // for (Enemy * enemy : location->get_enemies()) {
- // if (RNG::get().rand_double() < 0.5) continue;
- // Direction direction = random_direction(*location);
- // // location->remove_enemy(enemy); // TODO: this breaks the for loop
- // location->get_exit(direction)->add_enemy(enemy);
- // }
- // }
+void Dungeon::update(Location * player_location) {
+ this->player_location = player_location;
+
+ ListRange<Enemy *> enemies = player_location->get_enemies();
+
+ if (enemies.size() > 0)
+ this->update_attacks(enemies);
+ else
+ this->update_movement();
+}
+
+void Dungeon::update_attacks(ListRange<Enemy *> & enemies) {
+ printf("TODO: de vijanden vallen aan!\n");
+}
+
+void Dungeon::update_movement() {
+ bool moved = false;
+ for (Location * location : this->locations) {
+ for (Enemy * enemy : location->get_enemies()) {
+ if (RNG::get().rand_double() < 0.5) continue;
+
+ if (!moved)
+ lprtf(":: De vijanden bewegen ::\n");
+ Direction direction = random_direction(*location);
+ location->remove_enemy(enemy);
+ Location * new_location = location->get_exit(direction);
+ new_location->add_enemy(enemy);
+ if (player_location == new_location)
+ lprtf("%s komt de huidige locatie binnen\n", enemy->get_name().c_str());
+ moved = true;
+ }
+ }
}
void Dungeon::add_location(Location * location) {