Difference between revisions of "Lovetoys"
Line 11: | Line 11: | ||
<source lang="lua"> | <source lang="lua"> | ||
− | require(lovetoys/engine) | + | -- Importing lovetoys |
+ | require("lovetoys/engine") | ||
function love.load() | function love.load() | ||
− | + | engine = Engine() | |
− | |||
− | |||
world = love.physics.newWorld(0, 9.81*80, true) | world = love.physics.newWorld(0, 9.81*80, true) | ||
− | |||
world:setCallbacks(beginContact, endContact) | world:setCallbacks(beginContact, endContact) | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
eventmanager = EventManager() | eventmanager = EventManager() | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
end | end | ||
− | |||
function love.update(dt) | function love.update(dt) | ||
-- Engine update function | -- Engine update function | ||
engine:update(dt) | engine:update(dt) | ||
+ | world:update(dt) | ||
end | end | ||
Line 50: | Line 30: | ||
-- Engine draw function | -- Engine draw function | ||
engine:draw() | engine:draw() | ||
+ | end | ||
+ | |||
+ | function love.keypressed(key, isrepeat) | ||
+ | eventmanager:fireEvent(KeyPressed(key, isrepeat)) | ||
end | end | ||
− | + | function love.mousepressed(x, y, button) | |
− | + | eventmanager:fireEvent(MousePressed(x, y, button)) | |
− | |||
− | eventmanager:fireEvent( | ||
end | end | ||
Revision as of 12:47, 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:
-- Importing lovetoys
require("lovetoys/engine")
function love.load()
engine = Engine()
world = love.physics.newWorld(0, 9.81*80, true)
world:setCallbacks(beginContact, endContact)
eventmanager = EventManager()
end
function love.update(dt)
-- Engine update function
engine:update(dt)
world:update(dt)
end
function love.draw()
-- Engine draw function
engine:draw()
end
function love.keypressed(key, isrepeat)
eventmanager:fireEvent(KeyPressed(key, isrepeat))
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 Games.