Chapter 15: Autopilot Mode

Example Assets Needed:
To follow along with this chapter's examples, you'll need:

  • player.png — 32x32 character spritesheet (4 frames: idle, walk cycle)
  • enemy.png — 32x32 enemy spritesheet (3+ frames for animation)
  • coin.png — 16x16 collectible spritesheet (4 frames for spin animation)

Same assets from Chapter 6 work here!

You know what's exhausting? Micromanaging everything.

"Move the enemy 2 pixels... now move it 2 more... now animate frame 1... now frame 2... now check if it hit the player..."

That's a LOT of code in your game loop. And the more objects you have, the messier it gets.

What if you could just say "Hey, enemy sprite: walk right, animate yourself, and let me know if you hit something"—and then let Crash BASIC handle the details?

You can. Welcome to Autopilot Mode!

In this chapter, we'll learn how to set things up and let them run automatically:

  • Typewriter text that types itself
  • Behaviors that animate and move sprites on their own
  • Patterns that sequence behaviors automatically
  • Collisions that detect bumps between sprites

Let's put your game on autopilot!


Why Hardware Sprites Are So Fast

Before we dive in, let's talk about WHY you'd want to use these features instead of coding everything yourself.

When you manually move sprites in your game loop—tracking X and Y positions, incrementing them, checking bounds, animating frame by frame—all that math runs in your BASIC code, one instruction at a time. It works, but there's a limit to how many objects you can handle before things slow down.

Hardware sprites are different. They're managed by the graphics engine (Phaser under the hood), which uses GPU acceleration. Here's what that means for you:

1. GPU-Powered Movement
When you set a BEHAVIOR like BMOVE 2, 0, the graphics engine handles the math using optimized code that runs on your graphics card. The GPU can process thousands of sprites in parallel while your CPU focuses on game logic.

2. Automatic Batching
Drawing 100 sprites isn't much slower than drawing 1! The graphics engine batches similar sprites together into single draw calls. Manual pixel-by-pixel drawing can't do this.

3. Built-In Collision Detection
The engine tracks sprite bounding boxes automatically. When you use FOR COLLISIONS, the engine already knows which sprites overlap—it's not recalculating every frame. Manual collision checking means YOUR code runs O(n²) comparisons. The engine does it smarter.

4. Animation Without Loops
Setting ANIMATE "player", 0, 1, 2, 3 FRAMERATE 10 offloads frame counting to the engine. No frameTimer = frameTimer + 1 cluttering your game loop.

The Bottom Line:

  • Manual approach: YOU do the work, YOUR code gets slower with more objects
  • Hardware sprites: The ENGINE does the work, optimized and GPU-accelerated

This is why "autopilot" features matter—you're not just writing less code, you're using a system designed to handle hundreds of moving objects efficiently.

Okay, NOW let's learn these tools!


Part 1: Typewriter Text

Let's start simple. Remember dialog boxes? Wouldn't it be cool if the text typed out letter by letter, like in classic RPGs?

The RATE Modifier

Add RATE to your PRINT statement, and text appears one character at a time:

SCREEN 13

' Draw a dialog box
LINE (18, 138)-(302, 192), 15, B
WINDOW (20, 140) - (300, 190)

' Typewriter effect - 50ms per character
PRINT WORDS RATE(50) "The ancient door creaks open, revealing a dark passage..."

PAUSE

The number is the delay in milliseconds between each character:

  • RATE(30) = fast typing
  • RATE(50) = medium typing
  • RATE(100) = slow, dramatic typing

Non-Blocking: Your Game Keeps Running!

Here's the magic: RATE is non-blocking. Your program doesn't freeze while text types—it keeps running! Use TYPING() to check if text is still being typed:

SCREEN 13

LINE (18, 138)-(302, 192), 15, B
WINDOW (20, 140) - (300, 190)

PRINT WORDS RATE(30) "Press SPACE to skip this text..."

' Game loop continues while text types!
DO
    ' Check if player wants to skip
    IF KEYDOWN("SPACE") THEN
        ' You could implement skip logic here
    END IF

    ' Other game logic can happen here too!

    DELAY 16
LOOP UNTIL TYPING() = 0    ' Wait until typing finishes

PRINT ""
PRINT "Text complete!"
PAUSE

This is your first taste of "autopilot"—you start something, and Crash BASIC handles it in the background while your game keeps running.


Part 2: Sprite Behaviors

Now let's get to the REALLY cool stuff. Behaviors let you define how sprites animate and move—once. Then you just apply the behavior to any sprite, and it runs automatically!

Defining a Behavior

BEHAVIOR "walkRight"
    ANIMATE "player", 0, 1, 2, 3 FRAMERATE 10
    BMOVE 2, 0
END BEHAVIOR

This defines a behavior called "walkRight" that:

  1. Cycles through animation frames 0, 1, 2, 3 at 10 FPS
  2. Moves 2 pixels right every tick

But nothing happens yet—this is just the definition. Now let's USE it:

Applying Behaviors to Sprites

SCREEN 13

' Load a sprite sheet
LOADPNG "player.png", "player" AS SPRITESHEET(32, 32)

' Define behaviors
BEHAVIOR "walkRight"
    ANIMATE "player", 0, 1, 2, 3 FRAMERATE 10
    BMOVE 2, 0
END BEHAVIOR

BEHAVIOR "idle"
    ANIMATE "player", 0, 1 FRAMERATE 5
END BEHAVIOR

' Create a sprite
ENABLE SPRITE 0
SET SPRITE 0, 100, 100, "player"

' Apply a behavior - now it runs automatically!
SET SPRITE 0 BEHAVIOR "walkRight"

' Game loop - the sprite animates and moves on its own!
DO
    BEGIN FRAME
    ' No manual movement code needed!
    END FRAME
    DELAY 16
LOOP UNTIL KEYDOWN("ESCAPE")

The sprite walks and animates without any code in your game loop. That's autopilot!

Behavior Commands Reference

Here are all the things you can put inside a BEHAVIOR block:

Command What It Does
ANIMATE "img", 0, 1, 2 FRAMERATE 10 Cycle through animation frames
BMOVE dx, dy Move by (dx, dy) pixels per tick
BACCELERATION dx, dy Apply acceleration (gravity, thrust)
BFOLLOW spriteId DISTANCE d Follow another sprite
BORBIT (x,y) DISTANCE d Orbit around a point
BOSCILLATE AMPLITUDE x, y Float/wobble back and forth
BSHAKE AMPLITUDE a Shake/vibrate randomly
BALPHA from TO to DURATION t Fade transparency over time
BSCALE x1,y1 TO x2,y2 DURATION t Grow/shrink over time
BROTATE from TO to DURATION t Spin over time
BBLINK rate Flash on/off
BFLIPX ON/OFF Flip horizontally
BFLIPY ON/OFF Flip vertically
BIMAGE "name" Change sprite image
PATH (x,y), (x,y), ... LOOP Follow waypoints

Multiple Behaviors

A sprite can have MULTIPLE behaviors at once—they combine!

BEHAVIOR "wobble"
    BOSCILLATE AMPLITUDE 0, 5
END BEHAVIOR

BEHAVIOR "spin"
    BROTATE 0 TO 360 DURATION 60 LOOP
END BEHAVIOR

' Apply both!
SET SPRITE 0 BEHAVIOR "wobble"
SET SPRITE 0 BEHAVIOR "spin"    ' Now it wobbles AND spins!

Removing Behaviors

SET SPRITE 0 BEHAVIOR DELETE "spin"   ' Remove just the spin
SET SPRITE 0 BEHAVIOR NONE            ' Remove ALL behaviors

Checking Behaviors

IF HASBEHAVIOR(0, "walking") THEN
    PRINT "Sprite 0 is walking"
END IF

' Get all behaviors as a string
PRINT SPRITEBEHAVIORS$(0)    ' Might print "wobble,spin"

Part 3: Practical Behavior Examples

Floating Coin

BEHAVIOR "float"
    ANIMATE "coin", 0, 1, 2, 3 FRAMERATE 8
    BOSCILLATE AMPLITUDE 0, 8    ' Bob up and down
END BEHAVIOR

SET SPRITE coinSprite BEHAVIOR "float"

Enemy That Follows the Player

BEHAVIOR "chase"
    ANIMATE "enemy", 0, 1, 2 FRAMERATE 10
    BFOLLOW 0 DISTANCE 30 SPEED 2    ' Follow sprite 0 (player)
END BEHAVIOR

SET SPRITE enemySprite BEHAVIOR "chase"

Orbiting Shield

BEHAVIOR "orbit"
    BORBIT SPRITE 0 DISTANCE 40 SPEED 5    ' Orbit around sprite 0
    BROTATE 360 DURATION 30 LOOP           ' Spin while orbiting
END BEHAVIOR

SET SPRITE shieldSprite BEHAVIOR "orbit"

Damage Flash

BEHAVIOR "damaged"
    BBLINK 4                              ' Blink rapidly
    BSHAKE AMPLITUDE 3                    ' Shake
    BALPHA 1 TO 0.5 DURATION 10 LOOP     ' Flash transparency
END BEHAVIOR

Gravity Jump

BEHAVIOR "jumping"
    BMOVE 0, -10                   ' Initial upward velocity
    BACCELERATION 0, 0.5          ' Gravity pulls down
END BEHAVIOR

Patrol Path

BEHAVIOR "patrol"
    PATH ABSOLUTE (50, 100), (250, 100), (250, 150), (50, 150) SPEED 2 LOOP
    ANIMATE "guard", 0, 1, 2, 3 FRAMERATE 8
END BEHAVIOR

Part 4: Patterns - Sequencing Behaviors

Behaviors run continuously. But what if you want a SEQUENCE? First do this, then do that, then do something else?

That's what Patterns are for!

Basic Pattern

PATTERN "enemyRoutine" LOOP
    "walkRight" DURATION 60     ' Walk right for 1 second
    "idle" DURATION 30          ' Pause for half a second
    "walkLeft" DURATION 60      ' Walk left for 1 second
    "idle" DURATION 30          ' Pause again
END PATTERN

SET SPRITE 0 PATTERN "enemyRoutine"

The enemy now automatically walks right, pauses, walks left, pauses, and repeats forever!

Pattern Step Types

Patterns support three types of steps:

1. DURATION steps - Run for a fixed time:

"walking" DURATION 60    ' Run for 60 ticks (~1 second)

2. Completion steps - Run until the behavior finishes:

"fadeOut"                ' Run until fade completes

3. WHEN steps - Run while a condition is true:

"moveRight" WHEN KEYDOWN("RIGHT")    ' Only when key pressed

Death Sequence Pattern

PATTERN "death"
    GHOST                       ' Stop colliding
    "hitReaction" DURATION 10   ' Brief hit animation
    "fall"                      ' Fall animation (completion mode)
    FADE SPEED 2                ' Fade out
    DISABLE                     ' Remove sprite
END PATTERN

' When enemy dies:
SET SPRITE enemySprite PATTERN "death"

Player Control Pattern

PATTERN "playerControl" LOOP
    "idle"                              ' Default state
    "walkRight" WHEN KEYDOWN("RIGHT")   ' Override when key pressed
    "walkLeft" WHEN KEYDOWN("LEFT")
    "jump" WHEN KEYDOWN("SPACE")
END PATTERN

SET SPRITE 0 PATTERN "playerControl"

Now your player sprite handles its own input! The game loop can focus on other things.

Pattern Commands

These commands work INSIDE patterns:

Command What It Does
SHOW Make sprite visible
HIDE Make sprite invisible
DISABLE Remove sprite entirely
SOLID Enable collision
GHOST Disable collision (pass through)
FADE SPEED n Fade out over time
RETAG "tag" Change sprite's tag

Part 5: Collision Detection

Now let's make things bump into each other! With hardware sprites, Crash BASIC can detect collisions automatically—no manual coordinate checking needed.

Sprite Tags

First, tag your sprites so you know what's what:

SET SPRITE 0, 160, 100, "player" TAG "player"
SET SPRITE 1, 50, 50, "enemy" TAG "enemy"
SET SPRITE 2, 200, 80, "coin" TAG "coin"

FOR COLLISIONS Loop

Check all colliding sprite pairs automatically:

FOR COLLISIONS a, b
    tagA$ = SPRITETAG$(a)
    tagB$ = SPRITETAG$(b)

    ' Player hit coin?
    IF (tagA$ = "player" AND tagB$ = "coin") OR (tagB$ = "player" AND tagA$ = "coin") THEN
        ' Find which one is the coin and disable it
        IF tagA$ = "coin" THEN DISABLE SPRITE a ELSE DISABLE SPRITE b
        score = score + 10
    END IF

    ' Player hit enemy?
    IF (tagA$ = "player" AND tagB$ = "enemy") OR (tagB$ = "player" AND tagA$ = "enemy") THEN
        playerHealth = playerHealth - 10
    END IF
NEXT COLLISION

FOR SPRITES Loop

Process all sprites with a specific tag:

' Move all enemies down
FOR SPRITES e, "enemy"
    MOVE SPRITE e, SPRITEX(e), SPRITEY(e) + 1
NEXT SPRITE

' Count remaining enemies
enemyCount = SPRITECOUNT("enemy")
IF enemyCount = 0 THEN
    PRINT "Level complete!"
END IF

NEXTFREESPRITE - Spawning New Sprites

' Spawn a bullet
s = NEXTFREESPRITE()
IF s >= 0 THEN
    ENABLE SPRITE s
    SET SPRITE s, playerX, playerY, "bullet" TAG "bullet"
    SET SPRITE s BEHAVIOR "flyUp"
END IF

The COLLISION Function

For manual collision (without hardware sprites), use COLLISION:

' Box collision
IF COLLISION("BOX", x1, y1, w1, h1, x2, y2, w2, h2) THEN
    PRINT "Boxes overlap!"
END IF

' Circle collision
IF COLLISION("CIRCLE", cx1, cy1, r1, cx2, cy2, r2) THEN
    PRINT "Circles overlap!"
END IF

' Point in rectangle (mouse clicks)
IF COLLISION("POINT", MOUSEX(), MOUSEY(), btnX, btnY, btnW, btnH) THEN
    PRINT "Button clicked!"
END IF

Boundaries - Invisible Walls and Triggers

What about walls, floors, and trigger zones? You don't want to waste sprites on invisible rectangles. That's what boundaries are for!

' Create walls around the play area
BOUNDARY ADD "left-wall", (0, 0)-(10, 200) SOLID
BOUNDARY ADD "right-wall", (310, 0)-(320, 200) SOLID
BOUNDARY ADD "floor", (0, 190)-(320, 200) SOLID
BOUNDARY ADD "ceiling", (0, 0)-(320, 10) SOLID

Boundaries are invisible rectangles that sprites can collide with. The SOLID keyword means sprites with behaviors can't pass through—they'll stop at the edge.

Detecting Boundary Collisions

Use the three-parameter version of FOR COLLISIONS to detect boundary hits:

FOR COLLISIONS a, b, boundaryTag$
    IF b = -1 THEN
        ' Sprite hit a boundary!
        PRINT "Sprite"; a; "hit"; boundaryTag$

        IF boundaryTag$ = "floor" THEN
            playerOnGround = TRUE
        END IF

        IF boundaryTag$ = "spikes" THEN
            playerHealth = playerHealth - 1
        END IF
    ELSE
        ' Sprite hit another sprite
        PRINT "Sprite"; a; "hit sprite"; b
    END IF
NEXT COLLISION

When b = -1, it means a sprite hit a boundary instead of another sprite. The boundaryTag$ tells you WHICH boundary.

Trigger Zones vs Solid Walls

Without SOLID, boundaries act as trigger zones—sprites pass through but you still detect the collision:

' Solid wall - sprites stop here
BOUNDARY ADD "wall", (100, 0)-(110, 200) SOLID

' Trigger zone - sprites pass through but we detect it
BOUNDARY ADD "checkpoint", (200, 50)-(250, 150)

' In game loop:
FOR COLLISIONS a, b, tag$
    IF b = -1 AND tag$ = "checkpoint" THEN
        PRINT "Checkpoint reached!"
        BOUNDARY DELETE "checkpoint"    ' Remove after triggered
    END IF
NEXT COLLISION

Managing Boundaries

BOUNDARY DELETE "old-platform"    ' Remove one boundary
BOUNDARY CLEAR                    ' Remove ALL boundaries (level transition)

Platformer Example

' Create a simple platformer level
BOUNDARY ADD "ground", (0, 180)-(320, 200) SOLID
BOUNDARY ADD "platform1", (50, 140)-(120, 150) SOLID
BOUNDARY ADD "platform2", (180, 100)-(260, 110) SOLID
BOUNDARY ADD "left-wall", (0, 0)-(10, 200) SOLID
BOUNDARY ADD "right-wall", (310, 0)-(320, 200) SOLID

' Deadly spikes (solid so you can't fall through)
BOUNDARY ADD "spikes", (130, 180)-(170, 190) SOLID

Now your sprites with BMOVE or BACCELERATION behaviors will automatically stop at walls and land on platforms!

Enclosures - Keeping Sprites INSIDE

Sometimes you don't want to block sprites from entering an area—you want to keep them FROM LEAVING. That's what ENCLOSURE does!

Normal boundaries trigger when sprites ENTER them. Enclosures trigger when sprites try to LEAVE them. It's like an inverted boundary.

' Keep all sprites inside the game screen!
BOUNDARY ADD "play-area", (0, 0)-(320, 200) SOLID ENCLOSURE

With this single line, any sprite with a behavior that tries to go off-screen will be stopped at the edge. No need for four separate wall boundaries!

Enclosure vs Four Walls

Four separate walls:

BOUNDARY ADD "left", (0, 0)-(10, 200) SOLID
BOUNDARY ADD "right", (310, 0)-(320, 200) SOLID
BOUNDARY ADD "top", (0, 0)-(320, 10) SOLID
BOUNDARY ADD "bottom", (0, 190)-(320, 200) SOLID

One enclosure:

BOUNDARY ADD "screen", (0, 0)-(320, 200) SOLID ENCLOSURE

Same result, cleaner code!

Non-Solid Enclosures (Trigger Zones)

Without SOLID, enclosures detect when sprites leave but don't stop them:

' Detect when enemy leaves patrol zone
BOUNDARY ADD "patrol-zone", (100, 50)-(250, 150) ENCLOSURE

FOR COLLISIONS a, b, tag$
    IF b = -1 AND tag$ = "patrol-zone" THEN
        ' Sprite left the zone - turn it around!
        SET SPRITE a BEHAVIOR "turnAround"
    END IF
NEXT COLLISION

Arena Example

' Create an arena with a buffer zone

' Main play area - sprites can't escape
BOUNDARY ADD "arena", (20, 20)-(300, 180) SOLID ENCLOSURE

' Warning zone - triggers when getting close to edge
BOUNDARY ADD "edge-warning", (30, 30)-(290, 170) ENCLOSURE

FOR COLLISIONS a, b, tag$
    IF b = -1 AND tag$ = "edge-warning" THEN
        ' Player is near the edge!
        PRINT "Watch out - edge ahead!"
    END IF
NEXT COLLISION

Part 6: Mutations - Polygon Entities

Here's something unique to Crash BASIC: Mutations are polygon-based entities that can have behaviors too!

' Create a triangle mutation
DIM triangle AS MUTATION
triangle = MUTATION((0, 0), (50, 0), (25, 43))

' Draw it
POLYGON triangle, 14, 12    ' Yellow outline, red fill

' Apply a behavior to the whole shape!
SET MUTATION triangle BEHAVIOR "spin"

Mutations are great for:

  • Procedural shapes
  • Morphing polygons
  • Custom collision shapes
  • Special effects

Part 7: Putting It All Together

Let's build a complete example with behaviors, patterns, and collision:

SCREEN 13

' ================================================
' LOAD RESOURCES
' ================================================
LOADPNG "player.png", "player" AS SPRITESHEET(32, 32)
LOADPNG "enemy.png", "enemy" AS SPRITESHEET(32, 32)
LOADPNG "coin.png", "coin" AS SPRITESHEET(16, 16)

' ================================================
' DEFINE BEHAVIORS
' ================================================

BEHAVIOR "idle"
    ANIMATE "player", 0, 1 FRAMERATE 5
END BEHAVIOR

BEHAVIOR "walkRight"
    ANIMATE "player", 0, 1, 2, 3 FRAMERATE 10
    BMOVE 3, 0
    BFLIPX OFF
END BEHAVIOR

BEHAVIOR "walkLeft"
    ANIMATE "player", 0, 1, 2, 3 FRAMERATE 10
    BMOVE -3, 0
    BFLIPX ON
END BEHAVIOR

BEHAVIOR "enemyWalk"
    ANIMATE "enemy", 0, 1, 2 FRAMERATE 8
    BMOVE -1, 0
END BEHAVIOR

BEHAVIOR "coinFloat"
    ANIMATE "coin", 0, 1, 2, 3 FRAMERATE 10
    BOSCILLATE AMPLITUDE 0, 5
END BEHAVIOR

BEHAVIOR "collected"
    BSCALE 1, 1 TO 2, 2 DURATION 15
    BALPHA 1 TO 0 DURATION 15
END BEHAVIOR

' ================================================
' DEFINE PATTERNS
' ================================================

PATTERN "playerControl" LOOP
    "idle"
    "walkRight" WHEN KEYDOWN("RIGHT")
    "walkLeft" WHEN KEYDOWN("LEFT")
END PATTERN

PATTERN "coinCollected"
    "collected"
    DISABLE
END PATTERN

' ================================================
' CREATE SPRITES
' ================================================

' Player
ENABLE SPRITE 0
SET SPRITE 0, 50, 150, "player" TAG "player"
SET SPRITE 0 PATTERN "playerControl"

' Enemies
FOR i = 1 TO 3
    ENABLE SPRITE i
    SET SPRITE i, 320 + i * 100, 150, "enemy" TAG "enemy"
    SET SPRITE i BEHAVIOR "enemyWalk"
NEXT i

' Coins
FOR i = 10 TO 14
    ENABLE SPRITE i
    SET SPRITE i, 80 + (i - 10) * 50, 120, "coin" TAG "coin"
    SET SPRITE i BEHAVIOR "coinFloat"
NEXT i

' ================================================
' GAME VARIABLES
' ================================================
score = 0
gameOver = FALSE

' ================================================
' GAME LOOP
' ================================================

DO
    ' --- COLLISION DETECTION ---
    FOR COLLISIONS a, b
        tagA$ = SPRITETAG$(a)
        tagB$ = SPRITETAG$(b)

        ' Player + Coin = collect
        IF tagA$ = "player" AND tagB$ = "coin" THEN
            SET SPRITE b PATTERN "coinCollected"
            score = score + 10
        ELSEIF tagB$ = "player" AND tagA$ = "coin" THEN
            SET SPRITE a PATTERN "coinCollected"
            score = score + 10
        END IF

        ' Player + Enemy = game over
        IF (tagA$ = "player" AND tagB$ = "enemy") OR (tagB$ = "player" AND tagA$ = "enemy") THEN
            gameOver = TRUE
        END IF
    NEXT COLLISION

    ' --- RESPAWN ENEMIES ---
    FOR SPRITES e, "enemy"
        IF SPRITEX(e) < -32 THEN
            MOVE SPRITE e, 350, SPRITEY(e)
        END IF
    NEXT SPRITE

    ' --- RENDER ---
    BEGIN FRAME
    CLS 9    ' Blue background

    ' Ground
    LINE (0, 180)-(319, 199), 2, BF

    ' UI
    LOCATE 1, 1
    PRINT "Score: "; score

    IF gameOver THEN
        LOCATE 12, 12
        PRINT "GAME OVER!"
    END IF

    END FRAME
    DELAY 16

LOOP UNTIL gameOver AND KEYDOWN("ESCAPE")

Notice how LITTLE code is in the game loop! The sprites handle their own:

  • Animation (via behaviors)
  • Movement (via behaviors)
  • State changes (via patterns)

You just handle collision responses and UI. That's the power of autopilot!


Quick Reference

Typewriter Text

Command What It Does
PRINT RATE(ms) text$ Type text with delay
PRINT WORDS RATE(ms) text$ Word-wrap + typewriter
TYPING() Returns 1 if still typing

Behaviors

Command What It Does
BEHAVIOR "name" ... END BEHAVIOR Define a behavior
SET SPRITE n BEHAVIOR "name" Apply behavior
SET SPRITE n BEHAVIOR DELETE "name" Remove behavior
SET SPRITE n BEHAVIOR NONE Clear all behaviors
HASBEHAVIOR(n, "name") Check if behavior active

Patterns

Command What It Does
PATTERN "name" ... END PATTERN Define a pattern
SET SPRITE n PATTERN "name" Apply pattern
SET SPRITE n PATTERN NONE Clear pattern
"behavior" DURATION ticks Timed step
"behavior" WHEN condition Conditional step

Collision

Command What It Does
SET SPRITE n TAG "tag" Tag a sprite
SPRITETAG$(n) Get sprite's tag
FOR COLLISIONS a, b ... NEXT COLLISION Loop colliding pairs
FOR COLLISIONS a, b, tag$ ... NEXT Loop with boundary detection
FOR SPRITES s, "tag" ... NEXT SPRITE Loop sprites by tag
SPRITECOUNT("tag") Count sprites with tag
NEXTFREESPRITE() Get available sprite slot
COLLISION("BOX", ...) Manual box collision
COLLISION("CIRCLE", ...) Manual circle collision
COLLISION("POINT", ...) Point-in-rect collision

Boundaries

Command What It Does
BOUNDARY ADD "tag", (x1,y1)-(x2,y2) Create trigger zone
BOUNDARY ADD ... SOLID Create solid wall (blocks entry)
BOUNDARY ADD ... ENCLOSURE Inverted zone (triggers on exit)
BOUNDARY ADD ... SOLID ENCLOSURE Keep sprites inside area
BOUNDARY DELETE "tag" Remove a boundary
BOUNDARY CLEAR Remove all boundaries

Try It Yourself!

  1. Create a "power-up" behavior that makes the player blink and grow slightly for 5 seconds

  2. Make an enemy with a patrol pattern that walks back and forth, pausing at each end

  3. Build a simple space shooter where bullets and enemies use behaviors, and FOR COLLISIONS handles hits

  4. Create a "hurt" pattern for the player: flash red, become briefly invincible (GHOST), then return to normal

  5. Make floating platforms using PATH behaviors that move up and down

Autopilot mode lets you build complex games with simple code. Define behaviors once, apply them everywhere, and let Crash BASIC do the heavy lifting!

See you in Chapter 16!


Next Chapter: Is it soup yet? We'll put all the ingredients together and cook up a complete game!