bomber imp
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
MovableCrosshair = {}
|
||||
class('MovableCrosshair').extends(NobleSprite)
|
||||
class('MovableCrosshair').extends(playdate.graphics.sprite)
|
||||
|
||||
function MovableCrosshair:init()
|
||||
MovableCrosshair.super.init(self)
|
||||
@@ -14,40 +14,53 @@ function MovableCrosshair:init()
|
||||
self.moveRadius = 2
|
||||
self.moveSpeed = 2
|
||||
self.time = 0
|
||||
|
||||
-- Calculate size based on crosshair dimensions
|
||||
local totalSize = (self.lineLength + self.gapSize) * 2 + 10
|
||||
self:setSize(totalSize, totalSize)
|
||||
|
||||
-- Set the drawing offset to middle of sprite
|
||||
self.drawOffsetX = totalSize / 2
|
||||
self.drawOffsetY = totalSize / 2
|
||||
|
||||
self:add(self.baseX, self.baseY)
|
||||
self:setCenter(0.5, 0.5)
|
||||
self:markDirty()
|
||||
end
|
||||
|
||||
function MovableCrosshair:update()
|
||||
-- Update time
|
||||
MovableCrosshair.super.update(self)
|
||||
self.time = self.time + playdate.display.getRefreshRate() / 1000
|
||||
|
||||
-- Calculate new position with slight movement
|
||||
|
||||
local offsetX = math.sin(self.time) * self.moveRadius
|
||||
local offsetY = math.cos(self.time * 1.3) * self.moveRadius
|
||||
|
||||
self:moveTo(self.baseX + offsetX, self.baseY + offsetY)
|
||||
|
||||
self:draw()
|
||||
self:markDirty()
|
||||
end
|
||||
|
||||
function MovableCrosshair:draw()
|
||||
-- Draw horizontal lines
|
||||
local centerX = self.drawOffsetX
|
||||
local centerY = self.drawOffsetY
|
||||
|
||||
playdate.graphics.drawLine(
|
||||
self.x - self.lineLength - self.gapSize, self.y,
|
||||
self.x - self.gapSize, self.y
|
||||
)
|
||||
playdate.graphics.drawLine(
|
||||
self.x + self.gapSize, self.y,
|
||||
self.x + self.lineLength + self.gapSize, self.y
|
||||
centerX - self.lineLength - self.gapSize, centerY,
|
||||
centerX - self.gapSize, centerY
|
||||
)
|
||||
|
||||
-- Draw vertical lines
|
||||
playdate.graphics.drawLine(
|
||||
self.x, self.y - self.lineLength - self.gapSize,
|
||||
self.x, self.y - self.gapSize
|
||||
centerX + self.gapSize, centerY,
|
||||
centerX + self.lineLength + self.gapSize, centerY
|
||||
)
|
||||
|
||||
playdate.graphics.drawLine(
|
||||
self.x, self.y + self.gapSize,
|
||||
self.x, self.y + self.lineLength + self.gapSize
|
||||
centerX, centerY - self.lineLength - self.gapSize,
|
||||
centerX, centerY - self.gapSize
|
||||
)
|
||||
|
||||
playdate.graphics.drawLine(
|
||||
centerX, centerY + self.gapSize,
|
||||
centerX, centerY + self.lineLength + self.gapSize
|
||||
)
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user