Video Game Design and Coding

PLECK lesson 153 · suggested week 31, day 3

Complete a fair challenge and recovery path

Objective. Ensure failure teaches or resets rather than trapping the player.

Godot Engine Standard desktop editor 4.7.2-stable, GDScript (Godot 4), Compatibility renderer. Headless Godot 4.7.2.stable.official.ed1daf0bf passed 106 assertions on the supplied scaffolds, including malformed JSON saves. Audio used the Dummy driver and a synthetic WAV, not a speaker. The visual editor, browser export, and signed-in submission were not tested. The desk still does not run a student's own upload.

About 55 minutes. The due date is chosen by a parent.

Input robustness, rule completion, challenge and progress

Suggested pace: Recall and predict 5 min; Read instruction and scaffold 12 min; Build or design the assigned artifact 25 min; Run acceptance tests 8 min; Explain and checkpoint 5 min.

Materials: Godot Standard 4.7.2 desktop editor (GDScript, Compatibility renderer), Local course folder and prior checkpoint, No paid assets or public account required.

Comes after VGC-L152.

Implement the challenge’s full response and recovery. A fall returns to a safe checkpoint, damage honors recovery time, a failed puzzle gives useful feedback, or an invalid transaction preserves resources. Test the worst legal action order you can imagine. If the game intentionally allows loss, provide a clear ending and restart instead of an unexplained soft lock. A soft lock is a state where play continues but the goal has become impossible without the player knowing why.

Worked example

A repeat-input test might press a one-time choice rapidly. The accepted event happens once, while later calls observe the changed state and do nothing. Scaffold C-CHECKPOINT — A safe checkpoint respawn Setup: Add this pattern to a separate Node2D level root with child Player using C-PLATFORM. Call set_checkpoint with a safe global position when a player reaches a checkpoint Area2D; call respawn when entering a fall zone. This code does not connect Area2D automatically; select the area body_entered signal in editor and call these methods from its handler after checking the player group. Respawn is deferred because a physics callback may be active. ```gdscript extends Node2D @onready var player: CharacterBody2D = $Player var checkpoint: Vector2 func _ready() -> void: checkpoint = player.global_position func set_checkpoint(safe_position: Vector2) -> void: checkpoint = safe_position func respawn() -> void: _apply_respawn.call_deferred() func _apply_respawn() -> void: player.global_position = checkpoint player.velocity = Vector2.ZERO ``` Scaffold C-STATES — Explicit game states and gated scoring Setup: Attach to Node root StateLab with child Label Status. This is a standalone demonstrator; call start_round, add_points, finish_round from buttons or Remote Inspector. In a real game the manager owns this state. Additional Player and spawner scripts must also honor the manager’s state, or be disabled when finishing. ```gdscript extends Node enum Phase { TITLE, PLAY, WIN, LOSE } var phase: Phase = Phase.TITLE var score: int = 0 func _ready() -> void: _show() func start_round() -> void: score = 0 phase = Phase.PLAY _show() func add_points(amount: int) -> void: if phase != Phase.PLAY: return score += maxi(amount, 0) _show() func finish_round(won: bool) -> void: if phase != Phase.PLAY: return phase = Phase.WIN if won else Phase.LOSE _show() func _show() -> void: $Status.text = "State: %s | Score: %d" % [Phase.keys()[phase], score] ```

A safe checkpoint respawn

GDScript (Godot 4, not Scratch, Python, JavaScript or C#). Scaffold C-CHECKPOINT. Copy starts from this text. The desk does not run it.

Scene and node setup

Add this pattern to a separate Node2D level root with child Player using C-PLATFORM. Call set_checkpoint with a safe global position when a player reaches a checkpoint Area2D; call respawn when entering a fall zone. This code does not connect Area2D automatically; select the area body_entered signal in editor and call these methods from its handler after checking the player group. Respawn is deferred because a physics callback may be active.

extends Node2D
@onready var player: CharacterBody2D = $Player
var checkpoint: Vector2
func _ready() -> void:
    checkpoint = player.global_position
func set_checkpoint(safe_position: Vector2) -> void:
    checkpoint = safe_position
func respawn() -> void:
    _apply_respawn.call_deferred()
func _apply_respawn() -> void:
    player.global_position = checkpoint
    player.velocity = Vector2.ZERO

Checks to run in the editor

  • A fall returns to last safe point, not origin.
  • Player has no leftover falling velocity on return.

Native Godot 4.7.2.stable.official.ed1daf0bf headless compile and representative node-tree/runtime tests passed; see native-qa-results.json. Visual UI, audible output, exports and website submission still need separate checks.

Explicit game states and gated scoring

GDScript (Godot 4, not Scratch, Python, JavaScript or C#). Scaffold C-STATES. Copy starts from this text. The desk does not run it.

Scene and node setup

Attach to Node root StateLab with child Label Status. This is a standalone demonstrator; call start_round, add_points, finish_round from buttons or Remote Inspector. In a real game the manager owns this state. Additional Player and spawner scripts must also honor the manager’s state, or be disabled when finishing.

extends Node
enum Phase { TITLE, PLAY, WIN, LOSE }
var phase: Phase = Phase.TITLE
var score: int = 0
func _ready() -> void:
    _show()
func start_round() -> void:
    score = 0
    phase = Phase.PLAY
    _show()
func add_points(amount: int) -> void:
    if phase != Phase.PLAY:
        return
    score += maxi(amount, 0)
    _show()
func finish_round(won: bool) -> void:
    if phase != Phase.PLAY:
        return
    phase = Phase.WIN if won else Phase.LOSE
    _show()
func _show() -> void:
    $Status.text = "State: %s | Score: %d" % [Phase.keys()[phase], score]

Checks to run in the editor

  • Calling add_points before start does not change score.
  • After finish_round, extra score events do nothing.

Native Godot 4.7.2.stable.official.ed1daf0bf headless compile and representative node-tree/runtime tests passed; see native-qa-results.json. Visual UI, audible output, exports and website submission still need separate checks.

Complete a fair challenge and recovery path — evidence task

  1. 1. Implement recovery or explicit loss for the central challenge.
  2. 2. Test three failure sequences including a repeated event.

Deliverable. Challenge/recovery checkpoint and failure-sequence log.

Acceptance checks

  • VGC-L153-T1. Every tested failure has a clear next action.
  • VGC-L153-T2. No unexplained unwinnable state remains.

Understanding question. How is an explicit Lose screen different from a soft lock?

Include a downloadable project ZIP with project.godot, .tscn, .gd and original asset files when code changes. A private, teacher-accessible download link to that ZIP is equivalent. Screenshots or a playthrough do not replace editable source.

If this is still shaky. Work on one task-board item at a time and checkpoint after each passing test. Do not expand the room count yet. Start with the first assigned task and re-run its acceptance test before adding the remaining feature.

Optional extra. Add a harmless alternate input or optional route after required mechanics pass. Document one changed parameter, your prediction, and the observed effect; optional, not required for completion.

Turn in typed notes and a JPEG, PNG, or WebP screenshot. One https address is stored as text and is not opened, extracted, or run. An MP3, WAV, M4A, MP4, or WebM file up to 4 MB can show a demo. The demo does not replace editable source. Zip and code files are refused. If there is no private link, keep the project on the family computer and review the code in person.

  • Your first 2D game

    Free public tutorial; no account; external asset download is optional, not used by this course.

    · Opening this link does not submit the lesson.

This is a preview. A parent assigns the lesson and chooses the due date after the student is enrolled. The answer key is not on this page.

Print this lesson