First Post! Adventures in SDL/C++ learning


First post! 

After the first 72 hours of working on Splonking, I had a working prototype of the game finished: done with spaghetti code, held together with duct-tape, and missing implementation of most enemies/entities that would make it... y'know, fun.  I was trying to make it as a challenge for Ludum Dare, though after the fact because I missed the actual Jam due to finals.

Progress was made after the 72 hour period, and within 2 more days I had implemented a game that was actually fun to play!... built on the ultra-rough terrible code-base patchwork that I had already built. 

After that, I decided to greatly increase the scope of this project: the long-term goal is to not only create a game, but a reusable, versatile game engine/framework.

Anyway, prepare to see some big moves in the project over the coming weeks: I'm a full-time Comp-Sci student, but I've got a month or so off between semesters and need a project to continue to work on my coding chops, so here we go. I'm learning a lot of C++ as I go along, as I only have about 4 months experience in the language.

Since the prototype:

The code-base has been entirely refactored.. but is in the process of being refactored, again. And probably again. I'm developing the engine and implementing things in the engine for the current game, Splonking the Moon, at the same time. This probably isn't completely efficient, but it's very productive: when I'm faced with a question of how to implement something in game, I add/modify functionality in the looser framework/engine. Software bloat may occur with this, so I'm being careful to streamline as much as possible.

The paradigm/game engine model uses inheritance classes for every 'entity' that can be rendered and interact with the player/other entities. Coupled with a few 'handler' classes (an entity handler, an audio handler) and a few special non-entities (a level layout) the idea is to be able to provide a framework for just about any 2D game imaginable with just this framework and SDL. I don't aim to compete with Gamemaker Studio, Unity, Godot, and the like, but to provide a simple, probably open-source option.

My idea is NOT to create a typical library, but to offer modular full-source. For instance, writing a variety of "player" classes with different characteristics for different styles of games (top down shooter, platformer, etc) and having them simply drop into the framework. A "base" of pure source to work with, if you will. Once it's complete (well, the first release version at least) I plan on writing a variety of simple games with the engine, doing tutorials on them, and offering the classes used freely.

c++ learning

My first roadblock was that for speed and simplicity I was doing everything without dynamic memory allocation. This led to a hard-to-diagnose stack-overflow crashing issue, yuck. The entire thing was refactored to rely on dynamic memory allocation working with smart pointers: I had never worked with smart pointers before, only having learned how to manage memory explicitly and use raw pointers. Smart pointers to the rescue! Such an easy/simple solution to many headaches.  A shame we weren't allowed to use them in my last C++ course (gotta learn the hard way, I guess!)

The use of subtype polymorphism and pointer type-casting has made the job of handling a variety of different entities on screen a lot simpler. I'm still learning about how to optimize collision detection: currently it's implemented in a fairly brute-force manner and based solely on calculating simple rectangular hitboxes with the help of SDL. I'm debating between working in hitboxes of other geometry primitives, or touching up the entity base-class a bit and allowing for multiple rectangles forming a single "hit map" to simulate more complex geometry. We'll see what direction i end up taking. Maybe both? Layered rectangular hitboxes to form a map can give a pretty good approximation of arbitrary shape bounding/hitboxes, but my word, calculating reflections with overlaid rectangles sounds like a nightmare. 

This might be a job for SDL_gfx. I've never worked with it before (well, I'm only on a few days of working with SDL anyway!) but perhaps a solution to collision detection with primitives other than rectangles can be had through some clever usage of SDL_gfx. 

I'm currently working on refactoring the code for the engine to be simpler and more modular, as well as continuing to add features to Splonking - including a total now of 4 enemy/obstacle types,  and a fuel-system with fuel pickups. Looking for more powerups and baddies as we go. Assets are placeholders mostly, but I'm starting to get used to them :)

At ~3000 lines of code so far, this is shaping up to the be the biggest C++ project I've ever worked on (I know, it's not that big, but I'm new to the language!) and over the next week look out for a pre-alpha build of Splonking, plus I want to take care of some of the nitty-gritty of making this project "official" (reorganizing the project, getting it on github, working on official documentation, etc)

I also need a name for the engine/framework. I have zero ideas currently. 

Get Splonking

Download NowName your own price

Leave a comment

Log in with itch.io to leave a comment.