fc — one-page cheat sheet

← teachers   🖨 print   codeonline.io

The game skeleton

to update      -- runs every frame (logic)
  ...
to draw        -- runs every frame (pictures)
  clear screen to dark blue
  ...
run game with update and draw
Comments start with --. A program with no game loop just draws once.

Variables & objects

  • score is 0 — a value (set with is)
  • add 1 to score · remove 1 from score
  • hero is {x: 64, y: 64, hp: 3} — an object
  • hero.x is hero.x + 1 — a field
  • coins is [] · add c to coins — a list
  • each c in coins — loop over a list

Draw

  • clear screen to dark blue
  • draw circle at 64, 64 size 8 in red
  • draw rect at 10, 10 size 20, 6 in white
  • draw sprite "hero" at x, y
  • write "score {score}" at 2, 2 in white on hud
Screen is 128×128. { } drops a value into text.

Decisions & loops

if score > 10
  write "you win!" at 40, 60 in yellow
repeat 5 times
  ...
every 30 frames
  ...
time limit is 30 seconds
when time runs out
  mode is "over"

Move

  • move player with arrows
  • gravity is 0.2 + jump player 2.5
  • follow player with camera
  • ghosts chase player · bats wander
Gravity/jump act on the player.

Collisions (by rule)

coins are pickups
when player picks up any coin
  add 1 to score

rocks are solid       -- blocks movement
foes are hostile
when player hits any foe
  remove 1 from lives

Input

  • when "space" is pressed ...
  • if key "right" ...
  • when mouse is clicked (gives mouse.x, mouse.y)
  • show button "play" at 50, 70
  • when button "play" is clicked · go to play

Sound & sparks

  • play sound "coin" (pickup, jump, shoot, hurt, win…)
  • define sound "pop" as square from 600 to 1200 over 0.06
  • play music "theme"
  • burst 10 sparks at x, y in yellow

Colors

black, dark blue, dark green, brown, dark gray, light gray, white, red, orange, yellow, green, blue, indigo, pink, peach (& cyan, magenta, purple, gold…).