PLECK lesson 135 · suggested week 27, day 5
Submit Garden Patrol
Objective. Deliver a bounded playable AI/procedural game.
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.
Constraints, bounded systems, seed testing and an AI assessment
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-L134.
The finished game needs one readable patrol/chase/return guard, a seeded generated layout, a guaranteed required route, a clear goal, safe reset and an explicit actor/object cap. Include your state diagram, reserved-cell map, seed test matrix and limitations note. Keep all execution local; no networking or generated personal data is needed. Restore the project and play one complete seeded round before submitting. Optional recordings supplement the code and reproducible seed evidence.
Worked example
A procedural bug report might say seed 17, build alpha2, start at entrance, move right, expected clear corridor, actual blocking wall. The seed makes reproduction practical. Scaffold C-GRID — A deterministic grid with a guaranteed clear route Setup: Attach to Node2D GridLab. This example draws, not physics, so the assignment adds matching wall collision only after validation. Grid is 8 columns by 6 rows at 40 pixels per cell. Row 0 and column 7 are a guaranteed clear route from (0,0) to (7,5). RNG seed is a nonpersonal integer. ```gdscript extends Node2D const COLS: int = 8 const ROWS: int = 6 const CELL: int = 40 var cells: Array = [] func _ready() -> void: var rng := RandomNumberGenerator.new() rng.seed = 2468 for y in range(ROWS): var row: Array[int] = [] for x in range(COLS): var blocked: bool = y != 0 and x != COLS - 1 and rng.randf() < 0.25 row.append(1 if blocked else 0) cells.append(row) queue_redraw() func _draw() -> void: for y in range(cells.size()): for x in range(cells[y].size()): var color := Color.DIM_GRAY if cells[y][x] == 1 else Color.BEIGE draw_rect(Rect2(x * CELL, y * CELL, CELL - 2, CELL - 2), color) ``` Scaffold C-GUARD-AI — A readable patrol/chase/return state machine Setup: Create CharacterBody2D Guard with visible circle or polygon and matching collider. Layer 4 mask 2 for walls. Attach script and assign target to your Player instance in Inspector. Level is one open rectangle; this is steering, not navigation around walls. Damage remains a separate sensor/manager event. Draw detection radii on a design diagram before tuning values. ```gdscript extends CharacterBody2D enum Mode { PATROL, CHASE, RETURN } @export var target: Node2D @export var speed: float = 70.0 var mode: Mode = Mode.PATROL var home: Vector2 var patrol_target: Vector2 func _ready() -> void: home = global_position patrol_target = home + Vector2(80, 0) func _physics_process(delta: float) -> void: if not is_instance_valid(target): velocity = Vector2.ZERO return var distance: float = global_position.distance_to(target.global_position) if mode != Mode.CHASE and distance < 120.0: mode = Mode.CHASE elif mode == Mode.CHASE and distance > 180.0: mode = Mode.RETURN var destination: Vector2 if mode == Mode.CHASE: destination = target.global_position elif mode == Mode.RETURN: destination = home if global_position.distance_to(home) <= maxf(3.0, speed * delta): mode = Mode.PATROL else: destination = patrol_target if global_position.distance_to(patrol_target) <= maxf(3.0, speed * delta): patrol_target = home if patrol_target != home else home + Vector2(80, 0) var offset := destination - global_position velocity = offset.normalized() * minf(speed, offset.length() / maxf(delta, 0.001)) move_and_slide() ```
A deterministic grid with a guaranteed clear route
GDScript (Godot 4, not Scratch, Python, JavaScript or C#). Scaffold C-GRID. Copy starts from this text. The desk does not run it.
Scene and node setup
Attach to Node2D GridLab. This example draws, not physics, so the assignment adds matching wall collision only after validation. Grid is 8 columns by 6 rows at 40 pixels per cell. Row 0 and column 7 are a guaranteed clear route from (0,0) to (7,5). RNG seed is a nonpersonal integer.
extends Node2D
const COLS: int = 8
const ROWS: int = 6
const CELL: int = 40
var cells: Array = []
func _ready() -> void:
var rng := RandomNumberGenerator.new()
rng.seed = 2468
for y in range(ROWS):
var row: Array[int] = []
for x in range(COLS):
var blocked: bool = y != 0 and x != COLS - 1 and rng.randf() < 0.25
row.append(1 if blocked else 0)
cells.append(row)
queue_redraw()
func _draw() -> void:
for y in range(cells.size()):
for x in range(cells[y].size()):
var color := Color.DIM_GRAY if cells[y][x] == 1 else Color.BEIGE
draw_rect(Rect2(x * CELL, y * CELL, CELL - 2, CELL - 2), color)
Checks to run in the editor
- Same seed and version produce same grid.
- All cells on top row and rightmost column are empty.
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 readable patrol/chase/return state machine
GDScript (Godot 4, not Scratch, Python, JavaScript or C#). Scaffold C-GUARD-AI. Copy starts from this text. The desk does not run it.
Scene and node setup
Create CharacterBody2D Guard with visible circle or polygon and matching collider. Layer 4 mask 2 for walls. Attach script and assign target to your Player instance in Inspector. Level is one open rectangle; this is steering, not navigation around walls. Damage remains a separate sensor/manager event. Draw detection radii on a design diagram before tuning values.
extends CharacterBody2D
enum Mode { PATROL, CHASE, RETURN }
@export var target: Node2D
@export var speed: float = 70.0
var mode: Mode = Mode.PATROL
var home: Vector2
var patrol_target: Vector2
func _ready() -> void:
home = global_position
patrol_target = home + Vector2(80, 0)
func _physics_process(delta: float) -> void:
if not is_instance_valid(target):
velocity = Vector2.ZERO
return
var distance: float = global_position.distance_to(target.global_position)
if mode != Mode.CHASE and distance < 120.0:
mode = Mode.CHASE
elif mode == Mode.CHASE and distance > 180.0:
mode = Mode.RETURN
var destination: Vector2
if mode == Mode.CHASE:
destination = target.global_position
elif mode == Mode.RETURN:
destination = home
if global_position.distance_to(home) <= maxf(3.0, speed * delta):
mode = Mode.PATROL
else:
destination = patrol_target
if global_position.distance_to(patrol_target) <= maxf(3.0, speed * delta):
patrol_target = home if patrol_target != home else home + Vector2(80, 0)
var offset := destination - global_position
velocity = offset.normalized() * minf(speed, offset.length() / maxf(delta, 0.001))
move_and_slide()
Checks to run in the editor
- Far player: guard patrols 80 pixels from home.
- Within 120 pixels: chase.
- Beyond 180 pixels: return, then patrol.
- Missing target stops safely rather than throwing an invalid-instance error.
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.
Submit Garden Patrol — evidence task
- 1. Package source and design/test evidence.
- 2. Run one full round and regeneration/reset from the restored artifact.
Deliverable. Garden Patrol source artifact, state diagram, seed matrix and readme.
Acceptance checks
- VGC-L135-T1. Teacher can reproduce a named seed.
- VGC-L135-T2. Guard state changes and route invariants match the submitted diagrams.
Understanding question. Which information is essential to reproduce a procedural gameplay bug?
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. Keep guard patrol in a reserved open lane and the player route guaranteed. Avoid adding maze pathfinding to this project. Start with the first assigned task and re-run its acceptance test before adding the remaining feature.
Optional extra. Add one optional guard route only if the generator can prove its lane remains clear. 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.
