Hello everybody
I'm relativly new here and in programming expecially with LUA. I'm trying to implement the Pac-Man effect, very easy, but, even if I think everything is good, nothing happen. I think that there is some confusion between "self.x" and "aereoSpirte.x".
Here the main:
import "coreLibs/graphics"
import "coreLibs/sprites"
import "coreLibs/timer"
import "coreLibs/object"
import "coreLibs/easing"
import "coreLibs/crank"
import "aereo"
local pd <const> = playdate
local gfx <const> = pd.graphics
Aereo(200, 120)
local giocoVa = true
function pd.update()
if giocoVa == true then
gfx.sprite.update()
pd.timer.updateTimers()
end
end
and here the object Aereo:
local pd <const> = playdate
local gfx <const> = pd.graphics
class('Aereo').extends(gfx.sprite)
function Aereo:init(x, y)
local aereoImage = gfx.image.new("images/aereo")
aereoSprite = gfx.sprite.new(aereoImage)
self:setImage(aereoImage)
self:moveTo(x, y)
self:add()
self.speed = 2
end
function Aereo:update()
local crankAngle = pd.getCrankPosition()
self:moveBy(math.sin(math.rad(crankAngle)) * self.speed, 0)
self:moveBy(0, -math.cos(math.rad(crankAngle)) * self.speed)
self:setRotation(crankAngle)
self:pacman()
end
function Aereo:pacman()
if self.x > 400 then
self.x = 0
elseif self.x < 0 then
self.x = 400
end
end
There are no errors, I just think there is no "memorization" of the coordinates.
Sorry for my bad English.