Star Student Builder logoStar Student Builder
← Systems, Data and the Way Out Std 9–12Project 1 of 4

Menu, Game, Game Over β€” a State Machine

🎯 A project with a title screen, a playing state and an end screen, properly separated.

πŸ’‘ The idea behind it

Almost every real program is a state machine: it is in exactly one state at a time, and events move it between them. Most messy Scratch projects are messy because nobody told the author this.

🧱 Blocks you will need

variable (state)broadcastwhen I receiveif … thenstop this script

πŸ”¨ Build it

  1. Make a variable called state, holding 'menu', 'play' or 'over'.
  2. Every sprite's forever loop begins with: if state = 'play' β€” and does nothing otherwise.
  3. Clicking Start sets state to 'play' and broadcasts startGame, which resets score, lives and positions.
  4. Losing sets state to 'over' and broadcasts gameOver, which shows the end screen.
  5. Nothing anywhere else needs to know about screens. Each part asks only what state the program is in.

πŸš€ Make it harder

  • Add a paused state that freezes everything without losing it.
  • Add levels as a second variable, and reset positions between them.

🐞 Bugs you will hit

  • Game logic runs on the menu screen: a loop somewhere is missing its state check.
  • Score carries over between games: your startGame handler is not resetting everything it should.

⬇ Need Scratch itself?

Free from MIT, in a browser or as an offline app that needs no connection at all.

Get it β†’
Ask GuruAcharya Samayeshwar