Mario Recreation


Mario Project

This was the 2nd prototype game that I had created within C++ and the first time that I had delved into SDL2. This framework is very well documented and the documentation was easy to understand.

I am going to be talking about some of the things that I learnt within this project
Code: https://github.com/deadmonstor/Games-Engine-Creation

Things I learnt:

Static variables within classes to get "global" versions of those objects.

This made it very easy to reference managers even in different languages. For example in my tower defence game that I am making I am able to call out to a static variable to change things within that instance of the class that is only going to be created once. This is the code that was used within Mario.
CPP:
	class* class::mInstance = class::mInstance == nullptr ? NULL : class::mInstance;
	class* class::Instance()
	{
		if (!mInstance)
			mInstance = new class();

		return mInstance;
	}

Header:
	class class
	{
		private:
			static class* mInstance;
	};
						
This allowed me to write code like this. Obviously you will probably want to store this within a variable and not just directly call the Instance function everything you want to do anything.
CPP:
	class::Instance()->function();


Having a pipeline of events makes it so that things have the right data at the right time

What I mean above is that sometimes I was having issue with the camera feeling laggy. This was because the data that was controlling the camera was running after the camera had updated meaning that the camera was always on last frames data.
#define RENDERUPDATE 1
#define PRETICK 2
#define POSTTICK 3
#define PREMAPCHANGE 4
#define POSTMAPCHANGE 5
The order that the default game loop would go through is PRETICK -> RENDERUPDATE -> POSTTICK within the PRETICK and RENDERUPDATE events there was the ones that SDL2 injected which made it so that you could control the camera with your mouse and keyboard. Having this system in place made me understand the reason why UE4 and Unity do this in the first place.



Hopefully this will help someone else one day as I know it has helped me! I have had a blast learning this.