simplify
This commit is contained in:
@@ -28,16 +28,6 @@ fn opposite_tag(me) {
|
||||
else { "BUILTIN_transporter_east" }
|
||||
}
|
||||
|
||||
// The direction a front bump arrives from — the side opposite our facing (a
|
||||
// north-facing transporter is entered from the south, etc.). `bump` reacts only
|
||||
// when the reported direction matches this.
|
||||
fn entrance_dir(me) {
|
||||
if me.has_tag("BUILTIN_transporter_north") { South }
|
||||
else if me.has_tag("BUILTIN_transporter_south") { North }
|
||||
else if me.has_tag("BUILTIN_transporter_east") { West }
|
||||
else { East }
|
||||
}
|
||||
|
||||
// The 4-frame animation loop for this direction (CP437 tile codes).
|
||||
fn frames(me) {
|
||||
if me.has_tag("BUILTIN_transporter_north") { [94, 45, 94, 126] } // ^ - ^ ~
|
||||
@@ -67,14 +57,15 @@ fn transport(sx, sy, tx, ty) {
|
||||
}
|
||||
|
||||
fn bump(me, dir) {
|
||||
// Only transport things that hit us from the front — the entrance side. `dir`
|
||||
// is the direction the bump came from; a bump from any other side does nothing.
|
||||
if dir != entrance_dir(me) { return; }
|
||||
|
||||
let d = facing(me);
|
||||
let dx = d[0];
|
||||
let dy = d[1];
|
||||
|
||||
// Only transport things that hit us from the front — the entrance side (-facing).
|
||||
// `dir` is the side the bump came from, so its offset must be the opposite of our
|
||||
// facing; a bump from any other side does nothing.
|
||||
if dir.dx != -dx || dir.dy != -dy { return; }
|
||||
|
||||
// Whatever solid is pressed against our entrance cell (me - d) gets moved:
|
||||
// the player, another object, or a pushed crate — all handled uniformly by
|
||||
// shifting the solid at that coordinate onto an empty destination.
|
||||
|
||||
Reference in New Issue
Block a user