Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Hello again!

Crash-tan, saluting with a wink: purple hair, an orange hoodie with her name on it, and teal trainers.

It’s me, Crash-tan! Last time I showed you my language. This time I’m showing you my engine: the part of me that draws, moves sprites around, knocks them into each other and plays the music while it happens.

I’ll assume you’ve been through Learn Crash BASIC, so you know what a FUNCTION, a list and a !! modifier are. If something here looks new, it’s about the engine, and I’ll explain it.

How this page works

The lesson is on this side. On the other side there’s an editor with real code in it, and the game’s screen under that. It’s all real: that’s my whole engine over there, running in your browser, the same one that runs your games on a phone or a PC.

Every piece of code in a lesson has a Try it button. Press it and the code goes into the editor and runs. Then change it! Press Run (or Ctrl + Enter) to run it again, Stop to stop a game that’s still going, and Reset when you’d like the lesson’s version back.

SCREEN 320, 240
PRINT "Hello! I'm Crash-tan."
CIRCLE (160, 140), 40, 14, 14
Hello! I'm Crash-tan.

SCREEN opens a screen 320 pixels wide and 240 high, and everything after it draws on that. PRINT writes on the screen too. Under a piece of code in a lesson, the box marked “prints” is what it writes. CIRCLE takes a center, a radius, the color of its edge and the color to fill it with: 14 is yellow.

Crash-tan’s Tip: A game that wants keys needs the screen to have the focus. Click the screen, then press away. Clicking back in the editor gives the keys back to the editor.

Break something

Go on: change CIRCLE to CIRCEL over there and run it. My error messages say what I was looking at and what to try next, and it’s nicer to meet them now, while nothing’s at stake.

SCREEN 320, 240
CIRCEL (160, 120), 40, 14

Over in the editor, I check what you type as you go, and a line under the code tells you about the first thing I’d trip over before you even press Run.

A game is a program that keeps going

Everything above ran and was done. A game doesn’t end until somebody stops it: it draws a frame, looks at the keys, moves things, and does it again. Here’s the smallest one I can think of. It goes until you press Stop.

SCREEN 320, 240
x = 0
DO
    IF COOLDOWN(1)
        MEMORYBUFFER "scene"
            CIRCLE (x, 120), 12, 12, 12
        END MEMORYBUFFER
        FRAME
            CLS
            PUTIMAGE (0, 0), "scene"
        END FRAME
        x = (x + 2) MOD 320
    END IF
LOOP

That’s most of what the next few lessons are about: drawing, the frame, and the loop that keeps a game going. Then I’ll show you the parts of me that do the busy work for you, so your loop can stay small.