This commit is contained in:
2026-02-23 20:52:54 +01:00
parent fae2abf94e
commit 9eb426021e
32 changed files with 268 additions and 78 deletions

View File

@@ -0,0 +1,94 @@
Enemy = {}
class('Enemy').extends(NobleSprite)
function Enemy:init(x,y)
Enemy.super.init(self)
self:moveTo(x, y)
self:setZIndex(4)
self:add(x,y)
self.markImage = Graphics.image.new("assets/sprites/enemy"..math.random(1,2)) -- TODO: make it random
self.deadImage = Graphics.image.new("assets/sprites/enemy1_3")
self.hitSound = playdate.sound.fileplayer.new("assets/audio/hit1")
self:setImage(self.markImage)
self.removed = false
self:setGroups(CollideGroups.enemy)
self:setCollidesWithGroups({
CollideGroups.granade,
CollideGroups.enemy
})
self:setCollideRect(-6, -6, 46, 46)
self:setSize(32, 32)
self.vx = 0
self.vy = 0
self.isDying = false
self.friction = 0.95
end
function Enemy:update()
if not BomberScene.instance then return end
local speed = 0
if self.isDying then
self.vx = self.vx * self.friction
self.vy = self.vy * self.friction
self:moveBy(self.vx, self.vy + BomberScene.instance.scrollSpeed)
if math.abs(self.vx) < 0.1 and math.abs(self.vy) < 0.1 then
self.isDying = false
self.removed = true
end
elseif not self.removed then
speed = math.random(0, 7)/10
self:moveBy(0, BomberScene.instance.scrollSpeed + speed)
else
self:moveBy(0, BomberScene.instance.scrollSpeed)
end
local actualX, actualY, collisions, numberOfCollisions = self:checkCollisions(self.x, self.y)
if numberOfCollisions > 0 then
for i, collision in ipairs(collisions) do
if collision.other:getTag() == 154 and collision.other.currentRadius <= 0.05 and not self.isDying then
print("Collision with granade")
self:setImage(self.deadImage)
self.hitSound:play()
self:applyExplosionForce(collision.other.x, collision.other.y)
end
end
end
if self.y > 240 + 10 then
if not self.removed then
print("Removing enemy")
self:remove()
self:superRemove()
self.removed = true
end
end
end
function Enemy:applyExplosionForce(explosionX, explosionY)
local dx = self.x - explosionX
local dy = self.y - explosionY
local dist = math.sqrt(dx*dx + dy*dy)
if dist == 0 then dist = 0.001 end
dx = dx / dist
dy = dy / dist
local maxForce = 5
local maxRadius = 100
local force = maxForce * (1 - math.min(dist, maxRadius) / maxRadius)
force = math.max(force, 1)
self.vx = dx * force
self.vy = dy * force * 0.5
self.isDying = true
self:setRotation(math.random() * 360)
end

View File

@@ -4,7 +4,7 @@ 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.markImage = Graphics.image.new("assets/sprites/boomSplash" .. self.id)
self:setImage(self.markImage)
self:moveTo(x, y)
self:setZIndex(5)
@@ -12,6 +12,7 @@ function ExplosionMark:init(x, y)
end
function ExplosionMark:update()
if not BomberScene.instance then return end
self:moveBy(0, BomberScene.instance.scrollSpeed)
if self.y > 240 + 32 then

View File

@@ -1,19 +1,6 @@
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)
@@ -21,12 +8,12 @@ function Granade:init(x, y)
self.currentRadius = self.initialRadius
self.shrinkRate = 0.2
random = math.random(1, 4)
local 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
@@ -35,8 +22,15 @@ function Granade:init(x, y)
self.spriteSize = size
self:setSize(size, size)
self:moveTo(x, y)
self:setZIndex(10)
self:setTag(154)
self:setCenter(0.5, 0.5)
self:setGroups(CollideGroups.granade)
self:setCollidesWithGroups({
CollideGroups.enemy
})
self:setCollideRect(0, 0, self:getSize())
print("Granade init")
print(self.x, self.y)
self:add(x, y)

View File

@@ -4,28 +4,25 @@ class('MovableCrosshair').extends(playdate.graphics.sprite)
function MovableCrosshair:init()
MovableCrosshair.super.init(self)
-- Parameters for crosshair
self.lineLength = 10
self.gapSize = 3
-- Parameters for movement
self.baseX = 200
self.baseY = 150
self.moveRadius = 2
self.moveSpeed = 2
self.moveSpeed = 2.3
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()
self:setZIndex(11)
end
function MovableCrosshair:update()
@@ -66,24 +63,24 @@ end
function MovableCrosshair:moveUp()
if self.baseY > 5 then
self.baseY = self.baseY - 1
self.baseY = self.baseY - self.moveSpeed
end
end
function MovableCrosshair:moveDown()
if self.baseY < 235 then
self.baseY = self.baseY + 1
self.baseY = self.baseY + self.moveSpeed
end
end
function MovableCrosshair:moveLeft()
if self.baseX > 5 then
self.baseX = self.baseX - 1
self.baseX = self.baseX - self.moveSpeed
end
end
function MovableCrosshair:moveRight()
if self.baseX < 395 then
self.baseX = self.baseX + 1
self.baseX = self.baseX + self.moveSpeed
end
end

View File

@@ -0,0 +1,36 @@
NoiseAnimation = {}
class('NoiseAnimation').extends(NobleSprite)
function NoiseAnimation:init(x, y)
NoiseAnimation.super.init(self, "assets/sprites/noise", true)
self.animation:addState("run", 2, 11)
self.animation:addState("idle", 1, 1)
self.animation.run.frameDuration = 2.5
self.animation:setState("idle")
self:setZIndex(ZIndex.foreground)
self:setSize(400, 240)
self:add()
self:moveTo(x, y)
self.state = "idle"
self.idleFrames = 0
end
function NoiseAnimation:update()
if self.state == "idle" then
self.idleFrames -= 1
if self.idleFrames <= 0 then
self.state = "run"
self.animation:setState("run")
end
else
local r = math.random(0)
if r < 0.01 then
self.state = "idle"
self.idleFrames = math.random(30, 100)
self.animation:setState("idle")
else
self.animation:setState("run")
end
end
end