Last active
October 29, 2016 18:57
-
-
Save charles-l/f080be5576d28612c14e1445aabe5c12 to your computer and use it in GitHub Desktop.
End of tutorial 1 for the polished platformer series
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| bump = require 'bump' | |
| local world = bump.newWorld() | |
| local level = {elems = {}} | |
| function level:addElem(x, y, w, h, drawLambda) | |
| local t = {draw = drawLambda} | |
| world:add(t, x, y, w, h) | |
| table.insert(self.elems, t) | |
| return t | |
| end | |
| function level:draw() | |
| for _, v in pairs(self.elems) do | |
| v:draw(world:getRect(v)) -- self, x, y, w, h | |
| end | |
| end | |
| function love.load() | |
| love.graphics.setBackgroundColor(100, 100, 100) | |
| level:addElem(0, 500, 100, 100, | |
| function(self, x, y, w, h) | |
| love.graphics.setColor(255, 255, 0) | |
| love.graphics.rectangle('line', x, y, w, h) | |
| end) | |
| box = level:addElem(0, 10, 20, 20, | |
| function(self, x, y, w, h) | |
| love.graphics.setColor(0, 255, 0) | |
| love.graphics.rectangle('line', x, y, w, h) | |
| end) | |
| box2 = level:addElem(0, -10, 20, 20, | |
| function(self, x, y, w, h) | |
| love.graphics.setColor(0, 255, 0) | |
| love.graphics.rectangle('line', x, y, w, h) | |
| end) | |
| end | |
| function love.draw() | |
| level:draw() | |
| end | |
| function love.update(dt) | |
| local x, y, _, _ = world:getRect(box) | |
| world:move(box, x + 1, y + 10) | |
| world:move(box2, x + 4, y + 10) | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment