Video Game Design and Coding · PLECK lesson

PLECK lesson 13 · suggested week 3, day 3

Map actions rather than hardcoding keys

Objective. Create named input actions with alternate keyboard bindings.

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

An input action describes intent, such as move_left, rather than one physical key. In Project Settings > Input Map, create four movement actions and bind both WASD and arrow keys as shown in C-FREE-MOVE. The script asks Godot for the action, so two input devices can express the same intention. Check exact spelling and case: move_Left and move_left are different names. Use physical key events for movement and keep a visible controls note. Do not replace built-in ui_accept navigation actions.

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

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.

Map actions rather than hardcoding keys — evidence task

  1. 1. Configure all four actions with two bindings each.
  2. 2. Print a short message on a just-pressed movement action and test both bindings.

Deliverable. Input-map project files and a binding table.

Acceptance checks

Understanding question. Why is just_pressed useful for a menu selection but not continuous movement?

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.

Name ____________________ Date ____________________