For the last couple of months I've been toying with the idea of adding object oriented functionality to LÖVE.
I've developed one (still very experimental!) library called PÄSSION (passion in the code). Its main features are:
- There's an Actor class
- Actors can have an associated image and a physical body - both optional
- You can create "types of actors" (subclasses - for example a class called "Bullet") and create instances of them(each individual bullet)
- Actors have an "update(dt)" function (the update function of a bullet would be "advance dt*v, check for hits, if you are out of the limits then destroy yourself")
- Actors with a body have methods of body. So you don't have to do bullet.body:setMassFromShapes() - you can do bullet:setMassFromShapes() instead
- Similarly, passion has world-delegated functions. So you can do passion.world:setGravity(), but also passion:setGravity()
- By callig passion:update(dt) you update the physical word and then call "update" on each actor instance (so no need to have a loop to update the bullets and another one for the enemies, for example)
- Object-orientation is implemented by a lib called MiddleClass. This provides subclassing, instantiation and a very interesting super() facility (on all methods, for calling their parent version) among other things, like crude mixin support.
- There's allways one world, and one ground body, for physical objects. They are created at the same time, by the PÄSSION lib.
I've made the code on this demo a bit longer than the strictly necessary in order to show how inheritance can be used - there's a class Ball, and then 3 subclasses: GreenBall, SmallBall and BigBall. In reality, the Ball class is all that is needed on this example, but I wanted to show inheritance.
I'd love to hear from you any feedback from you guys - any feedback will be greatly appreciated. Opinion away!
For example: one of the things I'm not sure about is how I used love.filesystem.require - should I be using "absolute paths" in all files, or is there a better way of doing it?
Finally, two important disclaimers:
- Updated to love 0.6
- This has evolved enough to be considered a "very early alpha"