Custom made Entity Component System for Playdate


This is a screenshot of how the ECS system is built for the game Elf Factory, and it is a copy of what I did in Jewel Defender (though I cleaned up the code a bit from what I learned there)

The game is made up of scenes, and each scene has a function that is run to set it up when you switch to that scene.

Also that scene has an update function that runs for each frame of the game. Finally there is a draw call that happens, and this is done after playdates gfx.sprite.update() and is used to draw any extra things on top of the scene such as scoreboards and such.

A scene is also made up of objects, which usually have sprites, but also have ids (which match their keys), and their own update functions that are run after the scene's update function.

The Updater (which is really the only thing playdate.update() runs... I am trying to abstract playdate away as much as possible) handles making all these calls:

There are also DrawDelayed (images and text) which is used by object or scene updates if they want to throw some stuff up on the screen such as notifications to the user or ammo counts or other HUD things as that stuff is best done after all the sprites are done being painted.

CurrentScene is the global pointer to whatever scene is currently active. There is a function called ChangeScene(newScene) which will shut down and clean up the CurrentScene, point CurrentScene to newScene and then run it's setup.

For files, I have ctrl.lua, which has all the generic functions to control the game, main.lua where things are defined (such as Scenes and other global variables), and then a file for each of the scenes, in this case just gameScreen.lua, which contains all the functions that apply to objects in that scene.

Get Elf Factory

Buy Now$8.00 USD or more

Leave a comment

Log in with itch.io to leave a comment.