Difference between revisions of "Lovetoys"

Line 47: Line 47:
  
 
If you want to see a proper way of implementation or some nice examples for events and collisions, have a look at our [https://github.com/Nukesor/lua-lovetoys/tree/master/example Example-project] or our [https://github.com/raffomania/MAVE Game].
 
If you want to see a proper way of implementation or some nice examples for events and collisions, have a look at our [https://github.com/Nukesor/lua-lovetoys/tree/master/example Example-project] or our [https://github.com/raffomania/MAVE Game].
 +
 +
 +
[[Category:Libraries]]

Revision as of 08:52, 28 November 2013



Lovetoys is a small bundle of helper classes and libraries consisting of 3 packages.
The most important one is the Entity Component System which is based on Richard Lords Introduction to ECS's.
If you don't have any idea what this entity component stuff is all about, click that link and give it a read! It's totally worth it!

A basic structure of a main loop:

require(lovetoys/engine)
-- A new instance of an engine is beeing created
engine = Engine()
    -- A new instance of an eventmanager is beeing created
    eventmanager = EventManager()

    -- A new instance of a collisionmanager is beeing created
    collisionmanager = CollisionManager()

    -- The collisionmanager is beeing registered as a listener for the 
    -- "BeginContact" event.
    eventmanager:addListener("BeginContact", {collisionmanager, collisionmanager.fireEvent})

function love.update(dt)
    -- Engine update function
    engine:update(dt)
end

function love.draw()
    -- Engine draw function
    engine:draw()
end 

function love:keypressed(key, u)
    eventmanager:fireEvent(KeyPressed(key, u))
end

function love:mousepressed(x, y, button)
    eventmanager:fireEvent(MousePressed(x, y, button))
end



Grab it or give it a look on Github.

If you want to see a proper way of implementation or some nice examples for events and collisions, have a look at our Example-project or our Game.