noble animations

This commit is contained in:
2024-06-02 20:25:27 +03:00
parent f19610e458
commit 3ca6427583
15 changed files with 218 additions and 192 deletions

View File

@@ -1,24 +1,24 @@
Baleba = {}
class('Baleba').extends(AnimatedSprite)
class('Baleba').extends(NobleSprite)
function randomFloat(lower, greater)
return lower + math.random() * (greater - lower);
return lower + math.random() * (greater - lower);
end
local balebaImageTable = Graphics.imagetable.new("assets/sprites/baleba")
function Baleba:init(x, y, player, loop)
Baleba.super.init(self, balebaImageTable)
Baleba.super.init(self, "assets/sprites/baleba", true)
-- Animation properties
self:addState("run", 1,4, {tickStep = 2})
self:setDefaultState("run")
self:playAnimation()
self.animation:addState("run", 1, 4)
self.animation.run.frameDuration = 2
self.animation:setState("run")
-- Collision properties
self:setZIndex(11)
self:setCollideRect(3, 25, 40, 15)
self:setTag(154)
self:setSize(64, 64)
-- Sprite properties
self.standrate = randomFloat(0.3, 2)
@@ -28,15 +28,13 @@ function Baleba:init(x, y, player, loop)
-- Danger properties
self.danger = Danger(366, y, self)
self.danger:add()
self:add()
-- Move to initial position
self:moveTo(x, y)
end
function Baleba:update()
self:updateAnimation()
-- Speedup when player is moving right
if self.player == nil or self.player.isMovingRight() == false then
self.xVelocity = self.standrate
@@ -44,7 +42,7 @@ function Baleba:update()
self.xVelocity = 2 + self.standrate
end
self:moveTo(self.x-self.xVelocity, self.y)
self:moveTo(self.x - self.xVelocity, self.y)
-- Danger arrow management
if self.x < 430 and self.danger ~= nil then
@@ -52,7 +50,6 @@ function Baleba:update()
self.danger = nil
elseif self.danger == nil and self.x > 430 then
self.danger = Danger(366, self.y, self)
self.danger:add()
end
-- Lifeciycle management
@@ -69,4 +66,4 @@ function Baleba:destroy()
self.danger:remove()
end
self:remove()
end
end

View File

@@ -0,0 +1,28 @@
BigBoom = {}
class("BigBoom").extends(AnimatedSprite)
local bigBoomImageTable = Graphics.imagetable.new("assets/sprites/bigboom")
function BigBoom:init()
BigBoom.super.init(self, bigBoomImageTable)
-- Animation properties
self:addState("play", 1, 3, { tickStep = 4, loop = 3 })
self:setDefaultState("play")
self:playAnimation()
self:setCenter(0, 0)
self:setSize(playdate.display.getSize())
self:setZIndex(120)
self:moveTo(0, 0)
self:add()
end
function BigBoom:update()
self:updateAnimation()
end
function BigBoom:stopAnimation()
self:remove()
end

View File

@@ -1,24 +1,21 @@
Danger = {}
class("Danger").extends(AnimatedSprite)
local dangerImageTable = Graphics.imagetable.new("assets/sprites/danger")
class("Danger").extends(NobleSprite)
function Danger:init(x, y, dangerousObject)
Danger.super.init(self, dangerImageTable)
Danger.super.init(self, "assets/sprites/danger", true)
self.dangerousObject = dangerousObject
-- Animation properties
self:addState("run", 1,5, {tickStep = 2})
self:setDefaultState("run")
self:playAnimation()
self.animation:addState("run", 1, 5)
self.animation.run.frameDuration = 2
self.animation:setState("run")
-- Collision properties
self:setZIndex(11)
self:setTag(7)
self:setSize(64, 64)
self:add()
self:moveTo(x, y)
end
function Danger:update()
self:updateAnimation()
end

View File

@@ -1,21 +1,20 @@
Ground = {}
class("Ground").extends(Graphics.sprite)
local groundImage = Graphics.image.new("assets/sprites/groundFin")
class("Ground").extends(NobleSprite)
function Ground:init(x, y, player)
Ground.super.init(self, groundImage)
Ground.super.init(self, "assets/sprites/groundFin")
-- Collision properties
self:setZIndex(100)
self:setTag(3)
self:setCollideRect(0, 28, 800, 10)
self:setSize(800, 32)
-- Main properties
Ground.moveSpeed = 2
Ground.player = player
-- Move to initial position
self:add()
self:moveTo(x, y)
end
@@ -24,7 +23,6 @@ function Ground:setMoveSpeed(speed)
end
function Ground:update()
-- Stop ground
if Ground.moveSpeed == 0 then
return
@@ -43,5 +41,5 @@ function Ground:update()
end
-- Move ground
self:moveWithCollisions(self.x-Ground.moveSpeed, self.y)
end
self:moveWithCollisions(self.x - Ground.moveSpeed, self.y)
end

View File

@@ -1,20 +1,26 @@
Player = {}
class("Player").extends(AnimatedSprite)
local playerImageTable = Graphics.imagetable.new("assets/sprites/player")
class("Player").extends(NobleSprite)
function Player:init(x, y)
Player.super.init(self, playerImageTable)
Player.super.init(self, "assets/sprites/player", true)
-- Animation properties
self:addState("run", 1, 7, { tickStep = 2 })
self:addState("up", 1, 7, { tickStep = 6 })
self:addState("down", 1, 7, { tickStep = 6 })
self:addState("boom", 15, 21, { tickStep = 10, loop = false })
self:setDefaultState("down")
self:playAnimation()
self.animation:addState("run", 1, 7)
self.animation.run.frameDuration = 2
self.animation:addState("up", 1, 7)
self.animation.up.frameDuration = 6
self.animation:addState("down", 1, 7)
self.animation.down.frameDuration = 6
self.animation:addState("boom", 15, 21)
self.animation.boom.frameDuration = 10
self.animation.boom.loop = false
self.animation:setState("down")
self:add()
-- Collision properties
self:setSize(64, 64)
self:moveTo(x, y)
self:setZIndex(10)
self:setCollideRect(3, 19, 63, 33)
@@ -65,9 +71,9 @@ function Player:handleInput()
if crankChange ~= 0 then
local force = 0.01
if crankChange > 0 then
self:changeState("up")
self.animation:setState("up")
else
self:changeState("down")
self.animation:setState("down")
force = 0.05
end
self.yVelocity = self.yVelocity - acceleratedChange * force
@@ -83,25 +89,25 @@ function Player:changeToDownState()
Player.moveRight = false
self.yVelocity = self.fallSpeed
self.xVelocity = 0
self:changeState("down")
self.animation:setState("down")
self:setRotation(0)
end
function Player:changeToRunState(direction)
if direction == "left" then
self.xVelocity = -self.maxXSpeed
self.globalFlip = 1
self:changeState("run")
self.animation.direction = Noble.Animation.DIRECTION_LEFT
self.animation:setState("run")
elseif direction == "right" then
self.xVelocity = self.maxXSpeed
self.globalFlip = 0
self:changeState("run")
self.animation.direction = Noble.Animation.DIRECTION_RIGHT
self.animation:setState("run")
end
end
function Player:boom(collisionObject)
Player.dead = true
self:changeState("boom")
self.animation:setState("boom")
local particleB = ParticlePoly(self.x, self.y)
particleB:setThickness(2)
@@ -159,11 +165,12 @@ function Player:handleMovementAndCollisions()
return
elseif collisionTag == 2 then -- Tank
self:boom()
BigBoom()
local particleC = ParticlePoly(collisionObject.x, collisionObject.y)
particleC:setThickness(5)
particleC:setAngular(-15, 15)
particleC:setSize(1, 5)
particleC:setSize(1, 10)
particleC:setSpeed(1, 3)
particleC:setMode(Particles.modes.STAY)
particleC:setBounds(0, 0, 400, 240)
@@ -207,16 +214,13 @@ function Player:handleDischarge(state)
end
function Player:update()
self:updateAnimation()
self:handleMovementAndCollisions()
if Player.dead then
print("Player is dead")
return
end
local state = self:getCurrentState()["name"]
self:handleDischarge(state)
self:handleDischarge(self.animation.currentName)
self:handleInput()
end

View File

@@ -13,7 +13,7 @@ function Tank:init(x, y, player, ground)
Graphics.pushContext(self.faded_image)
self.tankImageD:drawBlurred(0, 0, 2, 2, Graphics.image.kDitherTypeFloydSteinberg)
Graphics.popContext()
Graphics.popContext()
-- Collision properties
self:setZIndex(99)
@@ -51,5 +51,5 @@ function Tank:update()
Tank.moveSpeed = 1
end
self:moveTo(self.x-Tank.moveSpeed, self.y)
self:moveTo(self.x - Tank.moveSpeed, self.y)
end