noble animations
This commit is contained in:
parent
f19610e458
commit
3ca6427583
16
.luarc.json
16
.luarc.json
@ -13,10 +13,22 @@
|
||||
"os": "disable",
|
||||
"package": "disable"
|
||||
},
|
||||
"runtime.nonstandardSymbol": ["+=", "-=", "*=", "/=", "//=", "%=", "<<=", ">>=", "&=", "|=", "^="],
|
||||
"runtime.nonstandardSymbol": [
|
||||
"+=",
|
||||
"-=",
|
||||
"*=",
|
||||
"/=",
|
||||
"//=",
|
||||
"%=",
|
||||
"<<=",
|
||||
">>=",
|
||||
"&=",
|
||||
"|=",
|
||||
"^="
|
||||
],
|
||||
"runtime.version": "Lua 5.4",
|
||||
"workspace.library": [
|
||||
"/home/ut3usw/src/playdate-luacats"
|
||||
"/home/ut3usw/src/playdate-luacats",
|
||||
"/home/ut3usw/Projects/VSCode-PlaydateTemplate/source/libraries"
|
||||
]
|
||||
}
|
||||
|
@ -1 +1,7 @@
|
||||
# FPV Run
|
||||
|
||||
## TODO:
|
||||
|
||||
- [ ] Menu audio
|
||||
- [ ] Tags, zOffset from constants
|
||||
- [ ] Add global game state (?)
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.4 KiB |
BIN
source/assets/sprites/bigboom-table-400-240.png
Normal file
BIN
source/assets/sprites/bigboom-table-400-240.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.8 KiB |
BIN
source/assets/sprites/oldbaleba-table-64-64.png
Normal file
BIN
source/assets/sprites/oldbaleba-table-64-64.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.5 KiB |
@ -49,7 +49,6 @@ Noble.Animation = {}
|
||||
-- end
|
||||
-- @see NobleSprite:init
|
||||
function Noble.Animation.new(__view)
|
||||
|
||||
local animation = {}
|
||||
|
||||
--- Properties
|
||||
@ -117,7 +116,6 @@ function Noble.Animation.new(__view)
|
||||
-- animation.["jump"].next -- "float"
|
||||
-- animation.idle.next -- nil
|
||||
function animation:addState(__name, __startFrame, __endFrame, __next, __loop, __onComplete, __frameDuration)
|
||||
|
||||
local loop = true
|
||||
local frameDuration = 1
|
||||
if (__loop ~= nil) then loop = __loop end
|
||||
@ -140,7 +138,6 @@ function Noble.Animation.new(__view)
|
||||
self.currentName = __name
|
||||
self.frameDuration = frameDuration
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--- Methods
|
||||
@ -180,7 +177,6 @@ function Noble.Animation.new(__view)
|
||||
-- groundedLastFrame = grounded
|
||||
-- end
|
||||
function animation:setState(__animationState, __continuous, __unlessThisState)
|
||||
|
||||
if (__unlessThisState ~= nil) then
|
||||
if (type(__unlessThisState) == "string") then
|
||||
if (self.currentName == __unlessThisState) then return end
|
||||
@ -228,7 +224,6 @@ function Noble.Animation.new(__view)
|
||||
-- animation:draw(100,100)
|
||||
-- end
|
||||
function animation:draw(__x, __y, __advance)
|
||||
|
||||
--print(self.currentName .. " > " .. self.currentFrame .. " >> " .. tostring(self.current.loop))
|
||||
|
||||
if (__advance == nil) then __advance = true end
|
||||
@ -242,11 +237,13 @@ function Noble.Animation.new(__view)
|
||||
self.previousFrameDurationCount = self.frameDuration
|
||||
self:setState(self.current.next) -- Set next animation state.
|
||||
elseif (self.current.loop == true) then
|
||||
self.currentFrame = self.current.startFrame -- Loop animation state. (TO-DO: account for continuous somehow?)
|
||||
self.currentFrame = self.current
|
||||
.startFrame -- Loop animation state. (TO-DO: account for continuous somehow?)
|
||||
self.frameDurationCount = 1 -- Reset ticks.
|
||||
self.previousFrameDurationCount = self.frameDuration
|
||||
elseif (__advance) then
|
||||
self.currentFrame = self.currentFrame - 1 -- Undo advance frame because we want to draw the same frame again.
|
||||
self.currentFrame = self.currentFrame -
|
||||
1 -- Undo advance frame because we want to draw the same frame again.
|
||||
end
|
||||
|
||||
if (self.current.onComplete ~= nil) then
|
||||
|
@ -56,9 +56,7 @@ class("NobleSprite").extends(Graphics.sprite)
|
||||
function NobleSprite:init(__view, __viewIsSpritesheet, __singleState, __singleStateLoop)
|
||||
NobleSprite.super.init(self)
|
||||
self.isNobleSprite = true -- This is important so other methods don't confuse this for a playdate.graphics.sprite. DO NOT modify this value at runtime.
|
||||
|
||||
if (__view ~= nil) then
|
||||
|
||||
-- __view is the path to an image or spritesheet file.
|
||||
if (type(__view) == "string") then
|
||||
self.animated = __viewIsSpritesheet -- NO NOT modify self.animated at runtime.
|
||||
@ -76,7 +74,6 @@ function NobleSprite:init(__view, __viewIsSpritesheet, __singleState, __singleSt
|
||||
if (__singleState == true) then
|
||||
self.animation:addState("default", 1, self.animation.imageTable:getLength(), nil, singleStateLoop)
|
||||
end
|
||||
|
||||
else
|
||||
-- Create a new Graphics.image object.
|
||||
self:setImage(Graphics.image.new(__view))
|
||||
@ -92,9 +89,7 @@ function NobleSprite:init(__view, __viewIsSpritesheet, __singleState, __singleSt
|
||||
self.animated = true
|
||||
self.animation = __view
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
function NobleSprite:draw()
|
||||
|
@ -13,7 +13,24 @@ import "libraries/playout"
|
||||
import 'utilities/enum'
|
||||
import 'utilities/ui'
|
||||
|
||||
ZIndex = {
|
||||
player = 4,
|
||||
enemy = 3,
|
||||
props = 3,
|
||||
fx = 6,
|
||||
ui = 10,
|
||||
alert = 12
|
||||
}
|
||||
CollideGroups = {
|
||||
player = 1,
|
||||
enemy = 2,
|
||||
props = 3,
|
||||
items = 4,
|
||||
wall = 5
|
||||
}
|
||||
|
||||
import "scripts/player"
|
||||
import "scripts/bigBoomSprite"
|
||||
import "scripts/groundSprite"
|
||||
import "scripts/balebaSprite"
|
||||
import "scripts/dangerSprite"
|
||||
|
@ -23,17 +23,18 @@ function scene:setValues()
|
||||
scene.telemLostSound = playdate.sound.fileplayer.new("assets/audio/telemko")
|
||||
scene.telemLostSoundPlayed = false
|
||||
|
||||
scene.resultShowed = false
|
||||
|
||||
scene.musicEnabled = Noble.Settings.get("music")
|
||||
|
||||
scene.balebas = {}
|
||||
|
||||
scene.t = playdate.timer.new(10000)
|
||||
scene.t.repeats = true
|
||||
|
||||
scene.tankTimer = playdate.timer.new(1000)
|
||||
|
||||
scene.fp = playdate.sound.fileplayer.new( "assets/audio/war" )
|
||||
scene.fp:setVolume(0.7)
|
||||
scene.hello = playdate.sound.fileplayer.new( "assets/audio/hello" )
|
||||
scene.balebaSpawner = playdate.timer.new(10000)
|
||||
scene.balebaSpawner.repeats = true
|
||||
|
||||
scene.levelAudio = playdate.sound.fileplayer.new("assets/audio/war")
|
||||
scene.levelAudio:setVolume(0.7)
|
||||
scene.helloAudio = playdate.sound.fileplayer.new("assets/audio/hello")
|
||||
end
|
||||
|
||||
function scene:init()
|
||||
@ -49,112 +50,86 @@ function scene:start()
|
||||
end
|
||||
|
||||
function scene:spawnBaleba()
|
||||
local baleba = Baleba(math.random(410, 900), math.random(10, 210), scene.player, true)
|
||||
baleba:add()
|
||||
local balebaCount = #scene.balebas
|
||||
if balebaCount >= 6 then
|
||||
return
|
||||
end
|
||||
|
||||
return baleba
|
||||
scene.balebas[balebaCount + 1] = Baleba(math.random(410, 900), math.random(10, 210), scene.player, true)
|
||||
|
||||
return scene.balebas[balebaCount + 1]
|
||||
end
|
||||
|
||||
function scene:enter()
|
||||
scene.super.enter(self)
|
||||
|
||||
scene.player = Player(30, 30)
|
||||
scene.player:add()
|
||||
scene.player = Player(150, 100)
|
||||
scene.ground = Ground(0, 225, scene.player)
|
||||
|
||||
scene.ground = Ground(400, 225, scene.player)
|
||||
scene.ground:add()
|
||||
|
||||
scene.t.timerEndedCallback = function()
|
||||
if #scene.balebas >= 6 then
|
||||
return
|
||||
end
|
||||
|
||||
local k = #scene.balebas+1
|
||||
scene.balebaSpawner.timerEndedCallback = function()
|
||||
--scene.balebas[k] = scene:spawnBaleba()
|
||||
end
|
||||
|
||||
for i = 1, 3 do
|
||||
scene.balebas[i] = scene:spawnBaleba()
|
||||
scene:spawnBaleba()
|
||||
end
|
||||
|
||||
local musicEnabled = Noble.Settings.get("music")
|
||||
scene.hello:play(1)
|
||||
if musicEnabled then
|
||||
scene.fp:play(0)
|
||||
scene.helloAudio:play(1)
|
||||
if scene.musicEnabled then
|
||||
scene.levelAudio:play(0)
|
||||
end
|
||||
|
||||
scene.tankTimer.timerEndedCallback = function()
|
||||
playdate.timer.performAfterDelay(1000, function()
|
||||
scene.tank = Tank(550, 190, scene.player, scene.ground)
|
||||
scene.tank:add()
|
||||
end
|
||||
scene:addSprite(scene.tank) -- Raw sprite
|
||||
end)
|
||||
end
|
||||
|
||||
function scene:update()
|
||||
scene.super.update(self)
|
||||
|
||||
if scene.player == nil then
|
||||
Noble.Text.draw("Telemetry Lost", 200, 110, Noble.Text.ALIGN_CENTER, false, font)
|
||||
return
|
||||
end
|
||||
|
||||
if scene.player.isDead() then
|
||||
if scene.resultShowed ~= true then
|
||||
Noble.Text.draw("Telemetry Lost", 200, 110, Noble.Text.ALIGN_CENTER, false, font)
|
||||
end
|
||||
else
|
||||
Noble.Text.draw("Bat: " .. math.floor(scene.player.getBat() / 100), 10, 215, Noble.Text.ALIGN_LEFT, false, font)
|
||||
end
|
||||
|
||||
if scene.player.isDead() and not scene.telemLostSoundPlayed then
|
||||
scene.telemLostSound:play(1)
|
||||
scene.telemLostSoundPlayed = true
|
||||
screenShake(500, 5)
|
||||
screenShake(1000, 5)
|
||||
|
||||
|
||||
local et = playdate.timer.new(6000)
|
||||
et.timerEndedCallback = function()
|
||||
playdate.timer.performAfterDelay(4000, function()
|
||||
scene.resultShowed = true
|
||||
c = notify("Nice", function()
|
||||
Noble.transition(Menu)
|
||||
end
|
||||
c:remove()
|
||||
end)
|
||||
c:moveTo(200, 120)
|
||||
c:add()
|
||||
end)
|
||||
|
||||
return
|
||||
end
|
||||
|
||||
local bat = scene.player.getBat()
|
||||
bat = math.floor(bat/100)
|
||||
Noble.Text.draw("Bat: " .. bat, 10, 215, Noble.Text.ALIGN_LEFT, false, font)
|
||||
|
||||
end
|
||||
|
||||
function scene:destroyPlayer()
|
||||
if scene.player ~= nil then
|
||||
scene.player:remove()
|
||||
scene.player = nil
|
||||
end
|
||||
end
|
||||
|
||||
function scene:exit()
|
||||
scene.super.exit(self)
|
||||
|
||||
scene:destroyPlayer()
|
||||
|
||||
scene.ground:remove()
|
||||
scene.ground = nil
|
||||
|
||||
scene.tank:remove()
|
||||
scene.ground = nil
|
||||
|
||||
for i=1, #scene.balebas do
|
||||
scene.balebas[i]:destroy()
|
||||
scene.balebas[i] = nil
|
||||
end
|
||||
|
||||
scene.telemLostSound:stop()
|
||||
scene.telemLostSoundPlayed = false
|
||||
|
||||
scene.fp:stop()
|
||||
|
||||
scene.t:remove()
|
||||
scene.t = nil
|
||||
|
||||
scene.tankTimer:remove()
|
||||
scene.tankTimer = nil
|
||||
|
||||
scene.levelAudio:stop()
|
||||
scene.balebaSpawner:remove()
|
||||
|
||||
Noble.showFPS = false
|
||||
end
|
||||
|
||||
|
||||
function scene:finish()
|
||||
scene.super.finish(self)
|
||||
playdate.display.setScale(1)
|
||||
|
@ -1,24 +1,24 @@
|
||||
Baleba = {}
|
||||
class('Baleba').extends(AnimatedSprite)
|
||||
class('Baleba').extends(NobleSprite)
|
||||
|
||||
function randomFloat(lower, greater)
|
||||
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
|
||||
@ -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
|
||||
|
28
source/scripts/bigBoomSprite.lua
Normal file
28
source/scripts/bigBoomSprite.lua
Normal 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
|
@ -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
|
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user