Marble Run

This is an archive of a topic from NESdev BBS, taken in mid-October 2019 before a server upgrade.
View original topic
Marble Run
by on (#220546)
Hello!

Marble Run is an NES game that I've been working on for some time and I think it is about done. I have tested this only on the FCEUX emulator, so there may be some bugs...

The idea is to collect all items and go to the exit as fast as possible. The game features 5 levels and some pretty smooth physics. Achieving a 3-star grade requires some non-obvious maneuvering, so each level has a "View Demo" feature that shows an example of how to achieve it for that level.

The NTSC ROM image and some screenshots are included as attachments.
Re: Marble Run
by on (#220549)
Looks fun. :D
Re: Marble Run
by on (#220565)
That's cool. Thanks for sharing!
Re: Marble Run
by on (#220567)
Pretty fun little game, nice job. And it does indeed work just fine on console with Everdrive.
Re: Marble Run
by on (#220568)
Once i saw it i knew i'd like it. It's super hard for me (i haven't beaten a single stage after 30 minutes) but it's still fun.
Re: Marble Run
by on (#220570)
That's interesting! How did you do the physics?
Re: Marble Run
by on (#220581)
pubby wrote:
That's interesting! How did you do the physics?

The first thing that might be worth mentioning is that it uses a CORDIC algorithm for vector magnitude calculation and normalization. CORDIC is an old algorithm that is very versatile, but I hadn't even heard of it before I started working on this project.

Here is a nice description of the idea behind CORDIC: https://www.uio.no/studier/emner/matnat ... cordic.pdf

Another thing might be the broad phase collision detection. Since the ball radius is constant, it has been included in the object AABBs. The object AABBs are sorted by their minimum x-coordinates in ascending order, which allows the broad phase to quickly figure out the last AABB to check. There is also an index list that allows the broad phase to quickly figure out the first AABB to check.

I included an NTSC ROM image for a test program that shows the broad phase in action.

In the test program:
- AABB corners are dark green, if the AABB is not checked in the broad phase
- AABB corners are light green, if the AABB is checked and rejected in the broad phase
- AABB corners are orange, if the AABB requires a narrow phase check

The rest is just calculating contact points and contact plane normals, pushing the ball out of the static objects and applying impulses.