Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require "libraries.luvnit"
- --[[ Shape class; color, x, y]]
- local Shape = Class()
- function Shape:init(info)
- self:setX(info.x or 0)
- self:setY(info.y or 0)
- self:setColor(info.color or {255, 255, 255})
- end
- Shape:newProperty("Color", {255, 255, 255})
- Shape:newProperty("X", 0)
- Shape:newProperty("Y", 0)
- --[[ Circle class; color, x, y, radius]]
- local Circle = Class(Shape)
- function Circle:init(info)
- self:setRadius(info.radius or 0)
- self:registerEvent("draw", function()
- love.graphics.setColor(self:getColor())
- love.graphics.circle("fill", self:getX(), self:getY(), self:getRadius())
- end)
- end
- Circle:newProperty("Radius", 0)
- --[[ Rectangle class; color, x, y, width, height]]
- local Rectangle = Class(Shape)
- function Rectangle:init(info)
- self:setWidth(info.width or 0)
- self:setHeight(info.height or 0)
- self:registerEvent("draw", function()
- love.graphics.setColor(self:getColor())
- love.graphics.rectangle("fill", self:getX(), self:getY(), self:getWidth(), self:getHeight())
- end)
- end
- Rectangle:newProperty("Width", 0)
- Rectangle:newProperty("Height", 0)
- --[[ Spawn a circle every second, tween it to a different position, and plop it in 'list' ]]
- local list = {}
- Timer(function()
- local obj = Circle({
- x = love.math.random(0, 100),
- y = love.math.random(0, 100),
- radius = love.math.random(10, 20),
- })
- Tween.to(obj, 1, {_X = obj:getX() + 100, _Y = obj:getY() + 100})
- table.insert(list, obj)
- return 1
- end)
- --[[ Draw all the objects ]]
- Event:register("_draw", function()
- for _, obj in ipairs(list) do
- obj:emitEvent("draw")
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement