Advertisement
Guest User

Untitled

a guest
Jun 9th, 2016
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.64 KB | None | 0 0
  1. require "libraries.luvnit"
  2.  
  3. --[[ Shape class; color, x, y]]
  4. local Shape = Class()
  5. function Shape:init(info)
  6.    self:setX(info.x or 0)
  7.    self:setY(info.y or 0)
  8.    self:setColor(info.color or {255, 255, 255})
  9. end
  10. Shape:newProperty("Color", {255, 255, 255})
  11. Shape:newProperty("X", 0)
  12. Shape:newProperty("Y", 0)
  13.  
  14. --[[ Circle class; color, x, y, radius]]
  15. local Circle = Class(Shape)
  16. function Circle:init(info)
  17.    self:setRadius(info.radius or 0)
  18.    self:registerEvent("draw", function()
  19.       love.graphics.setColor(self:getColor())
  20.       love.graphics.circle("fill", self:getX(), self:getY(), self:getRadius())
  21.    end)
  22. end
  23. Circle:newProperty("Radius", 0)
  24.  
  25. --[[ Rectangle class; color, x, y, width, height]]
  26. local Rectangle = Class(Shape)
  27. function Rectangle:init(info)
  28.    self:setWidth(info.width or 0)
  29.    self:setHeight(info.height or 0)
  30.    self:registerEvent("draw", function()
  31.       love.graphics.setColor(self:getColor())
  32.       love.graphics.rectangle("fill", self:getX(), self:getY(), self:getWidth(), self:getHeight())
  33.    end)
  34. end
  35. Rectangle:newProperty("Width", 0)
  36. Rectangle:newProperty("Height", 0)
  37.  
  38. --[[ Spawn a circle every second, tween it to a different position, and plop it in 'list' ]]
  39. local list = {}
  40. Timer(function()
  41.    local obj = Circle({
  42.       x = love.math.random(0, 100),
  43.       y = love.math.random(0, 100),
  44.       radius = love.math.random(10, 20),
  45.    })
  46.    Tween.to(obj, 1, {_X = obj:getX() + 100, _Y = obj:getY() + 100})
  47.    table.insert(list, obj)
  48.    return 1
  49. end)
  50.  
  51. --[[ Draw all the objects ]]
  52. Event:register("_draw", function()
  53.    for _, obj in ipairs(list) do
  54.       obj:emitEvent("draw")
  55.    end
  56. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement