Blocks pushed onto force floors should move at slide speed

This commit is contained in:
Eevee (Evelyn Woods) 2020-09-14 20:42:28 -06:00
parent 468a1d44ba
commit c214aeb0c6

View File

@ -590,18 +590,13 @@ export class Level {
// Try to move the given actor one tile in the given direction and update // Try to move the given actor one tile in the given direction and update
// their cooldown. Return true if successful. // their cooldown. Return true if successful.
attempt_step(actor, direction, speed = null) { attempt_step(actor, direction, pusher_speed = null) {
if (actor.stuck) if (actor.stuck)
return false; return false;
// If speed is given, we're being pushed by something so we're using // Record our speed, and remember to halve it if we're stepping onto a sliding tile
// its speed. Otherwise, use our movement speed. If we're moving onto let check_for_slide = true;
// a sliding tile, we'll halve it later let speed = actor.type.movement_speed;
let check_for_slide = false;
if (speed === null) {
speed = actor.type.movement_speed;
check_for_slide = true;
}
let move = DIRECTIONS[direction].movement; let move = DIRECTIONS[direction].movement;
if (!actor.cell) console.error(actor); if (!actor.cell) console.error(actor);
@ -638,8 +633,10 @@ export class Level {
if (! tile.blocks(actor, direction, this)) if (! tile.blocks(actor, direction, this))
continue; continue;
if (actor.type.pushes && actor.type.pushes[tile.type.name] && ! tile.stuck) { if (actor.type.pushes && actor.type.pushes[tile.type.name] && tile.movement_cooldown === 0 && ! tile.stuck) {
this.set_actor_direction(tile, direction); this.set_actor_direction(tile, direction);
// FIXME the speed adjustment at the end of all this should go before this
// call, but this all needs splitting up anyway
if (this.attempt_step(tile, direction, speed)) if (this.attempt_step(tile, direction, speed))
// It moved out of the way! // It moved out of the way!
continue; continue;
@ -675,6 +672,11 @@ export class Level {
return false; return false;
} }
// We cannot possibly move more slowly than something pushing us
if (pusher_speed !== null) {
speed = Math.min(speed, pusher_speed);
}
// We're clear! // We're clear!
this.move_to(actor, goal_cell, speed); this.move_to(actor, goal_cell, speed);
@ -777,7 +779,7 @@ export class Level {
if (neighbor) { if (neighbor) {
for (let tile of neighbor) { for (let tile of neighbor) {
// TODO repeating myself with tile.stuck (also should technically check for actor) // TODO repeating myself with tile.stuck (also should technically check for actor)
if (actor.type.pushes && actor.type.pushes[tile.type.name] && ! tile.stuck) { if (actor.type.pushes && actor.type.pushes[tile.type.name] && tile.movement_cooldown === 0 && ! tile.stuck) {
// Block slapping: you can shove a block by walking past it sideways // Block slapping: you can shove a block by walking past it sideways
this.set_actor_direction(tile, actor.secondary_direction); this.set_actor_direction(tile, actor.secondary_direction);
this.attempt_step(tile, actor.secondary_direction); this.attempt_step(tile, actor.secondary_direction);