XaiJu
Lizardrive
Lizardrive

patreon


SEGA Megadrive game development #3

Sprites structure

Even if C is not an object oriented language, I tried to structure my code in order to get close to this concept.  

By defining a sprite structure in sprites.h, I have the possibility to create enriched sprite objects which share common attributes.


Also, I decided to create a sprite array of 50 as I do not need many elements in my game. It allows me to save memory, which is always a good thing when working on limited hardware.  

I decided to assign hero to Sprites[0] and reserved the next 10 entries to recurring elements (such as faceset or UI elements).

Sprites specific to a level therefore start from Sprites[11].

In some cases I created simple using the type « Sprite* » because I did not need any of the attribute from SpriteStruct. It once again helps me to save RAM.


Main function

As long as the console is turned on, we will keep on looping in our main() function:


currentPhase is an u8 variable used to keep track of game state.

I use it in order to do transition between levels, as well as to know when player is freely moving or having an interaction (this can be a minigame, a dialog, or a cut-scene).

The for loop is used to update each and every sprites’ animation in case they are flagged as visible. We will go back to this function soon.

ZOrder is called only if player is roaming freely, as there is no need to know if the player is in front or below another character’s sprite otherwise.  

We'll see how this works next time.


More Creators