33 lines
784 B
Lua
33 lines
784 B
Lua
-- A pixie is like a sprite, but better
|
|
-- built-in collider, support for setting position at creation
|
|
-- ideal for subclassing sprites that don't need a custom
|
|
-- draw function
|
|
|
|
import "CoreLibs/object"
|
|
import "CoreLibs/graphics"
|
|
import "CoreLibs/sprites"
|
|
|
|
import "constants"
|
|
|
|
local gfx <const> = playdate.graphics
|
|
|
|
class("Pixie").extends(gfx.sprite)
|
|
|
|
-- automatically initialize pixie with a simple rectangle.
|
|
-- great for simple games or for debugging
|
|
function Pixie.new(width, height, color, x, y)
|
|
local img = gfx.image.new(width, height, color)
|
|
local pixie = Pixie(img, x, y)
|
|
return pixie
|
|
end
|
|
|
|
function Pixie:init(img, x, y)
|
|
x = x or 0
|
|
y = y or 0
|
|
|
|
Pixie.super.init(self, img)
|
|
self:setCollideRect(0, 0, self:getSize())
|
|
self:moveTo(x, y)
|
|
return self
|
|
end
|