more scripting, objects moving
This commit is contained in:
@@ -51,10 +51,37 @@ tile = "#"
|
||||
solid = false
|
||||
script_name = "greeter"
|
||||
|
||||
# A solid object placed by x/y that paces east on its own. Demonstrates the
|
||||
# rate-limited move(), the blocked() collision check, the Queue object, and the
|
||||
# bump() hook (walk the player into it to trigger a bump).
|
||||
[[objects]]
|
||||
x = 10
|
||||
y = 12
|
||||
fg = "#33aa33"
|
||||
bg = "#000000"
|
||||
tile = 1
|
||||
script_name = "mover"
|
||||
|
||||
[scripts]
|
||||
greeter = """
|
||||
fn init() {
|
||||
log(`hello from object — player at ${Board.player_x}, ${Board.player_y}`);
|
||||
set_tile(2); // change my glyph to ☻ — proves the write path
|
||||
}
|
||||
"""
|
||||
|
||||
mover = """
|
||||
// move() costs 250 ms, so the object steps ~4 cells/sec no matter how often
|
||||
// tick() runs. Queue.length() avoids piling up moves; blocked() avoids walking
|
||||
// into a wall (or another object's already-queued move this tick).
|
||||
fn tick(dt) {
|
||||
if Queue.length() == 0 {
|
||||
move(East);
|
||||
}
|
||||
}
|
||||
// Fires when something steps into this object; id is the bumper's array index,
|
||||
// or -1 for the player.
|
||||
fn bump(id) {
|
||||
log(`mover bumped by ${id}`);
|
||||
}
|
||||
"""
|
||||
Reference in New Issue
Block a user