From 2dc18a98db4ab5007e262445118c92e34a94cabb Mon Sep 17 00:00:00 2001 From: "Eevee (Evelyn Woods)" Date: Sun, 20 Sep 2020 01:05:24 -0600 Subject: [PATCH] Finally fix pushing a sliding block --- js/game.js | 17 ++++++++++------- js/tiletypes.js | 1 - 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/js/game.js b/js/game.js index 5ab31c0..afcf6b1 100644 --- a/js/game.js +++ b/js/game.js @@ -365,6 +365,10 @@ export class Level { if (! actor.cell) continue; + // Clear any old decisions ASAP. Note that this prop is only used internally within a + // single tic, so it doesn't need to be undoable + actor.decision = null; + // Decrement the cooldown here, but don't check it quite yet, // because stepping on cells in the next block might reset it if (actor.movement_cooldown > 0) { @@ -395,10 +399,6 @@ export class Level { // Second pass: actors decide their upcoming movement simultaneously for (let actor of this.actors) { - // Note that this prop is only used internally within a single iteration of this loop, - // so it doesn't need to be undoable - actor.decision = null; - if (! actor.cell) continue; @@ -558,7 +558,6 @@ export class Level { if (! actor.decision) continue; - this.set_actor_direction(actor, actor.decision); let old_cell = actor.cell; this.attempt_step(actor, actor.decision); @@ -576,7 +575,6 @@ export class Level { } if (could_push && actor.can_push(tile)) { // Block slapping: you can shove a block by walking past it sideways - this.set_actor_direction(tile, dir2); this.attempt_step(tile, dir2); } } @@ -627,6 +625,12 @@ export class Level { // Try to move the given actor one tile in the given direction and update // their cooldown. Return true if successful. attempt_step(actor, direction) { + // In mid-movement, we can't even change direction! + if (actor.movement_cooldown > 0) + return false; + + this.set_actor_direction(actor, direction); + if (actor.stuck) return false; @@ -692,7 +696,6 @@ export class Level { // This time make a copy, since we're modifying the contents of the cell for (let tile of Array.from(goal_cell)) { if (actor.can_push(tile)) { - this.set_actor_direction(tile, direction); this.attempt_step(tile, direction); } } diff --git a/js/tiletypes.js b/js/tiletypes.js index 8729e38..3360e29 100644 --- a/js/tiletypes.js +++ b/js/tiletypes.js @@ -720,7 +720,6 @@ const TILE_TYPES = { for (let actor of level.actors) { // TODO generify somehow?? if (actor.type.name === 'tank_yellow') { - level.set_actor_direction(actor, other.direction); level.attempt_step(actor, other.direction); } }