Video Game Design and Coding · PLECK lesson
PLECK lesson 99 · suggested week 20, day 4
Synchronize sound with a validated event
Objective. Play a cue after the rule accepts the action.
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.
Original sound, safe levels, activation, mute and licensing
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-L098.
Play sound after a valid state change, not merely after an attempted input. A denied purchase should not use the same success chime as a completed purchase. For a pickup, the manager can update score and then request the collect cue once. Duplicate collision notifications should still produce one reward and one cue. Use a separate quieter failure cue only if it adds useful information, and keep failure text. Test repeated events and invalid actions rather than listening only to a successful case.
Worked example
A short original tap sound confirms a collected object while a number changes on screen. Muting the tap leaves all required information visible. Scaffold C-AUDIO — Local audio playback with a reversible mute Setup: Create Control AudioLab with Button Play and CheckButton Mute. Child AudioStreamPlayer Sound: copy the supplied student-support/audio/course-tap.wav into your project audio folder and assign it (or another short original WAV/OGG), autoplay Off, volume_db -12. Attach script to AudioLab. Recording is optional: a teacher-provided original file is equivalent. No microphone or face recording is required and all recording stays private. ```gdscript extends Control func _ready() -> void: $Play.pressed.connect(_play) $Mute.toggled.connect(_mute) func _play() -> void: if not $Mute.button_pressed: $Sound.play() func _mute(enabled: bool) -> void: if enabled: $Sound.stop() ``` Scaffold C-PICKUP — An exactly-once pickup signal Setup: Create Area2D root Coin, CollisionShape2D Circle radius 10. Layer 3 (bit value 4), mask layer 1 only. Monitoring on. Attach script and save Coin.tscn. In the Node > Groups editor add Player root to group player. Put a Coin instance and Player instance in World. Manager connects each Coin.collected to its score handler (see C-MANAGER). Signal wiring here is code-only: do not also connect body_entered in editor. ```gdscript extends Area2D signal collected(points: int) @export var points: int = 1 var taken: bool = false func _ready() -> void: body_entered.connect(_on_body_entered) func _draw() -> void: draw_circle(Vector2.ZERO, 10.0, Color.GOLD) draw_line(Vector2(-5, 0), Vector2(5, 0), Color.BLACK, 2.0) func _on_body_entered(body: Node2D) -> void: if taken or not body.is_in_group("player"): return taken = true collected.emit(points) queue_free() ```
Local audio playback with a reversible mute
GDScript (Godot 4, not Scratch, Python, JavaScript or C#). Scaffold C-AUDIO. Copy starts from this text. The desk does not run it.
Scene and node setup
Create Control AudioLab with Button Play and CheckButton Mute. Child AudioStreamPlayer Sound: copy the supplied student-support/audio/course-tap.wav into your project audio folder and assign it (or another short original WAV/OGG), autoplay Off, volume_db -12. Attach script to AudioLab. Recording is optional: a teacher-provided original file is equivalent. No microphone or face recording is required and all recording stays private.
extends Control
func _ready() -> void:
$Play.pressed.connect(_play)
$Mute.toggled.connect(_mute)
func _play() -> void:
if not $Mute.button_pressed:
$Sound.play()
func _mute(enabled: bool) -> void:
if enabled:
$Sound.stop()
Checks to run in the editor
- Play produces sound only after user activation.
- Mute stops playback and suppresses future Play until unchecked.
- Equivalent visual cue remains available in assignment.
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.
An exactly-once pickup signal
GDScript (Godot 4, not Scratch, Python, JavaScript or C#). Scaffold C-PICKUP. Copy starts from this text. The desk does not run it.
Scene and node setup
Create Area2D root Coin, CollisionShape2D Circle radius 10. Layer 3 (bit value 4), mask layer 1 only. Monitoring on. Attach script and save Coin.tscn. In the Node > Groups editor add Player root to group player. Put a Coin instance and Player instance in World. Manager connects each Coin.collected to its score handler (see C-MANAGER). Signal wiring here is code-only: do not also connect body_entered in editor.
extends Area2D
signal collected(points: int)
@export var points: int = 1
var taken: bool = false
func _ready() -> void:
body_entered.connect(_on_body_entered)
func _draw() -> void:
draw_circle(Vector2.ZERO, 10.0, Color.GOLD)
draw_line(Vector2(-5, 0), Vector2(5, 0), Color.BLACK, 2.0)
func _on_body_entered(body: Node2D) -> void:
if taken or not body.is_in_group("player"):
return
taken = true
collected.emit(points)
queue_free()
Checks to run in the editor
- A player touching the coin emits once and removes it.
- A wall or hazard touching the coin does not collect.
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.
Synchronize sound with a validated event — evidence task
- 1. Connect one success cue to the accepted state update and one visible equivalent.
- 2. Test valid, invalid and repeated attempts.
Deliverable. Event-audio implementation and three-attempt evidence.
Acceptance checks
- VGC-L099-T1. Invalid attempts do not trigger success audio.
- VGC-L099-T2. Exactly-once events do not produce stacked duplicate sounds.
Understanding question. Why is button-pressed not always the correct place for a success sound?
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 short teacher-provided original sound or a privately recorded tap. Keep volume modest and retain text cues. Start with the first assigned task and re-run its acceptance test before adding the remaining feature.
Optional extra. Compare two sound choices with the same loudness and explain which better communicates the event. 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. - Exporting for the Web
Free public documentation. Local editor play is the required alternative to web export.
· Opening this link does not submit the lesson.
Name ____________________ Date ____________________