Video Game Design and Coding · PLECK lesson
PLECK lesson 32 · suggested week 7, day 2
Animate a falling hazard
Objective. Use elapsed time and remove objects beyond the playfield.
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.
Meteor Mail spawning, instancing and cleanup
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-L031.
C-HAZARD moves an Area2D down at a speed measured in pixels per second. Unlike CharacterBody2D move_and_slide, this direct position update needs delta. Start with a manually placed hazard at (320,-20). Its y coordinate grows until it passes 390, safely below the 360-pixel viewport. queue_free then removes it. Without cleanup, invisible objects accumulate and continue consuming processing time. The black cross distinguishes hazards from round gold deliveries without relying only on red versus gold.
Worked example
A Timer with wait_time 2 creates one hazard per timeout. A hazard traveling 100 pixels/second moves 50 pixels during half a second and is removed after leaving the playfield. Scaffold C-HAZARD — Falling hazard with player notification and cleanup Setup: Area2D Hazard root on layer 4 (bit 8), mask layer 1 only, child CollisionShape2D circle radius 12. Attach this script. Player in group player. A Player damage method is deliberately not hardcoded: connect hit_player to a manager’s damage handler when instantiating. Parent Hazards must be unscaled and unrotated. ```gdscript extends Area2D signal hit_player @export var fall_speed: float = 110.0 var hit: bool = false func _ready() -> void: body_entered.connect(_on_body_entered) func _draw() -> void: draw_rect(Rect2(-12, -12, 24, 24), Color.TOMATO) draw_line(Vector2(-8,-8),Vector2(8,8),Color.BLACK,2.0) func _physics_process(delta: float) -> void: position.y += fall_speed * delta if position.y > 390.0: queue_free() func _on_body_entered(body: Node2D) -> void: if hit or not body.is_in_group("player"): return hit = true hit_player.emit() queue_free() ```
Falling hazard with player notification and cleanup
GDScript (Godot 4, not Scratch, Python, JavaScript or C#). Scaffold C-HAZARD. Copy starts from this text. The desk does not run it.
Scene and node setup
Area2D Hazard root on layer 4 (bit 8), mask layer 1 only, child CollisionShape2D circle radius 12. Attach this script. Player in group player. A Player damage method is deliberately not hardcoded: connect hit_player to a manager’s damage handler when instantiating. Parent Hazards must be unscaled and unrotated.
extends Area2D
signal hit_player
@export var fall_speed: float = 110.0
var hit: bool = false
func _ready() -> void:
body_entered.connect(_on_body_entered)
func _draw() -> void:
draw_rect(Rect2(-12, -12, 24, 24), Color.TOMATO)
draw_line(Vector2(-8,-8),Vector2(8,8),Color.BLACK,2.0)
func _physics_process(delta: float) -> void:
position.y += fall_speed * delta
if position.y > 390.0:
queue_free()
func _on_body_entered(body: Node2D) -> void:
if hit or not body.is_in_group("player"):
return
hit = true
hit_player.emit()
queue_free()
Checks to run in the editor
- Hazard moves downward and disappears beyond y390.
- One overlap emits one damage event.
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.
Animate a falling hazard — evidence task
- 1. Create Hazard.tscn with C-HAZARD and test one falling instance.
- 2. Observe its scene-tree presence before and after it leaves.
Deliverable. Hazard project and cleanup observation.
Acceptance checks
- VGC-L032-T1. The hazard travels downward at a steady rate.
- VGC-L032-T2. It disappears from the Remote tree after passing y390.
Understanding question. Why does this recipe use delta when C-BODY does not?
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 manually placed falling hazard before enabling SpawnTimer. Keep the world unscaled and viewport 640 by 360. Start with the first assigned task and re-run its acceptance test before adding the remaining feature.
Optional extra. Compare two spawn intervals while keeping hazard speed fixed. 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 ____________________