noble animations
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user