bomber imp
This commit is contained in:
28
source/scripts/bomber/boom.lua
Normal file
28
source/scripts/bomber/boom.lua
Normal file
@@ -0,0 +1,28 @@
|
||||
SmallBoom = {}
|
||||
class("SmallBoom").extends(AnimatedSprite)
|
||||
|
||||
local smallBoomImageTable = Graphics.imagetable.new("assets/sprites/smallboom")
|
||||
|
||||
function SmallBoom:init()
|
||||
SmallBoom.super.init(self, smallBoomImageTable)
|
||||
|
||||
-- Animation properties
|
||||
self:addState("play", 1, 3, { tickStep = 1, loop = 2 })
|
||||
self:setDefaultState("play")
|
||||
self:playAnimation()
|
||||
self:setCenter(0, 0)
|
||||
self:setSize(playdate.display.getSize())
|
||||
self:setZIndex(ZIndex.flash)
|
||||
|
||||
self:moveTo(0, 0)
|
||||
|
||||
self:add()
|
||||
end
|
||||
|
||||
function SmallBoom:update()
|
||||
self:updateAnimation()
|
||||
end
|
||||
|
||||
function SmallBoom:stopAnimation()
|
||||
self:remove()
|
||||
end
|
20
source/scripts/bomber/explosionMark.lua
Normal file
20
source/scripts/bomber/explosionMark.lua
Normal file
@@ -0,0 +1,20 @@
|
||||
ExplosionMark = {}
|
||||
class('ExplosionMark').extends(NobleSprite)
|
||||
|
||||
function ExplosionMark:init(x, y)
|
||||
ExplosionMark.super.init(self)
|
||||
self.id = math.random(1, 2)
|
||||
self.markImage = Graphics.image.new("assets/sprites/boomSplash" .. self.id) -- TODO: make it random
|
||||
self:setImage(self.markImage)
|
||||
self:moveTo(x, y)
|
||||
self:setZIndex(5)
|
||||
self:add(x, y)
|
||||
end
|
||||
|
||||
function ExplosionMark:update()
|
||||
self:moveBy(0, BomberScene.instance.scrollSpeed)
|
||||
|
||||
if self.y > 240 + 32 then
|
||||
self:remove()
|
||||
end
|
||||
end
|
@@ -1,34 +1,91 @@
|
||||
Granade = {}
|
||||
class('Granade').extends(NobleSprite)
|
||||
|
||||
local function screenShake(shakeTime, shakeMagnitude)
|
||||
local shakeTimer = playdate.timer.new(shakeTime, shakeMagnitude, 0)
|
||||
shakeTimer.updateCallback = function(timer)
|
||||
local magnitude = math.floor(timer.value)
|
||||
local shakeX = math.random(-magnitude, magnitude)
|
||||
local shakeY = math.random(-magnitude, magnitude)
|
||||
playdate.display.setOffset(shakeX, shakeY)
|
||||
end
|
||||
shakeTimer.timerEndedCallback = function()
|
||||
playdate.display.setOffset(0, 0)
|
||||
end
|
||||
end
|
||||
|
||||
function Granade:init(x, y)
|
||||
Granade.super.init(self)
|
||||
|
||||
self.initialRadius = 10
|
||||
self.currentRadius = self.initialRadius
|
||||
self.shrinkRate = 0.2
|
||||
|
||||
random = math.random(1, 4)
|
||||
self.boomSound = playdate.sound.fileplayer.new("assets/audio/boom" .. random)
|
||||
self.boomSound:setVolume(0.5)
|
||||
|
||||
self.isActive = true
|
||||
-- Variables for random movement
|
||||
self.randomMovementTimer = 0
|
||||
self.randomXVelocity = 0
|
||||
self.randomYVelocity = 0
|
||||
|
||||
local size = self.initialRadius * 2
|
||||
self.spriteSize = size
|
||||
self:setSize(size, size)
|
||||
self:moveTo(x, y)
|
||||
|
||||
self:setCenter(0.5, 0.5)
|
||||
|
||||
print("Granade init")
|
||||
print(self.x, self.y)
|
||||
self:add(x, y)
|
||||
self:markDirty()
|
||||
end
|
||||
|
||||
function Granade:update()
|
||||
if self.isActive then
|
||||
if BomberScene.instance then
|
||||
self:moveBy(0, BomberScene.instance.scrollSpeed - 0.2)
|
||||
|
||||
self.randomMovementTimer = self.randomMovementTimer + 1
|
||||
|
||||
if self.randomMovementTimer >= 10 then
|
||||
self.randomMovementTimer = 0
|
||||
self.randomXVelocity = math.random(-50, 50) / 100
|
||||
self.randomYVelocity = math.random(-5, 10) / 100
|
||||
end
|
||||
|
||||
self:moveBy(self.randomXVelocity, self.randomYVelocity)
|
||||
end
|
||||
|
||||
self.currentRadius = self.currentRadius - self.shrinkRate
|
||||
|
||||
if self.currentRadius <= 0 then
|
||||
print("Granade deactivated")
|
||||
self.isActive = false
|
||||
local particleB = ParticlePoly(self.x, self.y)
|
||||
particleB:setThickness(1)
|
||||
particleB:setAngular(-5, 5122)
|
||||
particleB:setSize(1, 2)
|
||||
particleB:setSpeed(1, 20)
|
||||
particleB:setMode(Particles.modes.STAY)
|
||||
particleB:setBounds(0, 0, 400, 240)
|
||||
particleB:setColour(Graphics.kColorXOR)
|
||||
particleB:add(20)
|
||||
self.boomSound:play(1)
|
||||
screenShake(1000, 5)
|
||||
SmallBoom()
|
||||
ExplosionMark(self.x, self.y)
|
||||
|
||||
self:remove()
|
||||
end
|
||||
end
|
||||
self:draw()
|
||||
self:markDirty()
|
||||
end
|
||||
|
||||
function Granade:draw()
|
||||
playdate.graphics.fillCircleAtPoint(self.x, self.y, self.currentRadius)
|
||||
local centerX = self.spriteSize / 2
|
||||
local centerY = self.spriteSize / 2
|
||||
playdate.graphics.fillCircleAtPoint(centerX, centerY, self.currentRadius)
|
||||
end
|
@@ -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