Video Game Design and Coding

PLECK lesson 82 · suggested week 17, day 2

Implement the central challenge fairly

Objective. Connect obstacle behavior to a predictable game rule.

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.

Reliable input, challenge, feedback and reset integration

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-L081.

Build the challenge promised in your proposal: hazard damage, a lock condition, a route obstacle or a resource limit. Define what happens on failure and how the player can recover or restart. Use phase guards and exactly-once flags where needed. A challenge should be understandable from consistent cues. Test an ordinary success, an ordinary failure and a repeated event. Do not add random punishment simply to make the game seem longer.

Worked example

An input-to-feedback chain might be movement, pickup overlap, collected signal, manager score increment, then label refresh. Each stage has one clear responsibility. 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() ``` Scaffold C-PUZZLE — A testable gate rule Setup: Create Node root GateLab and attach this script. The pure gate_open function does not read input or change a scene. A level can call it with its inventory and lever state. Assertions run on start. For the assignment write additional tests before changing the rule. ```gdscript extends Node func gate_open(has_key: bool, lever_on: bool, alarm_on: bool) -> bool: return has_key and lever_on and not alarm_on func _ready() -> void: assert(gate_open(true, true, false)) assert(not gate_open(false, true, false)) assert(not gate_open(true, false, false)) assert(not gate_open(true, true, true)) print("Gate checks passed") ``` 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] ```

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.

A testable gate rule

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

Scene and node setup

Create Node root GateLab and attach this script. The pure gate_open function does not read input or change a scene. A level can call it with its inventory and lever state. Assertions run on start. For the assignment write additional tests before changing the rule.

extends Node
func gate_open(has_key: bool, lever_on: bool, alarm_on: bool) -> bool:
    return has_key and lever_on and not alarm_on
func _ready() -> void:
    assert(gate_open(true, true, false))
    assert(not gate_open(false, true, false))
    assert(not gate_open(true, false, false))
    assert(not gate_open(true, true, true))
    print("Gate checks passed")

Checks to run in the editor

  • Four supplied assertions pass.
  • A complete truth table contains eight input combinations.

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.

Implement the central challenge fairly — evidence task

  1. 1. Implement the central challenge and its feedback.
  2. 2. Run success, failure and repeated-event tests.

Deliverable. Challenge checkpoint and three-event test evidence.

Acceptance checks

  • VGC-L082-T1. The rule is applied consistently.
  • VGC-L082-T2. Repeated events do not duplicate rewards or produce negative resources.

Understanding question. Why test a repeated event separately?

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 your state-owner diagram to fix one system at a time. Keep the vertical-slice checkpoint available for comparison. Start with the first assigned task and re-run its acceptance test before adding the remaining feature.

Optional extra. Add one optional challenge only after the complete minimum loop passes. 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