I have programmed a small game engine as well as a physics engine from the ground up in C++ for this tiny GameBoy Replica. It can handle Sprites (Images) for the characters that are animated [source code included], which posed quite the challenge with multidimensional pointer-arrays (it’s a pain!). It runs on a NodeMCU MicroController wired to a custom perfboard. I have yet to come up with a fully-fledged game for it, but I found myself lacking time recently.
How I built it (Stages of development)
EXCERPT 1: GameBoy.ino
First variable / object initialization, followed by the setup() function that sets the chip up for the following game loop.
EXCERPT 2: Engine.cpp [Physics]
The physics engine, more specifically the method that updates the velocities of all characters (according to their acceleration) and their positions (according to velocity), causing them to move on screen. For example if a character jumps, he receives an instantaneous velocity to propel him upward (not 100% like real physics of course!), while a gravity constant decelerates him.
EXCERPT 3: Engine.cpp [Code Problem]
This code excerpt shows the Sprite::getImage() method. The method is called every frame and asks for a current image of the sprite. However, because I wanted to have animated sprites (see: walking animation in the GameBoy Demo) I needed to figure out a way how to accomplish that feat. Due to the character images themselves being an array, the final array to return the frame had to be multidimensional. Now if you also get pointers involved, things start to get really messy, as they tend to do in c++. After countless failed attempts, I managed to get it working with some code that doesn’t look too scary. But let me tell you – all of that pointer-casting and 2D array handling was a huge pain.