Mono Golf
Introduction
Mono golf is a 2D mini-golf game I developed independently in MonoGame for an assignment. All scripts were written in C# with Visual Studio. Apart from base MonoGame functionality, I was responsible for designing and implementing all other systems including physics, collisions, and animation. This was my first time working in a game framework instead of an engine, so I learned a lot while developing this game.
What I Learned
Per-Pixel Collision Detection
I developed a per-pixel collision system to ensure collisions between the golf ball and obstacles were semi-realistic when hitting edges, corners, or angled walls. MonoGame has built-in functionality for rectangular collisions already, so I used that as my primary collision detection. If a collision occurs between two rectangles, we check each pixel inside the overlapping area to see if both sprites have a non-transparent color. After all overlapping pixels have been checked, we average the positions of the colliding pixels to get a central point for the collision. Next we compute the normal vector by getting the vector from the collision center to the ball’s center, then reflect the ball’s velocity across that normal.
Golf ball Animation
I wanted the golf ball to have a rolling animation, but I needed it to “roll” in the direction the ball is moving while maintaining visual continuity. To achieve this, I made a pixel art sprite sheet in Aseprite that covers every possible divot placement. The sprites were organized in a rectangle so that every sprite is one pixel position off from its neighbors. This allows me to track the distance traveled on both axes and once the ball covers enough distance to constitute a roll, swap the current sprite with its neighboring sprite corresponding to the velocity direction.