aboutsummaryrefslogtreecommitdiff
path: root/BlueTileBehavior.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'BlueTileBehavior.cpp')
-rw-r--r--BlueTileBehavior.cpp22
1 files changed, 13 insertions, 9 deletions
diff --git a/BlueTileBehavior.cpp b/BlueTileBehavior.cpp
index 487398a..b0716bc 100644
--- a/BlueTileBehavior.cpp
+++ b/BlueTileBehavior.cpp
@@ -9,25 +9,29 @@ using namespace std;
BlueTileBehavior BlueTileBehavior::instance { BlueTileBehavior::type };
-void BlueTileBehavior::step(Artist & artist) {
+void BlueTileBehavior::step(Artist * artist) {
this->interactions++;
- if (this->interactions > 1) return;
+ if (dx != 0 || dy != 0) return;
+ if (artist == nullptr) return;
- if (artist.data.vx == 0) dx = 1;
- if (artist.data.vy == 0) dy = 1;
+ if (artist->data.vx == 0) dx = 1;
+ if (artist->data.vy == 0) dy = 1;
}
-void BlueTileBehavior::update_neighbor(Tile * tile) {
- if (tile == nullptr) return;
+void BlueTileBehavior::update_neighbor(Tile & here, int dx, int dy) {
+ if (dx == 0 && dy == 0) return;
+ Tile * neighbor = here.get_neighbor(dx, dy);
+ if (neighbor == &here) return;
+ if (neighbor == nullptr) return;
- tile->set_type(BlueTileBehavior::type);
+ neighbor->set_type(BlueTileBehavior::type);
}
void BlueTileBehavior::update(Tile & tile) {
if (this->interactions < 1) return;
- this->update_neighbor(tile.get_neighbor(this->dx, this->dy));
- this->update_neighbor(tile.get_neighbor(-this->dx, -this->dy));
+ this->update_neighbor(tile, this->dx, this->dy);
+ this->update_neighbor(tile, -this->dx, -this->dy);
tile.set_type(YellowTileBehavior::type);
}