About
Small game is built on a custom engine on SFML. Developed during a university elective.
Context
Type: Elective Project
Time: 1 Month (Jan 2024 - Feb 2024)
Build with: SFML and CMake


Introduction
While working on Won't Die Together 2, I also took a game engine class to learn how they work and what's involved in making one. It was a great course that lasted a few months. To build a basic 2d engine, we used SFML and CMake.
Custom Engine
During the elective, we added new features to the engine, following our lecturer's steps and using the project files he provided after every session. We began by implementing an Entity Component System (ECS), exploring the fundamental differences between Object-Oriented Programming (OOP) and Data-Oriented Programming (DOP) in engine design. In the process, we learned how entities and systems manage game objects and explored the advantages and disadvantages of both approaches. Then, we implemented a sprite component to add and customize visuals. Around it, we built other components and their definitions.
Then, we constructed core engine components, including a game loop, input manager, asset registry, and factory pattern, while also gaining practical experience with basic multithreading concepts. A level system was introduced to manage game object loading and initialization. We also covered essential topics like memory management and JSON data handling. The final project challenged us to develop a small game using our engine and add more features to it.
> Code - Engine Folder
Small Game
To ensure engine reusability, we separated the engine and the game code. Input, collisions, and entity basics were part of the engine, while enemies, player, and state manager were part of the game. Our lecturer gave us a game example, which we used as a reference so we knew what this custom engine was capable of.
My idea was to make a small game about killing monsters and collecting potions that power up the player. As a feature, I tried to make the game read WAV music files and change the game based on it. For example, the background color or enemy spawn rate could change with the music. However, initially, I couldn’t figure out how to get useful data from the music files.
I tried to get data from the WAV track using music samples. I loaded the WAV data into an int16 array, attempting to normalize the values to a 0-1 range and subsequently scale them to 0-255 for colors. Didn’t work out. Then, I tried to calculate the correct sample index by multiplying the track's playback time by its sample rate and channel count. Normalizing the left and right channels was slightly better, but still, it looked like random data.
But then I got what the problem was. Music tracks were just too complex to use for gameplay. Beat or instrument separation from the track could work, but it would require separating music myself or analyzing its rate and creating a cycle based on it. Since I was short on time, I saved music functions but moved on to finishing the game.
> Code - Game Folder

Conclusion
This project was a highly productive learning experience, deepening my understanding of game engine construction and leading to the creation of a small game on it. While the music feature did not work out as intended, it served as a basis for my further tests, which helped me develop a music system for Muramasa Burden.
My takeaways
- Gained knowledge of game engine architecture and development using SFML.
- Learned about audio functionality in C++, sparking a keen interest in the field.
- Learned new ways to connect music to gameplay.