Platformer game engine (a proper one, really!)
Posted: Mon Mar 12, 2012 1:00 am
Old screenshots: (1.0.0)
So I've seen a couple of platformer game tutorials for Love2d. Some have used physics for making player jump. Some sucked. Some succeed at both things.
Later someone asked me to make a proper, optimized tutorial for these. So I did.
Attachment contains most of functional part. Things missing are more detailed comments at some places, and step-by-step introduction to it - will be done tomorrow. As for now, you can play existing levels, add your own ones (levels are stored in accessible string format), and do whatever other things you can manage to.
Main concepts:
Game is split into blocks and entities.
Blocks are static object of fixed dimensions, which can hold variables and trigger events. Behaviour of these can be edited directly and dynamically (in example, 'toggle' block toggles its own drawn event between value and nil, appearing and disappearing).
Objects are dynamic entities, which obey their prototype 'meta' object behaviour. They can be placed freely, and controlled more widely than blocks.
Both blocks and objects have 4 base events - create (executed on creation), destroy (executed on destruction), update (executed on love.update), and render (executed on love.render).
Collisions with blocks can be done via level.check function, which takes a 'rectangle' (4 parameters) and a filter function, which determines if block meets conditions of check or not.
Collisions with objects can be done via level.meet function, which will return array of objects of given type that overlap given rectangle. Further conditions for these must be implemented separately.
Implementations of both are available in example.
For the sake of simplicity, objects are presented as a single unsorted array which game iterates through.
Platformer engine itself is kept simple and framerate-independent.
Comments, suggestions, and other things are welcome.
Have a nice day.