Dimwitted Sage

This site is being rebuilt. Some pages and posts are still in progress.

Physics Post-Mortem

November 21, 2025
Part 6 of 6 in Building an NES Game

The last post concluded with the promise of physics and animation in the near future. In truth I’d probably already begun playing with the physics at the time of the post, but as does happen, life got busy with some other personal responsibility and pure passion projects weren’t something I could pursue. At the time and even still, I wanted to play and explore with the physics implementation, not copy some implementation or have it generated from AI, so its evolution was going to be messy. I’ll perform search references as I run into problems.

The Model

Everything that moves is a phys_obj: a position and a velocity, each expressed as an 8.8 fixed point float because the NES has no floating point operations.

union fixed_point {
	struct {
		char subpixels;
		char pixels;
	} parts;
	int16_t point;
};

struct phys_obj
{
	union fixed_point x;
	union fixed_point y;
	union fixed_point x_vel;
	union fixed_point y_vel;
};

...

#define FAST_FALL 80

void updatePhysicsObject(void* obj) {
	struct phys_obj* phys = (struct phys_obj*)obj;

	char state = pad_state(0);
	char velocity_x = state & PAD_LEFT ? -1 : state & PAD_RIGHT ? 1 : 0;

    // Update velocity
	if(state & PAD_A) {
        phys->y_vel.parts.subpixels = 0;
		phys->y_vel.parts.pixels = -2;
	} else {
		phys->y_vel.point += FAST_FALL;      // <-- gravity: +80/256 px/frame²
		if(checkGndCollision()) {
			phys->y_vel.point = 0;
		}
	}

    // Update position
    phys->y.point += phys->y_vel.point;     // <-- velocity applied to position
	...

The union (6502 is little-endian) allows for the compiler to trivially separate subpixels to ignore while the point value allows direct manipulation of the position from subpixel velocity values. For this initial implementation, I just used fixed velocity for character left/right/jump movements and applied some downward acceleration for gravity. At this time, I hadn’t implemented anything for predictive boundary collision, as a result, it’s possible for my character to fall completely and partially through platforms because the state advancement skips platform tile positions.

I didn’t get as far with the graphics as I’d hoped to. I was able to add a very poor walk animation and reverse the render of my tiles to handle left and right movements, but I don’t think it’s worth sharing any kind of approach. My dream was and still is to write something that pushes the system to its limits based on progression of game development knowledge. To that end, I fully expected to wander about in my game development to pick up additional skills in ML (e.g., image generation) and compilers (mos-llvm / clang maintenance).

Next

I don’t want to end this series incomplete, but there are definitely other related technologies to explore. I started another series, Taking NES Games Apart, to begin digging into other game implementation details.