Improve rotation of frame blocks on railroads
This commit is contained in:
parent
4d5c1b4332
commit
6aed1fa38e
13
js/game.js
13
js/game.js
@ -1043,7 +1043,18 @@ export class Level {
|
|||||||
if (actor.movement_cooldown > 0)
|
if (actor.movement_cooldown > 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
direction = actor.cell.redirect_exit(actor, direction);
|
let redirected_direction = actor.cell.redirect_exit(actor, direction);
|
||||||
|
if (direction !== redirected_direction) {
|
||||||
|
// Some tiles (ahem, frame blocks) rotate when their attempted direction is redirected
|
||||||
|
if (actor.type.on_rotate) {
|
||||||
|
let turn = ['right', 'left', 'opposite'].filter(t => {
|
||||||
|
return DIRECTIONS[direction][t] === redirected_direction;
|
||||||
|
})[0];
|
||||||
|
actor.type.on_rotate(actor, this, turn);
|
||||||
|
}
|
||||||
|
|
||||||
|
direction = redirected_direction;
|
||||||
|
}
|
||||||
this.set_actor_direction(actor, direction);
|
this.set_actor_direction(actor, direction);
|
||||||
|
|
||||||
// Record our speed, and halve it below if we're stepping onto a sliding tile
|
// Record our speed, and halve it below if we're stepping onto a sliding tile
|
||||||
|
|||||||
@ -466,26 +466,6 @@ const TILE_TYPES = {
|
|||||||
level._set_tile_prop(me, 'entered_direction', other.direction);
|
level._set_tile_prop(me, 'entered_direction', other.direction);
|
||||||
},
|
},
|
||||||
on_depart(me, level, other) {
|
on_depart(me, level, other) {
|
||||||
if (other.type.name === 'frame_block') {
|
|
||||||
// Directional blocks are rotated when they leave
|
|
||||||
// FIXME this isn't right, they rotate by the difference between their attempted
|
|
||||||
// move and their redirected move
|
|
||||||
if (other.direction === DIRECTIONS[me.entered_direction].right) {
|
|
||||||
let new_arrows = new Set;
|
|
||||||
for (let arrow of other.arrows) {
|
|
||||||
new_arrows.add(DIRECTIONS[arrow].right);
|
|
||||||
}
|
|
||||||
level._set_tile_prop(other, 'arrows', new_arrows);
|
|
||||||
}
|
|
||||||
else if (other.direction === DIRECTIONS[me.entered_direction].left) {
|
|
||||||
let new_arrows = new Set;
|
|
||||||
for (let arrow of other.arrows) {
|
|
||||||
new_arrows.add(DIRECTIONS[arrow].left);
|
|
||||||
}
|
|
||||||
level._set_tile_prop(other, 'arrows', new_arrows);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (! level.is_cell_wired(me.cell)) {
|
if (! level.is_cell_wired(me.cell)) {
|
||||||
me.type._switch_track(me, level);
|
me.type._switch_track(me, level);
|
||||||
}
|
}
|
||||||
@ -951,6 +931,14 @@ const TILE_TYPES = {
|
|||||||
on_clone(me, original) {
|
on_clone(me, original) {
|
||||||
me.arrows = new Set(original.arrows);
|
me.arrows = new Set(original.arrows);
|
||||||
},
|
},
|
||||||
|
on_rotate(me, level, turn) {
|
||||||
|
// We rotate when turned on railroads
|
||||||
|
let new_arrows = new Set;
|
||||||
|
for (let arrow of me.arrows) {
|
||||||
|
new_arrows.add(DIRECTIONS[arrow][turn]);
|
||||||
|
}
|
||||||
|
level._set_tile_prop(me, 'arrows', new_arrows);
|
||||||
|
},
|
||||||
},
|
},
|
||||||
green_floor: {
|
green_floor: {
|
||||||
draw_layer: DRAW_LAYERS.terrain,
|
draw_layer: DRAW_LAYERS.terrain,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user