Video Game Design and Coding · PLECK lesson
PLECK lesson 70 · suggested week 14, day 5
Add a distinct goal state
Objective. Detect completion once and stop accepting conflicting gameplay.
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.
Progress markers, camera framing, collision feedback and limited forgiveness
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-L069.
Place a goal Area2D after the final platform. Its signal should notify the level manager only when a player enters and the phase is Play. On completion, show Delivered, stop Player physics, and offer Restart. Do not keep teleporting a completed player through a fall zone. Reuse the exclusive-state approach from Meteor Mail rather than introducing separate won/lost flags. Goal feedback should use text and an original symbol, not sound alone.
Worked example
A checkpoint trigger and safe spawn marker serve different roles. The trigger notices arrival, while the marker specifies a collision-free return location above a platform. 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] ``` 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 ```
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.
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.
Add a distinct goal state — evidence task
- 1. Add goal detection, completion feedback and Restart.
- 2. Touch goal twice, then restart and complete again.
Deliverable. Relay Runner full-loop checkpoint and goal/reset tests.
Acceptance checks
- VGC-L070-T1. Completion occurs exactly once per round.
- VGC-L070-T2. Restart restores player motion and the initial checkpoint.
Understanding question. Why guard the goal handler if the player is disabled after winning?
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. Use one checkpoint on a broad platform and keep the camera fixed until respawn is reliable. Start with the first assigned task and re-run its acceptance test before adding the remaining feature.
Optional extra. Compare start-only retries with a midpoint checkpoint using the same route. Document one changed parameter, your prediction, and the observed effect; optional, not required for completion.
- 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.
Name ____________________ Date ____________________