Inspiration
At hackathons I enjoy writing computer graphics experiments using C, and this time I decided to try and write my first game using OpenGL. Once I had a spinning Blåhaj model on the screen I considered a few ways I could turn it into a game and settled on an Agar.io-like game.
What it does
You play as Blåhaj, and eat small Blåhajar (the proper Swedish plural form of Blåhaj) to grow bigger. You have 30 seconds to eat as many as you can to get a high score.
How we built it
I built this program using C, SDL2, OpenGL, and NanoVG.
Challenges we ran into
I prefer to write code from scratch rather than using libraries where I can to better understand how the program works, and at the start of the event I was writing my own vector/matrix maths functions but was struggling to get the perspective projection matrix and lookat matrix working (I think I had the z coordinate flipped, leading to incorrect depth buffering). Hours into the project, I decided to delete hundreds of lines of my maths code and use a library (cglm). This lowered the complexity of the program significantly, and allowed faster development.
Accomplishments that we're proud of
The program simulates the wake left behind by the Blåhajar using the 2-dimensional wave equation. The code for the simulation was ported from a JavaScript p5.js program I once made. I ran into some stability issues with the simulation, where if the wave speed is set too high the heights of the waves diverge to infinity, but you can avoid this by just setting the parameters to appropriate values.
During hackathons I count the number of times my program has a segmentation fault. At HackTheMidlands I had 25, this time I (somehow) had only 4.
What we learned
For this project I learned more OpenGL rendering techniques, such as cubemapping for the skybox, and blending to render transparent water.
What's next for Blåhaj.io
To make this into a real .io game, networked multiplayer could be implemented where players attempt to eat smaller players instead of randomly moving computer-controlled Blåhajar.
I also wanted to implement a more sophisticated algorithm for the movement of the enemies such as the boids algorithm, but I did not have time.
It would be cool to add controller support using the SDL2 gamepad API, maybe even implement gyro controls.

Log in or sign up for Devpost to join the conversation.