Video Game Design and Coding

PLECK lesson 15 · suggested week 3, day 5

Keep movement inside a usable playfield

Objective. Test boundaries and explain a first interactive prototype.

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.

A visible actor, reusable scenes and measured movement

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

Boundary handling is part of the rules, not a cosmetic afterthought. The actor’s radius is fourteen pixels, so its center must stay at least fourteen pixels from the viewport edge. Clamping the center to zero still clips half the circle. Test all four edges and diagonal corners. Save a named checkpoint and restore it into a new practice folder to verify that project.godot, scene and script are present. Explain one code line in your own words rather than reading the entire script aloud.

Worked example

A circle drawn at Vector2.ZERO belongs to its Node2D origin. If its parent is at (100,80) and its local position is (20,10), its world origin is (120,90) when neither parent is rotated or scaled. Scaffold C-FREE-MOVE — Frame-independent movement without collisions Setup: Use Node2D root Actor, attach this script in place of C-DRAW. Project Settings > Input Map: add move_left, move_right, move_up, move_down. Bind A/Left, D/Right, W/Up, S/Down respectively using physical key events. Project Settings > Display > Window: viewport width 640 height 360. Local Actor has no transformed parent. This version moves but cannot collide with walls. ```gdscript extends Node2D @export var speed: float = 160.0 func _draw() -> void: draw_circle(Vector2.ZERO, 14.0, Color.CORNFLOWER_BLUE) draw_line(Vector2(-8, 0), Vector2(8, 0), Color.WHITE, 3.0) func _process(delta: float) -> void: var direction := Input.get_vector("move_left", "move_right", "move_up", "move_down") position += direction * speed * delta position.x = clampf(position.x, 14.0, 626.0) position.y = clampf(position.y, 14.0, 346.0) ```

Frame-independent movement without collisions

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

Scene and node setup

Use Node2D root Actor, attach this script in place of C-DRAW. Project Settings > Input Map: add move_left, move_right, move_up, move_down. Bind A/Left, D/Right, W/Up, S/Down respectively using physical key events. Project Settings > Display > Window: viewport width 640 height 360. Local Actor has no transformed parent. This version moves but cannot collide with walls.

extends Node2D
@export var speed: float = 160.0
func _draw() -> void:
    draw_circle(Vector2.ZERO, 14.0, Color.CORNFLOWER_BLUE)
    draw_line(Vector2(-8, 0), Vector2(8, 0), Color.WHITE, 3.0)
func _process(delta: float) -> void:
    var direction := Input.get_vector("move_left", "move_right", "move_up", "move_down")
    position += direction * speed * delta
    position.x = clampf(position.x, 14.0, 626.0)
    position.y = clampf(position.y, 14.0, 346.0)

Checks to run in the editor

  • Holding right moves about 160 pixels in one second away from boundary.
  • Diagonal direction length never exceeds 1.
  • Actor stays within 640 by 360 viewport.

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.

Keep movement inside a usable playfield — evidence task

  1. 1. Test and document four edges and two corners.
  2. 2. ZIP and restore the project into a new local folder, then run it.

Deliverable. First interactive prototype ZIP, boundary checklist and two-sentence explanation.

Acceptance checks

  • VGC-L015-T1. No part of the actor crosses the 640 by 360 viewport boundary.
  • VGC-L015-T2. Restored project runs with the same input bindings.

Understanding question. For radius 14 and width 640, what is the largest safe center x?

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 a 640 by 360 viewport, one unscaled Node2D and the C-DRAW recipe before adding movement. Start with the first assigned task and re-run its acceptance test before adding the remaining feature.

Optional extra. Add a second independently colored actor without changing the first actor’s script. 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.

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