Neon Dungeon: Rogue Crawler · Step 2 of 4
Keyboard Controls & Vector Movement
Now that our hero is rendered, let's give the player movement capabilities! In this step, you will capture keydown/keyup events (or key states), update velocity vectors (vx, vy), and update position on each frame (x += vx, y += vy). You will also enforce screen boundary constraints so the player doesn't wander off grid.
What you will learn
- Velocity Vector Physics: Character movement in games uses velocity vectors (vx, vy). Direction keys set velocity, which is then added to position coordinates each frame.
- Keyboard Event Handling: Listen to key presses (Arrow keys / WASD) to mutate velocity vectors smoothly.
Open this interactive lesson · Browse all lessons
In the editor, complete the marked TODOs. Use Stuck on a TODO? to reveal hints or a worked example, then run the lesson checks.