by_player flag on bump and delay flag on move
This commit is contained in:
+8
-7
@@ -53,7 +53,7 @@ fn tick(me, state, dt) {
|
||||
}
|
||||
```
|
||||
|
||||
### `fn bump(me, dir)`
|
||||
### `fn bump(me, dir, by_player)`
|
||||
|
||||
Called when a solid presses into this object's cell — the player, another object, or a **crate** being
|
||||
pushed into it (the push chain is walked through to reach the object it presses against).
|
||||
@@ -61,12 +61,13 @@ pushed into it (the push chain is walked through to reach the object it presses
|
||||
- `dir` is the [`Direction`] the bump **came from**: it points from this object toward the bumper, so
|
||||
the bumper occupies the cell at `(me.x + dir.dx, me.y + dir.dy)`.
|
||||
- Compare it against the `North`/`South`/`East`/`West` constants.
|
||||
- The hook can no longer tell *who* did the bumping (there is no id) — a crate bumps just like the player.
|
||||
- `by_player` is `true` when the bumper **is the player** — a crate the player shoves into this object
|
||||
(or another object moving in) reports `false`, since the crate is the immediate bumper.
|
||||
|
||||
```rhai
|
||||
fn bump(me, dir) {
|
||||
if dir == West { say("Something shoved me from the west."); }
|
||||
else { log(`bumped from ${dir}`); }
|
||||
fn bump(me, dir, by_player) {
|
||||
if by_player { say("Don't shove me, I'm fragile!"); }
|
||||
else { log(`shoved from ${dir} by something other than the player`); }
|
||||
}
|
||||
```
|
||||
|
||||
@@ -311,7 +312,7 @@ function call named `choice_key` (see [custom handler functions](#custom-handler
|
||||
arity rules — a choice handler is called with no `arg`).
|
||||
|
||||
```rhai
|
||||
fn bump(me, dir) {
|
||||
fn bump(me, dir, _by_player) {
|
||||
scroll([
|
||||
"The muffin looks delicious.",
|
||||
"",
|
||||
@@ -385,7 +386,7 @@ fn tick(me, state, dt) {
|
||||
else if !me.blocked(West) { move(West); }
|
||||
}
|
||||
|
||||
fn bump(me, dir) {
|
||||
fn bump(me, dir, by_player) {
|
||||
say(`Halt! Who approaches from the ${dir}?`); now();
|
||||
}
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user