🧠Concept
Pick the right answer.
game_state variable. What does this variable hold?game_state variable holds "play", so only the play code runs this frame. Next frame the player loses, so game_state changes to "game over". What does this design guarantee?game_state variable. What is the most common bug after the first run?if blocks below run in the same frame: the player presses space while past x = 200, so both checks are true. What happens to game_state?if <key (space v) pressed?> then set [game_state v] to [play] end if <(x position) > (200)> then set [game_state v] to [game over] end
👀Code Reading
Look at the blocks. Predict what happens.
game_state hold after this setup script runs?when flag clicked set [game_state v] to [start] set x to (-100)
game_state is "play" and the left arrow is NOT pressed. What happens?forever
if <(game_state) = [play]> then
if <key [left arrow v] pressed?> then
change x by (-3)
end
end
if <<(game_state) = [play]> and <not <key [left arrow v] pressed?>>> then
set [game_state v] to [start]
end
if <(game_state) = [game over]> then
stop [this script v]
end
endwhen flag clicked
set [game_state v] to [start]
forever
if <key [space v] pressed?> then
set [game_state v] to [play]
end
if <(game_state) = [play]> then
change y by (5)
end
if <(game_state) = [start]> then
set x to (-100)
end
end🐛Find the Bug
Something is broken. Pick the fix.
This game should reset to the start screen when the flag is clicked. But after a game over and a restart, the sprite runs the game over code at once. What is the fix?
when flag clicked
forever
if <(game_state) = [start]> then
set x to (-100)
end
if <(game_state) = [play]> then
change x by (3)
end
if <(game_state) = [game over]> then
say [Game Over] for (2) secs
stop [all v]
end
end🛠️Build It
Pick a level. Build it. Check the boxes.
Move right only in the play screen.
More
Build a two-screen game: "start" and "play". Use a game_state variable. When the right arrow is held, game_state = "play" and the sprite moves right. When released, game_state = "start" and the sprite stops. Always reset game_state to "start" at flag click.
Done when
game_state is set to "start" at flag click. The loop uses if (game_state) = [play] and if (game_state) = [start]. The screen switches correctly on key press and release. No overlapping screen code.
Start, play, and game over screens.
More
Add a "game over" screen. The game reaches it on the space key from the play screen, or when an enemy sprite touches the player. Reset the game_state variable at flag click.
Done when
Three screens are built: start, play, game over. Each screen is handled in its own if block. The game over screen ends the game. The game_state variable resets at flag click.
Reach the edge, win, then start again.
More
Add a "win" screen with a 2-second message. When the player reaches the right edge, game_state = "win". During "win", the sprite cannot be controlled. After 2 seconds, game_state returns to "start". No other screen interrupts "win".
Done when
The "win" screen blocks input for 2 seconds. A win message is visible. After it ends, the screen returns to "start". No other screen change fires during "win".
Review the student's project, then check each thing they did.
Project Evaluation
0 of 4 ticked
💬Talk About It
Present your project to your teacher or a classmate.
- 1️⃣Show your project.
- 2️⃣Point to the
game_statevariable. - 3️⃣Make one screen change and say the new screen out loud.
Watch the student present, then check each thing they did.
Presentation Checklist
0 of 4 ticked
📤Submit
Send your results to your teacher and parent.
0 of 0 answered