liveBook · Manning

Velocity

As explained in Classic Game Programming on the NES: Make your own retro video game

Velocity is a signed positional change applied along a spatial axis to determine an object's movement.

Velocity is a value added to an object's position each game-loop iteration. Separate X and Y velocity values move the ball horizontally and vertically. section 5.15

Set the ball's initial velocity to 1 on both axes, then reverse an axis when the ball reaches a screen boundary. A value of $FF supplies the opposite direction in the example. section 5.15

Bouncing ball

The game loop adds d_y to the ball's Y coordinate and d_x to its X coordinate. Reaching the top or left edge changes the relevant value to 1; reaching the bottom or right edge changes it to $FF.

How Classic Game Programming on the NES: Make your own retro video game covers it

How deep it goes
Explains initialization, per-loop position updates, and edge-triggered direction changes in assembly.
Examples
Uses a ball sprite initialized with unit X and Y velocities and reversed at the visible screen edges.
What you can do after
Build it from scratch by storing velocity values, adding them to sprite coordinates, and reversing them at boundaries.
How it connects
Connects velocity with sprite coordinates, the game loop, screen boundaries, and collision response.

Also explained in

Compare how 4 books explain velocity →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Classic Game Programming on the NES: Make your own retro video game. The section links point to the parts of the book it draws on.