Behaviors
ACCELERATION · AFTERCOLLISION · ALPHA · ANIMATE · BEHAVIOR · BLINK · BOUNCE · ELEVATE · FLIPX · FLIPY · FOLLOW · FRICTION · GRAVITY · IMAGE · IMPULSE · LOAD BEHAVIOR · LOAD PATTERN · LOAD RIG · MOVE · ONCOLLISION · ORBIT · ORIGIN · OSCILLATE · PATH · PATTERN · ROTATE · SAVE BEHAVIOR · SAVE PATTERN · SAVE RIG · SCALE · SET BEHAVIOR RATE · SET MUTATION BEHAVIOR · SHAKE · STEP · STEP BEVENT · STEP DISABLE · STEP FADE · STEP GHOST · STEP GOTOPATTERN · STEP HIDE · STEP RETAG · STEP SHOW · STEP SOLID · STEP WAITFOR · STOP · USE SHADER · VELOCITY · hasbehavior · haspattern · param · spritebehaviors · spritepattern · spritevelocityx · spritevelocityy · variance · varianceint
ACCELERATION
A steady acceleration, per tick.
ACCELERATION x, y [, z]
Parameters
- x - X.
- y - Y.
- z = NULL - Z (elevation).
Example
SCREEN 320, 240
LOADIMG "hero_run.png", "hero" !! spritesheet((40, 40))
// Speed up downward by 0.4 pixels per tick, every tick: a fall.
BEHAVIOR "fall"
ACCELERATION 0, 0.4
END BEHAVIOR
ENABLE SPRITE 0
SET SPRITE 0 !! x(150) y(0) image("hero") frame(0) behavior("fall")
SHOW SPRITE 0
DELAY 100
PRINT "falling at", spritevelocityy(0)
Notes
You can write it only inside BEHAVIOR.
AFTERCOLLISION
Runs after a collision has been resolved: given who it is, what it hit, their tags, the edge, and how hard, as (vx, vy).
AFTERCOLLISION
...
END AFTERCOLLISION
The handler is given: me, other, tag, other_tag, edge, impact
Example
SCREEN 320, 240
LOADIMG "hero_run.png", "hero" !! spritesheet((40, 40))
// A trigger zone (not solid): the sprite passes through it, and the
// handler hears when it is clear again.
BOUNDARY ADD "zone", (120, 0) -> (140, 240)
left_zone = FALSE
BEHAVIOR "run"
VELOCITY 4, 0
ONCOLLISION
PRINT "into", other_tag, "by its", edge, "at", impact
END ONCOLLISION
AFTERCOLLISION
PRINT "out of", other_tag
IF other_tag = "zone" THEN left_zone = TRUE
END AFTERCOLLISION
END BEHAVIOR
ENABLE SPRITE 0
SET SPRITE 0 !! x(90) y(100) image("hero") frame(0) behavior("run")
SHOW SPRITE 0
FOR i = 1 ... 120
IF left_zone THEN BREAK
YIELD
END FOR
PRINT "came out of the zone:", left_zone
Notes
Opens a block I keep instead of running, to be called later. Each time it’s called, the block is given me, other, tag, other_tag, edge, impact. You can write it only inside BEHAVIOR.
ALPHA
Fade from one opacity to another over duration ticks; with loop it keeps going.
ALPHA start, target, duration
Also documents: loop
Parameters
- start - Opacity it starts at.
- target - Opacity it ends at.
- duration - Ticks.
After !!
- loop(on = TRUE) - Keep going.
Example
SCREEN 320, 240
LOADIMG "hero_run.png", "hero" !! spritesheet((40, 40))
// Fade in from invisible over half a second (30 ticks at 60 a second).
BEHAVIOR "fade_in"
ALPHA 0, 1, 30
END BEHAVIOR
// A pulse that keeps going: 35% to fully opaque over 45 ticks, then again.
BEHAVIOR "pulse"
ALPHA 0.35, 1, 45 !! loop
END BEHAVIOR
ENABLE SPRITE 0
SET SPRITE 0 !! x(100) y(100) image("hero") frame(0) alpha(0) behavior("fade_in")
SHOW SPRITE 0
PRINT spritebehaviors(0)
Notes
You can write it only inside BEHAVIOR.
ANIMATE
Play frames of an image: a list of frame numbers (every frame when omitted).
ANIMATE image [, frames]
Also documents: auto_bbox, events_on, framerate, framerate_of_sprite, noloop
Parameters
- image - A loaded image, or
PARAM(name, default). - frames AS ARRAY = NULL - Frame numbers in order (
a ... bfor a run of them).
After !!
- auto_bbox(value) - Follow the image’s slice as the collision box: on (its first slice), or a slice’s name.
- events_on(value AS ARRAY) - Frame numbers that fire an animation event.
- framerate(value) - Frames per second; this or
framerate_of_spriteis required. - framerate_of_sprite(on = TRUE) - Use the image’s own per-frame durations.
- noloop(on = TRUE) - Play once and hold the last frame.
Examples
SCREEN 320, 240
LOADIMG "hero_run.png", "hero" !! spritesheet((40, 40))
// Frames 0 and 1, eight a second, forever.
BEHAVIOR "walk"
ANIMATE "hero", [0, 1] !! framerate(8)
END BEHAVIOR
ENABLE SPRITE 0
SET SPRITE 0 !! x(100) y(100) image("hero") frame(0) behavior("walk")
SHOW SPRITE 0
PRINT hasbehavior(0, "walk")
SCREEN 320, 240
LOADIMG "hero_run.png", "hero" !! spritesheet((40, 40))
// Once through, then hold the last frame; fire an event on frame 1.
BEHAVIOR "swing"
ANIMATE "hero", [0, 1] !! framerate(12) noloop events_on([1])
END BEHAVIOR
ENABLE SPRITE 0
SET SPRITE 0 !! x(100) y(100) image("hero") frame(0) behavior("swing")
SHOW SPRITE 0
PRINT hasbehavior(0, "swing")
Notes
You can write it only inside BEHAVIOR.
BEHAVIOR
Describes how sprites move and look, for the engine to run: a behavior’s commands, then what happens on a collision.
BEHAVIOR name
...
END BEHAVIOR
Also documents: includes
Parameters
- name AS STRING - What the behavior is called, for a sprite or a pattern to use.
After !!
- includes(behaviors…) - Starts from other behaviors’ commands, which it adds to.
Examples
SCREEN 320, 240
LOADIMG "hero_run.png", "hero" !! spritesheet((40, 40))
// Defined once, run by the engine every tick for every sprite it is on.
BEHAVIOR "drift"
VELOCITY 2, 1
END BEHAVIOR
ENABLE SPRITE 0
SET SPRITE 0 !! x(20) y(20) image("hero") frame(0) behavior("drift")
SHOW SPRITE 0
DELAY 100
PRINT "moved to", spritex(0), spritey(0)
SCREEN 320, 240
LOADIMG "hero_run.png", "hero" !! spritesheet((40, 40))
BEHAVIOR "walk"
VELOCITY 1, 0
END BEHAVIOR
// Starts from walk's commands and adds a blink.
BEHAVIOR "hurt_walk" !! includes("walk")
BLINK 6
END BEHAVIOR
ENABLE SPRITE 0
SET SPRITE 0 !! x(20) y(100) image("hero") frame(0) behavior("hurt_walk")
SHOW SPRITE 0
PRINT hasbehavior(0, "hurt_walk")
SCREEN 320, 240
LOADIMG "hero_run.png", "hero" !! spritesheet((40, 40))
// PARAM is a setting each sprite gives the behavior, with behavior_params.
BEHAVIOR "fall"
VELOCITY 0, PARAM("speed", 1)
END BEHAVIOR
FOR n = 0 ... 2
ENABLE SPRITE n
SET SPRITE n !! x(60 + n * 100) y(0) image("hero") frame(0)
!! behavior("fall") behavior_params({speed: n + 1})
SHOW SPRITE n
NEXT
DELAY 30
PRINT "falling at", spritevelocityy(0), spritevelocityy(1), spritevelocityy(2)
Notes
Opens a block I run once. Inside it you can write ACCELERATION, AFTERCOLLISION, ALPHA, ANIMATE, BLINK, BOUNCE, ELEVATE, FLIPX, FLIPY, FOLLOW, FRICTION, GRAVITY, IMAGE, IMPULSE, MOVE, ONCOLLISION, ORBIT, ORIGIN, OSCILLATE, PATH, ROTATE, SCALE, SHAKE, STOP, USE SHADER and VELOCITY.
See also: param, variance, SET SPRITE, PATTERN
BLINK
Toggle visibility every rate ticks (0: don’t blink).
BLINK rate
Parameters
- rate - Ticks between toggles.
Example
SCREEN 320, 240
LOADIMG "hero_run.png", "hero" !! spritesheet((40, 40))
// Flicker every 6 ticks while invulnerable.
BEHAVIOR "invulnerable"
BLINK 6
END BEHAVIOR
ENABLE SPRITE 0
SET SPRITE 0 !! x(100) y(100) image("hero") frame(0) behavior("invulnerable")
SHOW SPRITE 0
PRINT "blinking:", hasbehavior(0, "invulnerable")
DELAY 50
// ... and later, stop flickering.
SET SPRITE 0 !! remove_behavior("invulnerable")
PRINT "blinking:", hasbehavior(0, "invulnerable")
Notes
You can write it only inside BEHAVIOR.
BOUNCE
Bounce off what it collides with, keeping this fraction of the speed.
BOUNCE x, y [, z]
Parameters
- x - X.
- y - Y.
- z = NULL - Z (elevation).
Example
SCREEN 320, 240
LOADIMG "hero_run.png", "hero" !! spritesheet((40, 40))
BOUNDARY ADD "walls", (0, 0) -> (320, 240) !! solid enclosure
// A kick sideways and a pull down; each wall hit keeps 90% of the speed.
BEHAVIOR "ball"
IMPULSE 4, 0
ACCELERATION 0, 0.3
BOUNCE 0.9, 0.9
END BEHAVIOR
ENABLE SPRITE 0
SET SPRITE 0 !! x(40) y(40) image("hero") frame(0) solid behavior("ball")
SHOW SPRITE 0
DELAY 100
PRINT hasbehavior(0, "ball")
Notes
You can write it only inside BEHAVIOR.
ELEVATE
Raise or lower the elevation from one height to another over duration ticks.
ELEVATE start, target, duration
Also documents: loop
Parameters
- start - Elevation it starts at.
- target - Elevation it ends at.
- duration - Ticks.
After !!
- loop(on = TRUE) - Keep going.
Example
SCREEN 320, 240
LOADIMG "hero_run.png", "hero" !! spritesheet((40, 40))
// Rise 10 pixels off the ground over 30 ticks, and back, forever.
BEHAVIOR "hover"
ELEVATE 0, 10, 30 !! loop
END BEHAVIOR
ENABLE SPRITE 0
SET SPRITE 0 !! x(100) y(100) image("hero") frame(0) behavior("hover")
SHOW SPRITE 0
DELAY 100
PRINT "hovering at", spriteelevation(0)
Notes
You can write it only inside BEHAVIOR.
FLIPX
Mirror horizontally, or, given no, put it back.
FLIPX on
Parameters
- on AS BOOLEAN - Yes mirrors it, no puts it back.
Example
SCREEN 320, 240
LOADIMG "hero_run.png", "hero" !! spritesheet((40, 40))
// Walk left, drawn facing left.
BEHAVIOR "walk_left"
VELOCITY -2, 0
FLIPX TRUE
END BEHAVIOR
ENABLE SPRITE 0
SET SPRITE 0 !! x(200) y(100) image("hero") frame(0) behavior("walk_left")
SHOW SPRITE 0
PRINT hasbehavior(0, "walk_left")
Notes
You can write it only inside BEHAVIOR.
FLIPY
Mirror vertically, or, given no, put it back.
FLIPY on
Parameters
- on AS BOOLEAN - Yes mirrors it, no puts it back.
Example
SCREEN 320, 240
LOADIMG "hero_run.png", "hero" !! spritesheet((40, 40))
// Knocked out: drawn upside down while it falls away.
BEHAVIOR "knocked_out"
FLIPY TRUE
ACCELERATION 0, 0.5
END BEHAVIOR
ENABLE SPRITE 0
SET SPRITE 0 !! x(100) y(100) image("hero") frame(0) behavior("knocked_out")
SHOW SPRITE 0
PRINT hasbehavior(0, "knocked_out")
Notes
You can write it only inside BEHAVIOR.
FOLLOW
Follow another sprite, keeping distance pixels behind it.
FOLLOW target, distance
Also documents: elevation, seek_first, speed
Parameters
- target - The sprite to follow.
- distance - How far behind, in pixels.
After !!
- elevation(value) - Height above the target.
- seek_first(value) - Close the gap first: on, or the speed to close it at.
- speed(value) - Pixels per tick it can close at.
Example
SCREEN 320, 240
LOADIMG "hero_run.png", "hero" !! spritesheet((40, 40))
ENABLE SPRITE 1
SET SPRITE 1 !! x(160) y(120) image("hero") frame(0)
SHOW SPRITE 1
// Trail sprite 1 at 20 pixels, closing at 2 pixels a tick.
BEHAVIOR "tail"
FOLLOW 1, 20 !! speed(2)
END BEHAVIOR
ENABLE SPRITE 0
SET SPRITE 0 !! x(100) y(100) image("hero") frame(0) behavior("tail")
SHOW SPRITE 0
DELAY 100
PRINT "closer:", spritex(0) > 100
Notes
You can write it only inside BEHAVIOR.
FRICTION
Momentum lost per tick, as a fraction.
FRICTION x, y [, z]
Parameters
- x - X.
- y - Y.
- z = NULL - Z (elevation).
Example
SCREEN 320, 240
LOADIMG "hero_run.png", "hero" !! spritesheet((40, 40))
// One shove, then lose 5% of the speed every tick until it coasts to a stop.
BEHAVIOR "slide"
IMPULSE 6, 0
FRICTION 0.05, 0.05
END BEHAVIOR
ENABLE SPRITE 0
SET SPRITE 0 !! x(20) y(100) image("hero") frame(0) behavior("slide")
SHOW SPRITE 0
DELAY 100
PRINT "slowed to", spritevelocityx(0)
Notes
You can write it only inside BEHAVIOR.
GRAVITY
Pull the ELEVATION (z) toward the ground by this much per tick, every tick: weight for sprites on a plane layer. Not screen-down; for that, ACCELERATION 0, g.
GRAVITY strength
Parameters
- strength - Strength.
Example
SCREEN 320, 240
LOADIMG "hero_run.png", "hero" !! spritesheet((40, 40))
// Jump straight up off the plane (elevation) and fall back to it.
BEHAVIOR "jump"
IMPULSE 0, 0, 8
GRAVITY 1
END BEHAVIOR
ENABLE SPRITE 0
SET SPRITE 0 !! x(100) y(100) image("hero") frame(0) behavior("jump")
SHOW SPRITE 0
DELAY 50
PRINT "in the air:", spriteelevation(0) > 0
Notes
You can write it only inside BEHAVIOR.
IMAGE
Show this image (and frame) while the behavior runs.
IMAGE image [, frame]
Parameters
- image - A loaded image, or
PARAM(name, default). - frame = NULL - Spritesheet frame.
Example
SCREEN 320, 240
LOADIMG "hero_run.png", "hero" !! spritesheet((40, 40))
// Show frame 1 of "hero" while the behavior runs.
BEHAVIOR "hurt"
IMAGE "hero", 1
END BEHAVIOR
ENABLE SPRITE 0
SET SPRITE 0 !! x(100) y(100) image("hero") frame(0) behavior("hurt")
SHOW SPRITE 0
PRINT hasbehavior(0, "hurt")
Notes
You can write it only inside BEHAVIOR.
IMPULSE
A single shove, applied once.
IMPULSE x, y [, z]
Parameters
- x - X.
- y - Y.
- z = NULL - Z (elevation).
Example
SCREEN 320, 240
LOADIMG "hero_run.png", "hero" !! spritesheet((40, 40))
// A dash: one kick of 10 pixels per tick, worn away by friction.
BEHAVIOR "dash"
IMPULSE 10, 0
FRICTION 0.15, 0.15
END BEHAVIOR
ENABLE SPRITE 0
SET SPRITE 0 !! x(20) y(100) image("hero") frame(0) behavior("dash")
SHOW SPRITE 0
DELAY 100
PRINT "dashed to x =", spritex(0)
Notes
You can write it only inside BEHAVIOR.
LOAD BEHAVIOR
Load the behaviors saved to a JSON file.
LOAD BEHAVIOR filename
load_behavior(filename)
Parameters
- filename AS STRING - The file.
Example
SCREEN 320, 240
LOADIMG "hero_run.png", "hero" !! spritesheet((40, 40))
BEHAVIOR "drift"
VELOCITY 2, 0
END BEHAVIOR
SAVE BEHAVIOR "drift", "drift.json"
// Registers every behavior in the file under the name it was saved with.
LOAD BEHAVIOR "drift.json"
ENABLE SPRITE 0
SET SPRITE 0 !! x(20) y(100) image("hero") frame(0) behavior("drift")
SHOW SPRITE 0
PRINT hasbehavior(0, "drift")
Notes
It’s also the function load_behavior, for when you want what it gives back.
LOAD PATTERN
Load the patterns saved to a JSON file.
LOAD PATTERN filename
load_pattern(filename)
Parameters
- filename AS STRING - The file.
Example
SCREEN 320, 240
LOADIMG "hero_run.png", "hero" !! spritesheet((40, 40))
BEHAVIOR "drift"
VELOCITY 1, 0
END BEHAVIOR
PATTERN "patrol"
STEP "drift" !! duration(30)
END PATTERN
SAVE PATTERN "patrol", "patrol.json"
LOAD PATTERN "patrol.json"
ENABLE SPRITE 0
SET SPRITE 0 !! x(20) y(100) image("hero") frame(0) pattern("patrol")
SHOW SPRITE 0
PRINT spritepattern(0)
Notes
It’s also the function load_pattern, for when you want what it gives back.
LOAD RIG
Load a rig saved with save_rig: its behaviors, patterns and sprites, onto a sprite or where it was.
LOAD RIG filename
load_rig(filename)
Also documents: onto
Parameters
- filename AS STRING - The file.
After !!
- onto(value AS NUMBER) - The sprite its root lands on.
Example
SCREEN 320, 240
LOADIMG "hero_run.png", "hero" !! spritesheet((40, 40))
ENABLE SPRITE 0
SET SPRITE 0 !! x(100) y(100) image("hero") frame(0)
SHOW SPRITE 0
ENABLE SPRITE 1
SET SPRITE 1 !! x(100) y(84) image("hero") frame(1) parent(0) tag("head")
SHOW SPRITE 1
SAVE RIG 0, "guard.json"
// A second guard: sprite 10 becomes the root, and its head is made for it.
ENABLE SPRITE 10
SET SPRITE 10 !! x(200) y(120) image("hero") frame(0)
SHOW SPRITE 10
LOAD RIG "guard.json" !! onto(10)
PRINT "heads:", spritecount("head")
Notes
It’s also the function load_rig, for when you want what it gives back.
MOVE
Move by (x, y[, z]) every tick, or hold an axis at its value instead (the absolute options).
MOVE x, y [, z]
Also documents: absolute_x, absolute_y, absolute_z
Parameters
- x - X per tick (or the x to hold).
- y - Y per tick.
- z = NULL - Z (elevation) per tick.
After !!
- absolute_x(on = TRUE) - Hold x at
xinstead of moving by it. - absolute_y(on = TRUE) - Hold y at
y. - absolute_z(on = TRUE) - Hold the elevation at
z.
Examples
SCREEN 320, 240
LOADIMG "hero_run.png", "hero" !! spritesheet((40, 40))
// Drift 1 pixel right and 2 down every tick.
BEHAVIOR "drift"
MOVE 1, 2
END BEHAVIOR
ENABLE SPRITE 0
SET SPRITE 0 !! x(100) y(100) image("hero") frame(0) behavior("drift")
SHOW SPRITE 0
DELAY 100
PRINT spritex(0) > 100, spritey(0) > 100
SCREEN 320, 240
LOADIMG "hero_run.png", "hero" !! spritesheet((40, 40))
// Hold x at 40 each tick; keep moving down.
BEHAVIOR "rail"
MOVE 40, 1 !! absolute_x
END BEHAVIOR
ENABLE SPRITE 0
SET SPRITE 0 !! x(100) y(100) image("hero") frame(0) behavior("rail")
SHOW SPRITE 0
DELAY 100
PRINT "x held at", spritex(0)
Notes
You can write it only inside BEHAVIOR.
ONCOLLISION
Runs when a sprite with this behavior collides: given who it is, what it hit, their tags, the edge, and how hard, as (vx, vy).
ONCOLLISION
...
END ONCOLLISION
The handler is given: me, other, tag, other_tag, edge, impact
Example
SCREEN 320, 240
LOADIMG "hero_run.png", "hero" !! spritesheet((40, 40))
BOUNDARY ADD "edge", (0, 0) -> (320, 240) !! solid enclosure
hit = ""
BEHAVIOR "run"
VELOCITY 6, 0
ONCOLLISION
hit = other_tag + " " + edge
END ONCOLLISION
END BEHAVIOR
ENABLE SPRITE 0
SET SPRITE 0 !! x(280) y(100) image("hero") frame(0) solid behavior("run")
SHOW SPRITE 0
FOR i = 1 ... 120
IF hit <> "" THEN BREAK
YIELD
END FOR
PRINT hit
Notes
Opens a block I keep instead of running, to be called later. Each time it’s called, the block is given me, other, tag, other_tag, edge, impact. You can write it only inside BEHAVIOR.
ORBIT
Circle a point (center) or a sprite (center_sprite) at distance pixels.
ORBIT distance
Also documents: axis, center, center_sprite, clockwise, decay, seek_first, speed, start_angle
Parameters
- distance - The orbit’s radius.
After !!
- axis(value) - The axis it turns about,
(x, y, z), for an orbit tilted out of the screen. - center(value) - The point it circles:
(x, y[, z]), a list of numbers or parameters, orPARAM(name, (x, y)). - center_sprite(value) - The sprite it circles.
- clockwise(on = TRUE) - On (the default) for clockwise, off for counterclockwise.
- decay(value) - Pixels per tick the radius shrinks (
DECAY; needsspeed). - seek_first(value) - Travel onto the circle first: on, or the speed to travel at.
- speed(value) - Degrees per tick.
- start_angle(value) - Where on the circle it starts, in degrees.
Examples
SCREEN 320, 240
LOADIMG "hero_run.png", "hero" !! spritesheet((40, 40))
// Circle the point (160, 120) at 40 pixels, 3 degrees a tick.
BEHAVIOR "moon"
ORBIT 40 !! center((160, 120)) speed(3)
END BEHAVIOR
ENABLE SPRITE 0
SET SPRITE 0 !! x(100) y(100) image("hero") frame(0) behavior("moon")
SHOW SPRITE 0
PRINT hasbehavior(0, "moon")
SCREEN 320, 240
LOADIMG "hero_run.png", "hero" !! spritesheet((40, 40))
ENABLE SPRITE 1
SET SPRITE 1 !! x(160) y(120) image("hero") frame(0)
SHOW SPRITE 1
// Circle sprite 1, counterclockwise, starting above it.
BEHAVIOR "guard"
ORBIT 30 !! center_sprite(1) start_angle(270) clockwise(FALSE)
END BEHAVIOR
ENABLE SPRITE 0
SET SPRITE 0 !! x(100) y(100) image("hero") frame(0) behavior("guard")
SHOW SPRITE 0
PRINT hasbehavior(0, "guard")
Notes
You can write it only inside BEHAVIOR.
ORIGIN
Set the anchor it is placed by, 0-1 across it, while the behavior runs.
ORIGIN x, y
Parameters
- x - Across, 0-1.
- y - Down, 0-1.
Example
SCREEN 320, 240
LOADIMG "hero_run.png", "hero" !! spritesheet((40, 40))
// Anchor the sprite by its bottom centre while the behavior runs.
BEHAVIOR "feet"
ORIGIN 0.5, 1
END BEHAVIOR
ENABLE SPRITE 0
SET SPRITE 0 !! x(100) y(100) image("hero") frame(0) behavior("feet")
SHOW SPRITE 0
PRINT hasbehavior(0, "feet")
Notes
You can write it only inside BEHAVIOR.
OSCILLATE
Swing back and forth around where it is, amp_x / amp_y pixels either way.
OSCILLATE amp_x, amp_y [, amp_z]
Also documents: decay, persistent, phase, speed
Parameters
- amp_x - Swing across, in pixels.
- amp_y - Swing down, in pixels.
- amp_z = NULL - Swing in elevation.
After !!
- decay(value) - How fast the swing dies away.
- persistent(on = TRUE) - Keep its place in the swing when the behavior is re-applied.
- phase(value) - Where in the swing it starts, in degrees.
- speed(value) - How fast it swings.
Example
SCREEN 320, 240
LOADIMG "hero_run.png", "hero" !! spritesheet((40, 40))
// Bob 4 pixels up and down.
BEHAVIOR "bob"
OSCILLATE 0, 4 !! speed(2)
END BEHAVIOR
// A shake that dies away.
BEHAVIOR "quake"
OSCILLATE 6, 6 !! speed(8) decay(0.2)
END BEHAVIOR
ENABLE SPRITE 0
SET SPRITE 0 !! x(100) y(100) image("hero") frame(0) behavior("bob")
SHOW SPRITE 0
PRINT spritebehaviors(0)
Notes
You can write it only inside BEHAVIOR.
PATH
Travel through points in order: (x, y[, z]) waypoints, or a MUTATION’s points.
PATH points
Also documents: absolute, loop, pingpong, seek_first, speed
Parameters
- points - The waypoints: a list of
(x, y)/(x, y, z), or aMUTATION.
After !!
- absolute(on = TRUE) - Waypoints are screen positions, not offsets from where it starts.
- loop(on = TRUE) - Start over at the end.
- pingpong(on = TRUE) - Run back and forth.
- seek_first(value) - Travel to the first waypoint first: on, or the speed to travel at.
- speed(value) - Pixels per tick.
Examples
SCREEN 320, 240
LOADIMG "hero_run.png", "hero" !! spritesheet((40, 40))
// Walk a triangle, 2 pixels a tick, forever. Points are offsets from where it starts.
BEHAVIOR "patrol"
PATH [(0, 0), (60, 0), (30, 40)] !! speed(2) loop
END BEHAVIOR
ENABLE SPRITE 0
SET SPRITE 0 !! x(100) y(100) image("hero") frame(0) behavior("patrol")
SHOW SPRITE 0
DELAY 100
PRINT "on patrol at", spritex(0), spritey(0)
SCREEN 320, 240
LOADIMG "hero_run.png", "hero" !! spritesheet((40, 40))
// Screen points, back and forth, heading for the first one at speed 3.
BEHAVIOR "lift"
PATH [(40, 200), (40, 60)] !! absolute pingpong seek_first(3)
END BEHAVIOR
ENABLE SPRITE 0
SET SPRITE 0 !! x(100) y(100) image("hero") frame(0) behavior("lift")
SHOW SPRITE 0
PRINT hasbehavior(0, "lift")
Notes
You can write it only inside BEHAVIOR.
PATTERN
Describes what a sprite does, step after step, for the engine to run.
PATTERN name
...
END PATTERN
Also documents: includes, loop
Parameters
- name AS STRING - What the pattern is called, for a sprite to run.
After !!
- includes(patterns…) - Starts with other patterns’ steps.
- loop(on = TRUE) - Starts again from the first step after the last.
Examples
SCREEN 320, 240
LOADIMG "hero_run.png", "hero" !! spritesheet((40, 40))
BEHAVIOR "rise"
VELOCITY 0, -1
END BEHAVIOR
BEHAVIOR "sink"
VELOCITY 0, 1
END BEHAVIOR
// Up for half a second, down for half a second, over and over.
PATTERN "bob" !! loop
STEP "rise" !! duration(30)
STEP "sink" !! duration(30)
END PATTERN
ENABLE SPRITE 0
SET SPRITE 0 !! x(150) y(100) image("hero") frame(0) pattern("bob")
SHOW SPRITE 0
PRINT spritepattern(0)
SCREEN 320, 240
LOADIMG "hero_run.png", "hero" !! spritesheet((40, 40))
BEHAVIOR "idle"
STOP
END BEHAVIOR
BEHAVIOR "left"
VELOCITY -2, 0
END BEHAVIOR
BEHAVIOR "right"
VELOCITY 2, 0
END BEHAVIOR
// A group of WHEN steps: each is checked every tick, given the sprite.
PATTERN "steer"
STEP "idle" !! when(sprite => TRUE)
STEP "left" !! when(sprite => keydown("Left"))
STEP "right" !! when(sprite => keydown("Right"))
END PATTERN
ENABLE SPRITE 0
SET SPRITE 0 !! x(150) y(100) image("hero") frame(0) pattern("steer")
SHOW SPRITE 0
PRINT haspattern(0, "steer")
Notes
Opens a block I run once. Inside it you can write STEP, STEP BEVENT, STEP DISABLE, STEP FADE, STEP GHOST, STEP GOTOPATTERN, STEP HIDE, STEP RETAG, STEP SHOW, STEP SOLID and STEP WAITFOR.
ROTATE
Turn to an angle (degrees) over duration ticks; with loop it keeps turning. start is the angle it turns from, origin the point it turns about.
ROTATE target, duration
Also documents: loop, origin, start
Parameters
- target - The angle (or turn) in degrees.
- duration - Ticks per turn.
After !!
- loop(on = TRUE) - Keep turning.
- origin(value) - The point it turns about, 0-1 across its extent:
(x, y[, z]), a list of numbers or parameters, orPARAM(name, (x, y)). - start(value) - The angle it starts from.
Example
SCREEN 320, 240
LOADIMG "hero_run.png", "hero" !! spritesheet((40, 40))
// One full turn every 60 ticks, forever, about the sprite's centre.
BEHAVIOR "spin"
ROTATE 360, 60 !! origin((0.5, 0.5)) loop
END BEHAVIOR
// Turn from 0 to 90 degrees over 30 ticks, then stay there.
BEHAVIOR "quarter_turn"
ROTATE 90, 30 !! start(0)
END BEHAVIOR
ENABLE SPRITE 0
SET SPRITE 0 !! x(100) y(100) image("hero") frame(0) behavior("spin")
SHOW SPRITE 0
PRINT hasbehavior(0, "spin")
Notes
You can write it only inside BEHAVIOR.
SAVE BEHAVIOR
Save a behavior to a JSON file.
SAVE BEHAVIOR name, filename
save_behavior(name, filename)
Parameters
- name - Which one.
- filename AS STRING - The file.
Example
SCREEN 320, 240
BEHAVIOR "drift"
VELOCITY PARAM("vx", 1), 0
END BEHAVIOR
// Written to a JSON file, for LOAD BEHAVIOR to read back in any game.
SAVE BEHAVIOR "drift", "drift.json"
PRINT "saved", LEN(LOADTEXT("drift.json")) > 0
Notes
It’s also the function save_behavior, for when you want what it gives back.
SAVE PATTERN
Save a pattern to a JSON file.
SAVE PATTERN name, filename
save_pattern(name, filename)
Parameters
- name - Which one.
- filename AS STRING - The file.
Example
SCREEN 320, 240
BEHAVIOR "drift"
VELOCITY 1, 0
END BEHAVIOR
PATTERN "patrol" !! loop
STEP "drift" !! duration(60)
END PATTERN
SAVE PATTERN "patrol", "patrol.json"
PRINT "saved", LEN(LOADTEXT("patrol.json")) > 0
Notes
It’s also the function save_pattern, for when you want what it gives back.
SAVE RIG
Save a sprite and every sprite parented to it to a JSON file.
SAVE RIG sprite, filename
save_rig(sprite, filename)
Parameters
- sprite - Which one.
- filename AS STRING - The file.
Example
SCREEN 320, 240
LOADIMG "hero_run.png", "hero" !! spritesheet((40, 40))
BEHAVIOR "bob"
OSCILLATE 0, 2 !! speed(2)
END BEHAVIOR
// A body (sprite 0) with a head (sprite 1) parented to it.
ENABLE SPRITE 0
SET SPRITE 0 !! x(100) y(100) image("hero") frame(0)
SHOW SPRITE 0
ENABLE SPRITE 1
SET SPRITE 1 !! x(100) y(84) image("hero") frame(1) parent(0) behavior("bob")
SHOW SPRITE 1
SAVE RIG 0, "guard.json"
PRINT "saved", LEN(LOADTEXT("guard.json")) > 0
Notes
It’s also the function save_rig, for when you want what it gives back.
SCALE
Scale from one size to another over duration ticks.
SCALE start_x, start_y, to_x, to_y, duration
Also documents: loop
Parameters
- start_x - Width scale it starts at.
- start_y - Height scale it starts at.
- to_x - Width scale it ends at.
- to_y - Height scale it ends at.
- duration - Ticks.
After !!
- loop(on = TRUE) - Keep going.
Example
SCREEN 320, 240
LOADIMG "hero_run.png", "hero" !! spritesheet((40, 40))
// Grow from normal size to double over 30 ticks.
BEHAVIOR "grow"
SCALE 1, 1, 2, 2, 30
END BEHAVIOR
// Squash and stretch, over and over.
BEHAVIOR "wobble"
SCALE 1, 1, 1.2, 0.8, 15 !! loop
END BEHAVIOR
ENABLE SPRITE 0
SET SPRITE 0 !! x(100) y(100) image("hero") frame(0) behavior("grow")
SHOW SPRITE 0
PRINT hasbehavior(0, "grow")
Notes
You can write it only inside BEHAVIOR.
SET BEHAVIOR RATE
How many times a second the behavior engine ticks (default 60).
SET BEHAVIOR RATE rate
set_behavior_rate(rate)
Parameters
- rate AS NUMBER - Ticks per second.
Example
SCREEN 320, 240
LOADIMG "hero_run.png", "hero" !! spritesheet((40, 40))
BEHAVIOR "walk"
VELOCITY 1, 0
END BEHAVIOR
// Tick the behavior engine 120 times a second: per-tick motion goes twice as fast.
SET BEHAVIOR RATE 120
ENABLE SPRITE 0
SET SPRITE 0 !! x(20) y(100) image("hero") frame(0) behavior("walk")
SHOW SPRITE 0
DELAY 100
PRINT "walked to", spritex(0)
SET BEHAVIOR RATE 60
Notes
It’s also the function set_behavior_rate, for when you want what it gives back.
SET MUTATION BEHAVIOR
Attach a behavior to a shape (or remove one), so the engine moves it.
SET MUTATION BEHAVIOR shape
set_mutation_behavior(shape)
Also documents: behavior, behavior_params, clear_behaviors, remove_behavior
Parameters
- shape AS ARRAY - The shape: a
MUTATION.
After !!
- behavior(value AS STRING) - Attach a behavior.
- behavior_params(value) - Values for the behavior’s
@parameters, by name. - clear_behaviors(on = TRUE) - Remove every behavior.
- remove_behavior(value) - Remove a behavior, or a list of them. Removed before
behavior=is added.
Example
SCREEN 320, 240
BEHAVIOR "drift"
VELOCITY 1, 0
END BEHAVIOR
rock = MUTATION((20, 20), (30, 20), (25, 30))
SET POLYGON 5 !! bind(rock) color(7)
// The engine moves every point of the shape together.
SET MUTATION BEHAVIOR rock !! behavior("drift")
DELAY 100
PRINT "first point now at", rock(0)
SET MUTATION BEHAVIOR rock !! clear_behaviors
Notes
It’s also the function set_mutation_behavior, for when you want what it gives back.
SHAKE
Shake by this many pixels.
SHAKE amplitude
Parameters
- amplitude - Pixels.
Example
SCREEN 320, 240
LOADIMG "hero_run.png", "hero" !! spritesheet((40, 40))
// Tremble up to 3 pixels either way while hurt.
BEHAVIOR "hurt"
SHAKE 3
END BEHAVIOR
ENABLE SPRITE 0
SET SPRITE 0 !! x(100) y(100) image("hero") frame(0) behavior("hurt")
SHOW SPRITE 0
PRINT hasbehavior(0, "hurt")
Notes
You can write it only inside BEHAVIOR.
STEP
Runs a behavior: until it is done, for a while, or while a function says so.
STEP behavior
Also documents: duration, when
Parameters
- behavior AS STRING - The behavior to run.
After !!
- duration(ticks AS NUMBER) - For this many ticks, and no longer.
- when(condition AS FUNCTION) - Only while this function, given the sprite, says so.
Example
SCREEN 320, 240
LOADIMG "hero_run.png", "hero" !! spritesheet((40, 40))
BEHAVIOR "walk"
VELOCITY 1, 0
END BEHAVIOR
// Walk for a second, then walk only while the Right key is held.
PATTERN "p"
STEP "walk" !! duration(60)
STEP "walk" !! when(sprite => keydown("Right"))
END PATTERN
ENABLE SPRITE 0
SET SPRITE 0 !! x(20) y(100) image("hero") frame(0) pattern("p")
SHOW SPRITE 0
DELAY 100
PRINT "walked to", spritex(0)
Notes
You can write it only inside PATTERN.
STEP BEVENT
Fires an event.
STEP BEVENT event
Also documents: sync, when
Parameters
- event AS STRING - The event’s name, as
CALL EVENThears it.
After !!
- sync(on = TRUE) - Fire it on every player’s game.
- when(condition AS FUNCTION) - Only while this function, given the sprite, says so.
Example
SCREEN 320, 240
LOADIMG "hero_run.png", "hero" !! spritesheet((40, 40))
arrived = -1
// The event comes with the sprite that fired it.
FUNCTION on_arrived(sprite)
arrived = sprite
END FUNCTION
CALL EVENT on_arrived, "arrived"
BEHAVIOR "walk"
VELOCITY 1, 0
END BEHAVIOR
PATTERN "p"
STEP "walk" !! duration(3)
STEP BEVENT "arrived"
END PATTERN
ENABLE SPRITE 0
SET SPRITE 0 !! x(20) y(100) image("hero") frame(0) pattern("p")
SHOW SPRITE 0
DELAY 200
PRINT "sprite", arrived, "arrived"
Notes
You can write it only inside PATTERN.
STEP DISABLE
Takes the sprite out of play.
STEP DISABLE [when]
Also documents: when
Parameters
- when AS FUNCTION = NULL
After !!
- when(condition AS FUNCTION) - Only while this function, given the sprite, says so.
Example
SCREEN 320, 240
LOADIMG "hero_run.png", "hero" !! spritesheet((40, 40))
BEHAVIOR "walk"
VELOCITY 1, 0
END BEHAVIOR
// Walk a little way, then leave the game: the pattern goes with it.
PATTERN "p"
STEP "walk" !! duration(3)
STEP DISABLE
END PATTERN
ENABLE SPRITE 0
SET SPRITE 0 !! x(20) y(100) image("hero") frame(0) pattern("p")
SHOW SPRITE 0
DELAY 200
PRINT "enabled:", spriteenabled(0)
Notes
You can write it only inside PATTERN.
STEP FADE
Fades the sprite out.
STEP FADE speed
Also documents: when
Parameters
- speed AS NUMBER - How much of its opacity it loses each tick.
After !!
- when(condition AS FUNCTION) - Only while this function, given the sprite, says so.
Example
SCREEN 320, 240
LOADIMG "hero_run.png", "hero" !! spritesheet((40, 40))
BEHAVIOR "walk"
VELOCITY 1, 0
END BEHAVIOR
// Walk, fade out in half a second (speed 2), then go.
PATTERN "p"
STEP "walk" !! duration(3)
STEP FADE 2
STEP DISABLE
END PATTERN
ENABLE SPRITE 0
SET SPRITE 0 !! x(20) y(100) image("hero") frame(0) pattern("p")
SHOW SPRITE 0
PRINT spritepattern(0)
Notes
You can write it only inside PATTERN.
STEP GHOST
Lets things pass through the sprite.
STEP GHOST [when]
Also documents: when
Parameters
- when AS FUNCTION = NULL
After !!
- when(condition AS FUNCTION) - Only while this function, given the sprite, says so.
Example
SCREEN 320, 240
LOADIMG "hero_run.png", "hero" !! spritesheet((40, 40))
BEHAVIOR "walk"
VELOCITY 1, 0
END BEHAVIOR
// Only once Space is pressed does it drop its collider.
PATTERN "p"
STEP "walk" !! when(sprite => TRUE)
STEP GHOST !! when(sprite => keydown("Space"))
END PATTERN
ENABLE SPRITE 0
SET SPRITE 0 !! x(20) y(100) image("hero") frame(0) pattern("p")
SHOW SPRITE 0
PRINT haspattern(0)
Notes
You can write it only inside PATTERN.
STEP GOTOPATTERN
Carries on with another pattern.
STEP GOTOPATTERN pattern
Also documents: when
Parameters
- pattern AS STRING - The pattern to carry on with.
After !!
- when(condition AS FUNCTION) - Only while this function, given the sprite, says so.
Example
SCREEN 320, 240
LOADIMG "hero_run.png", "hero" !! spritesheet((40, 40))
BEHAVIOR "walk"
VELOCITY 1, 0
END BEHAVIOR
PATTERN "rest"
STEP HIDE
END PATTERN
// Walk a few ticks, then carry on with "rest".
PATTERN "p"
STEP "walk" !! duration(3)
STEP GOTOPATTERN "rest"
END PATTERN
ENABLE SPRITE 0
SET SPRITE 0 !! x(20) y(100) image("hero") frame(0) pattern("p")
SHOW SPRITE 0
DELAY 200
PRINT spritepattern(0)
Notes
You can write it only inside PATTERN.
STEP HIDE
Hides the sprite.
STEP HIDE [when]
Also documents: when
Parameters
- when AS FUNCTION = NULL
After !!
- when(condition AS FUNCTION) - Only while this function, given the sprite, says so.
Example
SCREEN 320, 240
LOADIMG "hero_run.png", "hero" !! spritesheet((40, 40))
BEHAVIOR "walk"
VELOCITY 1, 0
END BEHAVIOR
// Walk a little way, then vanish (it still exists, and can be shown again).
PATTERN "p"
STEP "walk" !! duration(3)
STEP HIDE
END PATTERN
ENABLE SPRITE 0
SET SPRITE 0 !! x(20) y(100) image("hero") frame(0) pattern("p")
SHOW SPRITE 0
DELAY 200
PRINT "visible:", spritevisible(0), "enabled:", spriteenabled(0)
Notes
You can write it only inside PATTERN.
STEP RETAG
Gives the sprite another tag.
STEP RETAG tag
Also documents: when
Parameters
- tag AS STRING - Its new tag.
After !!
- when(condition AS FUNCTION) - Only while this function, given the sprite, says so.
Example
SCREEN 320, 240
LOADIMG "hero_run.png", "hero" !! spritesheet((40, 40))
BEHAVIOR "walk"
VELOCITY 1, 0
END BEHAVIOR
// After a few ticks' walk, it is tired.
PATTERN "p"
STEP "walk" !! duration(3)
STEP RETAG "tired"
END PATTERN
ENABLE SPRITE 0
SET SPRITE 0 !! x(20) y(100) image("hero") frame(0) tag("fresh") pattern("p")
SHOW SPRITE 0
DELAY 200
PRINT spritetag(0)
Notes
You can write it only inside PATTERN.
STEP SHOW
Shows the sprite.
STEP SHOW [when]
Also documents: when
Parameters
- when AS FUNCTION = NULL
After !!
- when(condition AS FUNCTION) - Only while this function, given the sprite, says so.
Example
SCREEN 320, 240
LOADIMG "hero_run.png", "hero" !! spritesheet((40, 40))
BEHAVIOR "walk"
VELOCITY 1, 0
END BEHAVIOR
// Walk unseen for a few ticks, then appear.
PATTERN "p"
STEP HIDE
STEP "walk" !! duration(3)
STEP SHOW
END PATTERN
ENABLE SPRITE 0
SET SPRITE 0 !! x(20) y(100) image("hero") frame(0) pattern("p")
SHOW SPRITE 0
DELAY 200
PRINT "visible again:", spritevisible(0)
Notes
You can write it only inside PATTERN.
STEP SOLID
Makes the sprite solid.
STEP SOLID [when]
Also documents: when
Parameters
- when AS FUNCTION = NULL
After !!
- when(condition AS FUNCTION) - Only while this function, given the sprite, says so.
Example
SCREEN 320, 240
LOADIMG "hero_run.png", "hero" !! spritesheet((40, 40))
BEHAVIOR "walk"
VELOCITY 1, 0
END BEHAVIOR
// Pass through everything while it walks in, then become solid.
PATTERN "p"
STEP GHOST
STEP "walk" !! duration(30)
STEP SOLID
END PATTERN
ENABLE SPRITE 0
SET SPRITE 0 !! x(20) y(100) image("hero") frame(0) pattern("p")
SHOW SPRITE 0
PRINT spritepattern(0)
Notes
You can write it only inside PATTERN.
STEP WAITFOR
Waits for an event.
STEP WAITFOR event
Also documents: timeout
Parameters
- event AS STRING - The event’s name.
After !!
- timeout(ticks AS NUMBER) - Give up after this many ticks.
Example
SCREEN 320, 240
LOADIMG "hero_run.png", "hero" !! spritesheet((40, 40))
BEHAVIOR "walk"
VELOCITY 1, 0
END BEHAVIOR
// Stand still until "go" fires (or two seconds pass), then walk.
PATTERN "p"
STEP WAITFOR "go" !! timeout(120)
STEP "walk" !! duration(60)
END PATTERN
ENABLE SPRITE 0
SET SPRITE 0 !! x(20) y(100) image("hero") frame(0) pattern("p")
SHOW SPRITE 0
DELAY 50
PRINT "before go:", spritex(0)
EVENT "go"
DELAY 100
PRINT "after go:", spritex(0)
Notes
You can write it only inside PATTERN.
STOP
Stop moving.
STOP
Example
SCREEN 320, 240
LOADIMG "hero_run.png", "hero" !! spritesheet((40, 40))
BEHAVIOR "dash"
IMPULSE 10, 0
END BEHAVIOR
// Attaching this halts the sprite: the speed it built up is gone.
BEHAVIOR "halt"
STOP
END BEHAVIOR
ENABLE SPRITE 0
SET SPRITE 0 !! x(20) y(100) image("hero") frame(0) behavior("dash")
SHOW SPRITE 0
DELAY 50
SET SPRITE 0 !! clear_behaviors
SET SPRITE 0 !! behavior("halt")
DELAY 50
PRINT "speed now", spritevelocityx(0)
Notes
You can write it only inside BEHAVIOR.
USE SHADER
Run a shader on it while the behavior runs, optionally animating one of its parameters.
USE SHADER shader
Also documents: duration, loop, param, start, to
Parameters
- shader - A shader’s name, or
PARAM(name, default).
After !!
- duration(value) - Ticks.
- loop(on = TRUE) - Keep going.
- param(value AS STRING) - The shader parameter to animate (
@p). - start(value) - Its value at the start.
- to(value) - Its value at the end.
Example
SCREEN 320, 240
LOADIMG "hero_run.png", "hero" !! spritesheet((40, 40))
SHADER "Grey"
USE NUMBER amount DEFAULT 1.0
WHEN DRAWING
c = IMAGE
SET COLOR = c
END WHEN
END SHADER
// Take the shader's amount from 0 to 1 over 30 ticks, back and forth.
BEHAVIOR "grey_out"
USE SHADER "Grey" !! param("amount") start(0) to(1) duration(30) loop
END BEHAVIOR
ENABLE SPRITE 0
SET SPRITE 0 !! x(100) y(100) image("hero") frame(0) behavior("grey_out")
SHOW SPRITE 0
PRINT hasbehavior(0, "grey_out")
Notes
You can write it only inside BEHAVIOR.
VELOCITY
A steady velocity, per tick.
VELOCITY x, y [, z]
Parameters
- x - X.
- y - Y.
- z = NULL - Z (elevation).
Example
SCREEN 320, 240
LOADIMG "hero_run.png", "hero" !! spritesheet((40, 40))
// Two pixels right and one down, every tick, for as long as it is attached.
BEHAVIOR "drift"
VELOCITY 2, 1
END BEHAVIOR
ENABLE SPRITE 0
SET SPRITE 0 !! x(20) y(20) image("hero") frame(0) behavior("drift")
SHOW SPRITE 0
DELAY 100
PRINT spritevelocityx(0), spritevelocityy(0)
Notes
You can write it only inside BEHAVIOR.
hasbehavior
Returns 1 if the specified behavior is currently active on the sprite, 0 otherwise. Behavior name matching is case-insensitive.
hasbehavior(sprite_num, behavior_name)
Parameters
- sprite_num - Sprite slot number (0-99,999)
- behavior_name - Name of behavior to check
Example
SCREEN 320, 240
LOADIMG "hero_run.png", "hero" !! spritesheet((40, 40))
BEHAVIOR "walk_right"
VELOCITY 2, 0
END BEHAVIOR
ENABLE SPRITE 0
SET SPRITE 0 !! x(20) y(100) image("hero") frame(0) behavior("walk_right")
SHOW SPRITE 0
PRINT hasbehavior(0, "walk_right"), hasbehavior(0, "WALK_RIGHT"), hasbehavior(0, "idle")
haspattern
Returns 1 (TRUE) if the specified sprite has an active pattern, 0 (FALSE) otherwise. With a pattern name, returns 1 only if that is the pattern currently running.
It can be written haspattern(sprite_num) or haspattern(sprite_num, pattern_name).
haspattern(sprite_num, pattern_name = NULL)
Parameters
- sprite_num - Sprite slot number (0-99,999)
- pattern_name = NULL - Optional. Ask about ONE pattern: returns 1 only if that is the pattern running. Matched case-insensitively, like every other pattern name.
Example
SCREEN 320, 240
LOADIMG "hero_run.png", "hero" !! spritesheet((40, 40))
BEHAVIOR "stroll"
VELOCITY 1, 0
END BEHAVIOR
PATTERN "Walk"
STEP "stroll" !! when(sprite => TRUE)
END PATTERN
ENABLE SPRITE 0
SET SPRITE 0 !! x(20) y(100) image("hero") frame(0)
SHOW SPRITE 0
PRINT haspattern(0)
SET SPRITE 0 !! pattern("Walk")
PRINT haspattern(0), haspattern(0, "walk"), haspattern(0, "Run")
param
A behavior’s parameter: a number a sprite can set for itself, with the value it has otherwise. Write it in a BEHAVIOR where a number goes, and give each sprite its own with SET SPRITE n !! behavior("name") behavior_params({name: value}). The first BASIC wrote it @name.
param(name AS STRING, default = 0)
Parameters
- name AS STRING - What the sprite calls it in
behavior_params. - default = 0 - The value it has when the sprite doesn’t give one.
Examples
SCREEN 320, 240
LOADIMG "hero_run.png", "hero" !! spritesheet((40, 40))
// One behavior, with a speed each sprite can give it: 3 if it doesn't.
BEHAVIOR "runner"
VELOCITY PARAM("speed", 3), 0
END BEHAVIOR
ENABLE SPRITE 0
SET SPRITE 0 !! x(20) y(60) image("hero") frame(0)
!! behavior("runner")
SHOW SPRITE 0
ENABLE SPRITE 1
SET SPRITE 1 !! x(20) y(120) image("hero") frame(0)
!! behavior("runner") behavior_params({speed: 1})
SHOW SPRITE 1
DELAY 30
PRINT "the first runs at", spritevelocityx(0), "and the second at", spritevelocityx(1)
SCREEN 320, 240
LOADIMG "hero_run.png", "hero" !! spritesheet((40, 40))
// A parameter can be any number a behavior's command takes.
BEHAVIOR "circle"
ORBIT PARAM("r", 60) !! center((160, 120)) speed(3)
END BEHAVIOR
FOR n = 0 ... 3
ENABLE SPRITE n
SET SPRITE n !! image("hero") frame(0) origin((0.5, 0.5))
!! behavior("circle") behavior_params({r: 20 + n * 15})
SHOW SPRITE n
NEXT
PRINT "four rings, from 20 to 65 pixels out"
See also: BEHAVIOR, SET SPRITE, variance
spritebehaviors
Returns a comma-separated string of all behavior names currently active on the specified sprite. Returns empty string if no behaviors are active.
spritebehaviors(sprite_num)
Parameters
- sprite_num - Sprite slot number (0-99,999)
Example
SCREEN 320, 240
LOADIMG "hero_run.png", "hero" !! spritesheet((40, 40))
BEHAVIOR "walk"
VELOCITY 1, 0
END BEHAVIOR
BEHAVIOR "blink"
BLINK 10
END BEHAVIOR
ENABLE SPRITE 0
SET SPRITE 0 !! x(20) y(100) image("hero") frame(0) behavior("walk")
SHOW SPRITE 0
SET SPRITE 0 !! behavior("blink")
PRINT spritebehaviors(0)
spritepattern
Returns the name of the currently active pattern on the specified sprite, or an empty string if no pattern is active.
spritepattern(sprite_num)
Parameters
- sprite_num - Sprite slot number (0-99,999)
Example
SCREEN 320, 240
LOADIMG "hero_run.png", "hero" !! spritesheet((40, 40))
BEHAVIOR "stroll"
VELOCITY 1, 0
END BEHAVIOR
PATTERN "Walk"
STEP "stroll" !! when(sprite => TRUE)
END PATTERN
ENABLE SPRITE 0
SET SPRITE 0 !! x(20) y(100) image("hero") frame(0) pattern("walk")
SHOW SPRITE 0
// Spelled as PATTERN defined it, whatever case attached it.
PRINT spritepattern(0)
spritevelocityx
Returns the sprite’s current total X velocity (includes VELOCITY, ACCELERATION, and any other velocity-affecting behaviors). Returns 0 if the sprite has no active velocity. Pass the optional literal “direction” as a second argument to get the sign of the velocity (-1, 0, or 1) instead of the raw value.
spritevelocityx(sprite_num, direction = NULL)
Parameters
- sprite_num - Sprite slot number (0-99,999)
- direction = NULL - Optional literal string; returns the sign of the velocity (-1, 0, or 1) instead of the raw value.
Example
SCREEN 320, 240
LOADIMG "hero_run.png", "hero" !! spritesheet((40, 40))
BEHAVIOR "walk_left"
VELOCITY -2, 0
END BEHAVIOR
ENABLE SPRITE 0
SET SPRITE 0 !! x(200) y(100) image("hero") frame(0) behavior("walk_left")
SHOW SPRITE 0
DELAY 100
PRINT spritevelocityx(0), spritevelocityx(0, "direction")
spritevelocityy
Returns the sprite’s current total Y velocity (includes VELOCITY, ACCELERATION, and any other velocity-affecting behaviors). Returns 0 if the sprite has no active velocity. Positive values indicate downward movement. Pass the optional literal “direction” as a second argument to get the sign of the velocity (-1, 0, or 1) instead of the raw value.
spritevelocityy(sprite_num, direction = NULL)
Parameters
- sprite_num - Sprite slot number (0-99,999)
- direction = NULL - Optional literal string; returns the sign of the velocity (-1, 0, or 1) instead of the raw value.
Example
SCREEN 320, 240
LOADIMG "hero_run.png", "hero" !! spritesheet((40, 40))
BEHAVIOR "rise"
VELOCITY 0, -3
END BEHAVIOR
ENABLE SPRITE 0
SET SPRITE 0 !! x(100) y(200) image("hero") frame(0) behavior("rise")
SHOW SPRITE 0
DELAY 100
IF spritevelocityy(0, "direction") < 0 THEN PRINT "going up at", spritevelocityy(0)
variance
A number that is different for each sprite: base plus an amount from low to high.
variance(base AS NUMBER, low AS NUMBER, high AS NUMBER)
Parameters
- base AS NUMBER
- low AS NUMBER
- high AS NUMBER
Example
SCREEN 320, 240
BEHAVIOR "drift"
VELOCITY VARIANCE(2, -1, 1), 0
END BEHAVIOR
ENABLE SPRITE 0
SET SPRITE 0 !! behavior("drift")
SHOW SPRITE 0
PRINT hasbehavior(0, "drift")
See also: varianceint, param, BEHAVIOR
varianceint
A whole number that is different for each sprite: base plus a whole amount from low to high.
varianceint(base AS NUMBER, low AS NUMBER, high AS NUMBER, nonzero = FALSE)
Also documents: nonzero
Parameters
- base AS NUMBER
- low AS NUMBER
- high AS NUMBER
- nonzero = FALSE
After !!
- nonzero(on = TRUE) - Never 0.
Example
SCREEN 320, 240
spin = VARIANCEINT(0, -3, 3) !! nonzero
BEHAVIOR "wobble"
ROTATE spin, 10
END BEHAVIOR
ENABLE SPRITE 0
SET SPRITE 0 !! behavior("wobble")
SHOW SPRITE 0
PRINT hasbehavior(0, "wobble")