Crash-tan Crash-tan

2.2.0 is out with a new scene builder!

Crash BASIC 2.2.0 Release Notes

written by Crash-tan

Scenes you can lay out instead of type out! A scene file holds a piece of
your world (its pictures, its layers, its walls and floors, and every sprite
with where it stands and what it does), and one line puts it on screen.

SCENE FILES

BEGIN SCENE "level1" FROM "level1.scene.json"
  hero = SCENENODE("hero")
  WHILE NOT KEYDOWN("ESCAPE")
    YIELD
  WEND
END SCENE

FROM builds the file as the scene begins, on top of the world as it is.
Everything it builds belongs to the scene, so END SCENE takes it all away
again and puts your world back, exactly like anything else made inside a
scene.

A scene file has:

  • images to load
  • layers: map layers from your .map.json files, and plain ones, with
    their alpha, wrap, clip, plane, shader and scroll
  • boundaries: written out, from a boundaries file, or traced from a layer
  • sprites, as a tree: a sprite's children are attached to it, at their
    offset from it, with their images, frames, tags, hitboxes, behaviors and
    pattern, and the values for their @parameters

A sprite can also bring a whole file with it: a .rig.json, or another scene
file used as a prefab. Put the same door down five times and each one is
its own door.

I check the whole file before I build any of it. A typo'd key, a picture
that isn't there, a behavior nobody defined: I tell you the file and the
exact place in it, and nothing gets half-built.

In BASIC 2 it's SCENE "level1" !! from("level1.scene.json"), and in Python,
Lua and JavaScript it's the from option on crash.scene.

SCENENODE

Sprites from a scene file get free sprite numbers, so they never bump into
yours. Find them by name: SCENENODE("hero"), or SCENENODE("door1/hinge")
for a sprite inside a prefab. Scenes inside scenes look in the innermost one
first.

In CrashNet

Every player and the server run the same BEGIN SCENE ... FROM, and each
builds its own part: the host builds the shared world, each player's server
builds that player's own nodes (give a node "authority": "player" and
everyone gets their own avatar), and each player's screen builds its local
ones. SCENENODE gives every one of them the same answer. A player who joins
late walks straight into the scene, with everything already in it. If the
host's half takes longer than SCENE TIMEOUT (5 seconds unless you set it in
the CRASHNET block), I tell you which names never arrived.

SAVE SCENE

SAVE SCENE TO "slot1.scene.json"

Saves the game. I write the whole world out as a scene file, as it is right
now: every sprite with its settings, its behaviors with how far along they
are (the random VARIANCE they rolled, the way along their path, the step
their pattern is on), the layers with what's drawn on them, the boundaries,
and the pictures. BEGIN SCENE "game" FROM "slot1.scene.json" puts it all
back and play carries on from exactly there. Your own variables aren't part
of a scene, so save those beside it with SAVEJSON.

SAVE SCENE "edit" TO f$ writes only what one scene made, for an editor
that runs inside a scene and saves the level it's editing.
SAVE SCENE FROM SPRITE door TO f$ writes one sprite and its children as a
prefab. Add WITH DEFINITIONS and the behaviors and patterns they use go in
the file too.

In CrashNet each side saves its own part: the host the world, each player's
server that player's things, each screen its local ones. When everyone then
loads a file the server saved, a player who doesn't have it is sent the
server's copy. demos/crashnet_scene_editor is one player editing a level,
saving it, and everyone, late joiners too, playing the saved version.

CHECKING AND PREVIEWING

crashplayer --validate checks every scene file in your game too, the same
way loading it would, and tells you the file and the place in it. Anything
only your running program can answer (a picture it makes, say) comes back as
a note rather than an error.

crashplayer --scene level.scene.json --screen 320x240 game shows a scene
file as it stands on its own, in a game in any of the five languages: the
behaviors and patterns it carries move, and nothing of your program runs. A
behavior it names that only your program defines is left off, and I tell you
which, because a scene can't count on what it doesn't carry.

THE SCENE EDITOR

Open a .scene.json in the IDE and lay it out: your map layers drawn from
their tilesets, every sprite where the game will put it, prefabs drawn from
their own files, boundaries over the top. "New scene..." in the file list's
menu starts a file from nothing. Snap puts what you move and draw on the
map's tiles.

  • Sprites: drag them about, turn and scale them with their handles, and
    drop a picture from the file list to make a new one. The sprite you pick
    shows its collision box, and the inspector sets it and everything else.
  • The tree: drag nodes into their places or onto the one they belong to,
    and right-click a node for the rest.
  • Boundaries: draw them, drag them to move them, and drag their edges and
    corners to size them. They move with their layer's scroll, a slope is
    drawn as its solid triangle, and a one-way face is drawn heavy, with arrows
    the way it stops you.
  • Planes: a layer can be AFFINE or PERSPECTIVE, with its zoom, horizon,
    height and heading, and its wrap and clip. You lay a plane out flat, from
    above, with its camera drawn on it (where it stands, which way it looks and
    the floor it sees). Camera view shows it through that camera, as the game
    will.
  • Behaviors: the Behaviors page builds the file's own. Add one, put
    commands in it, and give each number a value, a VARIANCE or an
    @parameter with its default. They are kept in the scene file, so they
    work the same in a game written in any of the five languages, and a game
    that never defined them still runs them.
  • Preview runs the scene in the game player, on the desktop and in the
    browser, at the screen size you pick for it.

What you see is what the game draws: the editor builds the scene with the
game's own loader, and the canvas is drawn by CrashGFX, the game's renderer.

The editor and Preview show a scene as it stands on its own, whatever
language your game is in: nothing of your program runs. A behavior or pattern
a node names that only your program defines is left off there, and I tell you
which, because a scene can't count on what it doesn't carry. In your game it
runs as always.

THE LATEST ONE WINS

Behaviors, patterns and pictures all work the same way now: whatever was
loaded or defined last under a name is the one in use. A scene file's
behavior replaces yours of the same name, and you can replace it right back.

A SMALLER WEB PLAYER

The colour emoji font is no longer built into the web player's renderer or
the IDE: it is its own file, fonts/FluentEmojiFlat.ttf, fetched once by a
page and shared by both. The renderer's module drops from 29 MB to under
3 MB. The web runtime and web exports carry the font beside the player.
A page of your own that starts the renderer (crashgfx_wasm.js) without
crashplayer.js hands it the font with gfx_supply_emoji_font(bytes)
before drawing; crashplayer/emoji-font.js fetches it.

FIXES

  • A sprite swinging back and forth (OSCILLATE, BOSCILLATE) stays on its
    swing when SET SPRITE gives it only an x or only a y. Set its x every
    frame while it bobbed up and down, and the bob used to wander hundreds of
    pixels off, because the y it wasn't given became the middle of the swing.
  • A sprite taller or wider than a sloped boundary now meets it. A box that
    spanned the whole slope, its top above it and its bottom below, went straight
    through, so whether a sprite hit a small ramp could depend on where its
    ORIGIN put its box.
  • SET SPRITE on a sprite with a PARENT now shows it where it is in the
    world straight away. For one frame it used to be drawn at its offset from
    the top-left corner of the screen, turned about a different point, until the
    engine's next tick put it right.
  • A picture loaded inside a scene under a name you'd already used no longer
    leaves your sprites with nothing to show after END SCENE. The old one comes
    back.
  • Pictures made inside a scene with TEXTTOIMAGE, GETIMAGE or
    BEGIN MEMORYBUFFER are cleaned up at END SCENE, like every other picture.
  • A rig loaded onto a sprite inside a scene (LOAD RIG ... ONTO SPRITE) no
    longer leaves its parts on screen after END SCENE.
  • In CrashNet, a player's END SCENE puts back only that player's sprites.
    It used to roll the whole world back to where it was when their scene
    began, undoing everything the host and the other players had done since.
  • In CrashNet, a player's END SCENE no longer frees pictures on their screen
    twice.
  • In CrashNet, a map made from a file (CREATE MAP("level.map.json")) on the
    host now reaches every player, as named maps always have.
  • In CrashNet, a player who joins late now sees the maps and layers everyone
    else already has, not just the sprites.
  • In CrashNet, a sprite's scroll is no longer applied twice: the server sends
    where things are in the world, and each player's screen scrolls by itself.
  • In CrashNet, the same BOUNDARY ADD run by every server is kept once, so a
    wall no longer reports each bump several times.
  • In CrashNet, changing a sprite someone else made tells you whose it is (the
    host, or player 2) and how to fix it, instead of pointing you at
    ME.SPRITES, which is long gone.
  • In the IDE, a Crash BASIC 2 statement's hint shows its arguments once. It
    used to show them twice, run together.
  • In the IDE's debugger, a Crash BASIC 2 game stopped in its main program
    shows its call stack and its thread. It used to say "not stopped" with no
    threads, whenever nothing was holding a value at that moment. A runtime
    error in the main program keeps its call stack too.
  • In the IDE, a mistake about a name (one that nothing gives a value, say) is
    underlined on that name, and the Problems tab gives its column, instead of
    the whole line from column 1.