Difference between revisions of "Lovetoys"

Line 63: Line 63:
 
Grab it or give it a look on [https://github.com/Lovetoys/lovetoys Github].
 
Grab it or give it a look on [https://github.com/Lovetoys/lovetoys Github].
  
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/Lovetoys/Lovetoys-example Example-project] or our [https://github.com/Lovetoys/Lovetoys-games Games].
+
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/Lovetoys/Lovetoys-examples Example-project] or our [https://github.com/Lovetoys/Lovetoys-games Games].
  
  
 
[[Category:Libraries]]
 
[[Category:Libraries]]

Revision as of 12:26, 2 September 2014



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!
The Software is published under MIT License. Feel free to use it in your projects.

A simple example for implementation:

require(lovetoys/engine)

function love.load()

    -- Creation of a new world
    love.physics.setMeter(64)
    world = love.physics.newWorld(0, 9.81*80, true)
    -- Enabling the collision functions
    world:setCallbacks(beginContact, endContact)

    love.window.setMode(1000, 600, {fullscreen=false, vsync=true, resizable=false})

    -- 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})

    -- Logic (update) systems are beeing added to the engine
    engine:addSystem(ExampleSystem(), "logic", 1)

    -- Drawing systems are beeing added to the engine
    engine:addSystem(ExampleDrawSystem(), "draw", 1)
end


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

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

-- Love2d Collision function, creation of an event and piping it to the eventmanager
function beginContact(a, b, coll)
    -- Dynamic creation of a new instance of BeginContact and firing it to the Eventmanager
    eventmanager:fireEvent(BeginContact(a, b, coll))
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 Games.