diff --git a/js/game.js b/js/game.js index f57a030..66d89b9 100644 --- a/js/game.js +++ b/js/game.js @@ -792,6 +792,7 @@ export class Level extends LevelInterface { } this._swap_players(); + this._do_post_actor_phase(); // Wire updates every frame, which means thrice per tic this._do_wire_phase(); @@ -805,6 +806,7 @@ export class Level extends LevelInterface { _advance_tic_lynx() { this._do_decision_phase(); this._do_combined_action_phase(3); + this._do_post_actor_phase(); this._do_wire_phase(); this._do_wire_phase(); this._do_wire_phase(); @@ -817,16 +819,19 @@ export class Level extends LevelInterface { _advance_tic_lynx60() { this._do_decision_phase(true); this._do_combined_action_phase(1, true); + this._do_post_actor_phase(); this._do_wire_phase(); this.frame_offset = 1; this._do_decision_phase(true); this._do_combined_action_phase(1, true); + this._do_post_actor_phase(); this._do_wire_phase(); this.frame_offset = 2; this._do_decision_phase(); this._do_combined_action_phase(1); + this._do_post_actor_phase(); this._do_wire_phase(); this.frame_offset = 0; @@ -846,6 +851,7 @@ export class Level extends LevelInterface { this._do_decision_phase(! is_decision_frame); this._do_combined_action_phase(1, ! is_decision_frame); + this._do_post_actor_phase(); this._do_wire_phase(); if (this.frame_offset === 2) { @@ -903,6 +909,7 @@ export class Level extends LevelInterface { } this.sfx.set_player_position(this.player.cell); + this.pending_green_toggle = false; } // Decision phase: all actors decide on their movement "simultaneously" @@ -1153,6 +1160,31 @@ export class Level extends LevelInterface { } } + _do_post_actor_phase() { + if (this.pending_green_toggle) { + // Swap green floors and walls + // TODO could probably make this more compact for undo purposes + for (let cell of this.linear_cells) { + let terrain = cell.get_terrain(); + if (terrain.type.name === 'green_floor') { + this.transmute_tile(terrain, 'green_wall'); + } + else if (terrain.type.name === 'green_wall') { + this.transmute_tile(terrain, 'green_floor'); + } + + let item = cell.get_item(); + if (item && item.type.name === 'green_chip') { + this.transmute_tile(item, 'green_bomb'); + } + else if (item && item.type.name === 'green_bomb') { + this.transmute_tile(item, 'green_chip'); + } + } + this.pending_green_toggle = false; + } + } + _do_cleanup_phase() { // Lynx compat: Any blue tank that still has the reversal flag set here, but is in motion, // should ignore it. Unfortunately this has to be done as its own pass (as it is in Lynx!) diff --git a/js/tiletypes.js b/js/tiletypes.js index b551b73..04e4b21 100644 --- a/js/tiletypes.js +++ b/js/tiletypes.js @@ -1335,6 +1335,13 @@ const TILE_TYPES = { }, green_floor: { layer: LAYERS.terrain, + blocks(me, level, other) { + // Toggle walls don't toggle until the end of the frame, but the collision takes into + // account whether a toggle is coming + return ( + level.pending_green_toggle && + (other.type.collision_mask & COLLISION.all_but_ghost)); + }, on_gray_button(me, level) { level.transmute_tile(me, 'green_wall'); }, @@ -1344,7 +1351,12 @@ const TILE_TYPES = { }, green_wall: { layer: LAYERS.terrain, - blocks_collision: COLLISION.all_but_ghost, + blocks(me, level, other) { + // Same as above + return ( + ! level.pending_green_toggle && + (other.type.collision_mask & COLLISION.all_but_ghost)); + }, on_gray_button(me, level) { level.transmute_tile(me, 'green_floor'); }, @@ -2034,25 +2046,7 @@ const TILE_TYPES = { button_green: { layer: LAYERS.terrain, do_button(level) { - // Swap green floors and walls - // TODO could probably make this more compact for undo purposes - for (let cell of level.linear_cells) { - let terrain = cell.get_terrain(); - if (terrain.type.name === 'green_floor') { - level.transmute_tile(terrain, 'green_wall'); - } - else if (terrain.type.name === 'green_wall') { - level.transmute_tile(terrain, 'green_floor'); - } - - let item = cell.get_item(); - if (item && item.type.name === 'green_chip') { - level.transmute_tile(item, 'green_bomb'); - } - else if (item && item.type.name === 'green_bomb') { - level.transmute_tile(item, 'green_chip'); - } - } + level.pending_green_toggle = ! level.pending_green_toggle; }, on_arrive(me, level, other) { level.sfx.play_once('button-press', me.cell);