aboutsummaryrefslogtreecommitdiff
path: root/YellowTileBehavior.cpp
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-10-13 17:43:36 +0200
committerLoek Le Blansch <loek@pipeframe.xyz>2024-10-13 17:43:36 +0200
commitfeaf272efad381414c6ee76c0cd4bf929e8087ae (patch)
treecbdf4ffc206eba701ce39871562a60e889a9ccab /YellowTileBehavior.cpp
parent4343c7cd36a19c03c4885dbf15aaa22fe51b4fe0 (diff)
WIP
Diffstat (limited to 'YellowTileBehavior.cpp')
-rw-r--r--YellowTileBehavior.cpp35
1 files changed, 32 insertions, 3 deletions
diff --git a/YellowTileBehavior.cpp b/YellowTileBehavior.cpp
index 2999229..4e0b7f1 100644
--- a/YellowTileBehavior.cpp
+++ b/YellowTileBehavior.cpp
@@ -1,17 +1,46 @@
#include <memory>
+#include <random>
#include "YellowTileBehavior.h"
+#include "Tile.h"
+#include "Museum.h"
+using std::uniform_int_distribution;
+using std::uniform_real_distribution;
+using std::random_device;
+using std::mt19937;
using namespace std;
YellowTileBehavior YellowTileBehavior::instance {"Y"};
-void YellowTileBehavior::run(Tile &) {
- printf("TODO: %s\n", __PRETTY_FUNCTION__);
+random_device dev{};
+mt19937 rng(dev());
+uniform_int_distribution<int> random_bool(0, 1);
+uniform_real_distribution<float> random_float(-1, 1);
+
+void YellowTileBehavior::update(Tile & tile) {
+ this->steps_total += this->steps;
+ for (unsigned int i = 0; i < this->steps; i++) {
+ ArtistData new_data = {
+ .x = static_cast<float>(tile.x),
+ .y = static_cast<float>(tile.y),
+ };
+ float velocity = random_float(rng);
+ random_bool(rng) ? new_data.vx = velocity : new_data.vy = velocity;
+ this->museum->people.add_artist(new_data);
+ }
+ this->steps = 0;
+
+ if (this->steps_total >= 2) {
+ TileData new_data = tile.data;
+ new_data.type = "G";
+ tile.set_data(new_data);
+ }
}
-unique_ptr<TileBehaviorStrategy> YellowTileBehavior::clone() {
+unique_ptr<TileBehaviorStrategy> YellowTileBehavior::clone(Museum & museum) {
auto instance = new YellowTileBehavior();
+ instance->museum = &museum;
return unique_ptr<TileBehaviorStrategy>(instance);
}