Compare commits
3 Commits
3ca6427583
...
b0256d7ae3
Author | SHA1 | Date | |
---|---|---|---|
b0256d7ae3 | |||
9cd5c1bd81 | |||
4f6d0a6c24 |
@ -3,5 +3,6 @@
|
||||
## TODO:
|
||||
|
||||
- [ ] Menu audio
|
||||
- [ ] Tags, zOffset from constants
|
||||
- [x] Tags, zOffset from constants
|
||||
- [ ] Add global game state (?)
|
||||
- [x] Add inertia to the player
|
||||
|
BIN
source/assets/sprites/bgTest.png
Normal file
BIN
source/assets/sprites/bgTest.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.3 KiB |
@ -3,6 +3,8 @@ import "CoreLibs/object"
|
||||
import "CoreLibs/sprites"
|
||||
import "CoreLibs/timer"
|
||||
import "CoreLibs/ui"
|
||||
import "CoreLibs/math"
|
||||
|
||||
|
||||
-- Libraries
|
||||
import 'libraries/noble/Noble'
|
||||
@ -19,7 +21,9 @@ ZIndex = {
|
||||
props = 3,
|
||||
fx = 6,
|
||||
ui = 10,
|
||||
alert = 12
|
||||
alert = 12,
|
||||
ground = 100,
|
||||
flash = 101
|
||||
}
|
||||
CollideGroups = {
|
||||
player = 1,
|
||||
|
@ -17,9 +17,25 @@ local function screenShake(shakeTime, shakeMagnitude)
|
||||
end
|
||||
end
|
||||
|
||||
function scene:setValues()
|
||||
scene.background = Graphics.image.new("assets/sprites/bg")
|
||||
function scene:drawBackground()
|
||||
local speed = 0.1
|
||||
if Ground.player ~= nil and Ground.player.isMovingRight() == true then
|
||||
speed = 0.2
|
||||
end
|
||||
|
||||
if scene.distance > 0 then
|
||||
scene.bgX = scene.bgX - speed
|
||||
end
|
||||
|
||||
if scene.bgX <= -400 then
|
||||
scene.bgX = 0
|
||||
end
|
||||
self.bg:draw(scene.bgX or 0, 0)
|
||||
end
|
||||
|
||||
function scene:setValues()
|
||||
self.bg = Graphics.image.new("assets/sprites/bgTest")
|
||||
scene.bgX = 0
|
||||
scene.telemLostSound = playdate.sound.fileplayer.new("assets/audio/telemko")
|
||||
scene.telemLostSoundPlayed = false
|
||||
|
||||
@ -35,6 +51,10 @@ function scene:setValues()
|
||||
scene.levelAudio = playdate.sound.fileplayer.new("assets/audio/war")
|
||||
scene.levelAudio:setVolume(0.7)
|
||||
scene.helloAudio = playdate.sound.fileplayer.new("assets/audio/hello")
|
||||
|
||||
scene.tank = nil
|
||||
|
||||
scene.distance = 900
|
||||
end
|
||||
|
||||
function scene:init()
|
||||
@ -45,6 +65,8 @@ end
|
||||
function scene:start()
|
||||
scene.super.start(self)
|
||||
|
||||
playdate.ui.crankIndicator:draw() -- not sure why this is not working
|
||||
|
||||
self.optionsMenu:addMenuItem("Main Menu", function() Noble.transition(Menu) end)
|
||||
Noble.showFPS = true
|
||||
end
|
||||
@ -52,37 +74,37 @@ end
|
||||
function scene:spawnBaleba()
|
||||
local balebaCount = #scene.balebas
|
||||
if balebaCount >= 6 then
|
||||
scene.balebaSpawner:remove()
|
||||
return
|
||||
end
|
||||
|
||||
scene.balebas[balebaCount + 1] = Baleba(math.random(410, 900), math.random(10, 210), scene.player, true)
|
||||
|
||||
return scene.balebas[balebaCount + 1]
|
||||
--scene.balebas[balebaCount + 1] = Baleba(math.random(410, 900), math.random(10, 210), scene.player, true)
|
||||
end
|
||||
|
||||
function scene:enter()
|
||||
scene.super.enter(self)
|
||||
|
||||
|
||||
scene.player = Player(150, 100)
|
||||
scene.ground = Ground(0, 225, scene.player)
|
||||
|
||||
scene.balebaSpawner.timerEndedCallback = function()
|
||||
--scene.balebas[k] = scene:spawnBaleba()
|
||||
scene:spawnBaleba()
|
||||
end
|
||||
|
||||
for i = 1, 3 do
|
||||
scene:spawnBaleba()
|
||||
end
|
||||
|
||||
scene.helloAudio:play(1)
|
||||
--scene.helloAudio:play(1)
|
||||
if scene.musicEnabled then
|
||||
scene.levelAudio:play(0)
|
||||
--scene.levelAudio:play(0)
|
||||
end
|
||||
end
|
||||
|
||||
playdate.timer.performAfterDelay(1000, function()
|
||||
scene.tank = Tank(550, 190, scene.player, scene.ground)
|
||||
scene:addSprite(scene.tank) -- Raw sprite
|
||||
end)
|
||||
function round(number)
|
||||
local formatted = string.format("%.2f", number)
|
||||
return formatted
|
||||
end
|
||||
|
||||
function scene:update()
|
||||
@ -92,12 +114,24 @@ function scene:update()
|
||||
return
|
||||
end
|
||||
|
||||
if scene.distance > 0 then
|
||||
scene.distance = scene.distance - 1
|
||||
end
|
||||
|
||||
if scene.distance < 850 and scene.tank == nil then
|
||||
scene.tank = Tank(500, 190, scene.player, scene.ground)
|
||||
scene:addSprite(scene.tank) -- Raw sprite
|
||||
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)
|
||||
local t = scene.player.getBat() / 10000
|
||||
local lerpBat = playdate.math.lerp(12.0, 16.8, t)
|
||||
Noble.Text.draw(round(lerpBat) .. "v", 10, 210, Noble.Text.ALIGN_LEFT, false, font)
|
||||
Noble.Text.draw(scene.distance .. "m", 200, 40, Noble.Text.ALIGN_CENTER, false, font)
|
||||
end
|
||||
|
||||
if scene.player.isDead() and not scene.telemLostSoundPlayed then
|
||||
@ -107,7 +141,11 @@ function scene:update()
|
||||
|
||||
playdate.timer.performAfterDelay(4000, function()
|
||||
scene.resultShowed = true
|
||||
c = notify("Nice", function()
|
||||
local message = "You failed!"
|
||||
if scene.player.targetDone then
|
||||
message = "You did it!"
|
||||
end
|
||||
c = notify(message, function()
|
||||
Noble.transition(Menu)
|
||||
c:remove()
|
||||
end)
|
||||
|
@ -15,10 +15,15 @@ function Baleba:init(x, y, player, loop)
|
||||
self.animation:setState("run")
|
||||
|
||||
-- Collision properties
|
||||
self:setZIndex(11)
|
||||
self:setZIndex(ZIndex.enemy)
|
||||
self:setCollideRect(3, 25, 40, 15)
|
||||
self:setTag(154)
|
||||
self:setSize(64, 64)
|
||||
self:setGroups(CollideGroups.enemy)
|
||||
self:setCollidesWithGroups(
|
||||
{
|
||||
CollideGroups.player
|
||||
})
|
||||
|
||||
-- Sprite properties
|
||||
self.standrate = randomFloat(0.3, 2)
|
||||
|
@ -12,7 +12,7 @@ function BigBoom:init()
|
||||
self:playAnimation()
|
||||
self:setCenter(0, 0)
|
||||
self:setSize(playdate.display.getSize())
|
||||
self:setZIndex(120)
|
||||
self:setZIndex(ZIndex.flash)
|
||||
|
||||
self:moveTo(0, 0)
|
||||
|
||||
|
@ -12,7 +12,7 @@ function Danger:init(x, y, dangerousObject)
|
||||
self.animation:setState("run")
|
||||
|
||||
-- Collision properties
|
||||
self:setZIndex(11)
|
||||
self:setZIndex(ZIndex.alert)
|
||||
self:setTag(7)
|
||||
self:setSize(64, 64)
|
||||
|
||||
|
@ -5,9 +5,14 @@ function Ground:init(x, y, player)
|
||||
Ground.super.init(self, "assets/sprites/groundFin")
|
||||
|
||||
-- Collision properties
|
||||
self:setZIndex(100)
|
||||
self:setZIndex(ZIndex.ground)
|
||||
self:setTag(3)
|
||||
self:setGroups(CollideGroups.wall)
|
||||
self:setCollideRect(0, 28, 800, 10)
|
||||
self:setCollidesWithGroups(
|
||||
{
|
||||
CollideGroups.player
|
||||
})
|
||||
self:setSize(800, 32)
|
||||
|
||||
-- Main properties
|
||||
|
@ -5,7 +5,7 @@ function Player:init(x, y)
|
||||
Player.super.init(self, "assets/sprites/player", true)
|
||||
|
||||
-- Animation properties
|
||||
self.animation:addState("run", 1, 7)
|
||||
self.animation:addState("run", 8, 14)
|
||||
self.animation.run.frameDuration = 2
|
||||
self.animation:addState("up", 1, 7)
|
||||
self.animation.up.frameDuration = 6
|
||||
@ -22,27 +22,39 @@ function Player:init(x, y)
|
||||
-- Collision properties
|
||||
self:setSize(64, 64)
|
||||
self:moveTo(x, y)
|
||||
self:setZIndex(10)
|
||||
self:setCollideRect(3, 19, 63, 33)
|
||||
self:setZIndex(ZIndex.player)
|
||||
self:setGroups(CollideGroups.player)
|
||||
self:setCollidesWithGroups(
|
||||
{
|
||||
CollideGroups.enemy,
|
||||
CollideGroups.wall
|
||||
})
|
||||
self:setCollideRect(3, 19, 60, 33)
|
||||
self:setTag(1)
|
||||
|
||||
-- Physics properties
|
||||
self.xVelocity = 0
|
||||
self.yVelocity = 0
|
||||
self.fallSpeed = 0.05
|
||||
self.xVelocity = -0.5
|
||||
self.yVelocity = self.fallSpeed
|
||||
self.maxXSpeed = 2
|
||||
self.maxYSpeed = 5
|
||||
self.fallSpeed = 0.05
|
||||
self.maxFallSpeed = 0.4
|
||||
self.acceleration = 0.05
|
||||
self.friction = 0.95
|
||||
self.yInertia = 0
|
||||
self.maxFallSpeed = 0.7
|
||||
self.frictionAccel = 0.3
|
||||
|
||||
-- Player State
|
||||
self.touchingGround = false
|
||||
self.touchingCeiling = false
|
||||
self.touchingWall = false
|
||||
Player.dead = false
|
||||
Player.bat = 10000
|
||||
Player.fullBat = 10000
|
||||
Player.bat = Player.fullBat
|
||||
Player.dischargeRate = 1
|
||||
self.cantDown = false
|
||||
Player.moveRight = false
|
||||
self.lastDirection = nil
|
||||
self.targetDone = false
|
||||
end
|
||||
|
||||
function Player:handleInput()
|
||||
@ -52,54 +64,53 @@ function Player:handleInput()
|
||||
|
||||
local crankChange, acceleratedChange = playdate.getCrankChange()
|
||||
|
||||
if playdate.buttonJustReleased(playdate.kButtonLeft) or playdate.buttonJustReleased(playdate.kButtonRight) then
|
||||
self.cantDown = false
|
||||
end
|
||||
|
||||
if playdate.buttonIsPressed(playdate.kButtonLeft) then
|
||||
self:changeToRunState("left")
|
||||
self:setRotation(10)
|
||||
self.cantDown = true
|
||||
-- X velocity
|
||||
if not playdate.buttonIsPressed(playdate.kButtonLeft) and not playdate.buttonIsPressed(playdate.kButtonRight) then
|
||||
self.xVelocity = self.xVelocity * self.friction
|
||||
Player.moveRight = false
|
||||
elseif playdate.buttonIsPressed(playdate.kButtonRight) then
|
||||
self:changeToRunState("right")
|
||||
self:setRotation(10)
|
||||
self.cantDown = true
|
||||
Player.moveRight = true
|
||||
self.animation:setState("down")
|
||||
end
|
||||
|
||||
local isChangingDirection = false
|
||||
if playdate.buttonIsPressed(playdate.kButtonLeft) then
|
||||
if self.lastDirection == "right" then
|
||||
isChangingDirection = true
|
||||
end
|
||||
self:changeToRunState("left")
|
||||
self.lastDirection = "left"
|
||||
self.xVelocity = self.xVelocity - self.acceleration
|
||||
elseif playdate.buttonIsPressed(playdate.kButtonRight) then
|
||||
if self.lastDirection == "left" then
|
||||
isChangingDirection = true
|
||||
end
|
||||
self:changeToRunState("right")
|
||||
Player.moveRight = true
|
||||
self.lastDirection = "right"
|
||||
self.xVelocity = self.xVelocity + self.acceleration
|
||||
end
|
||||
|
||||
if isChangingDirection then
|
||||
self.xVelocity = self.xVelocity * self.frictionAccel
|
||||
end
|
||||
|
||||
-- Y velocity
|
||||
if crankChange ~= 0 then
|
||||
local force = 0.01
|
||||
if crankChange > 0 then
|
||||
self.animation:setState("up")
|
||||
else
|
||||
self.animation:setState("down")
|
||||
force = 0.05
|
||||
end
|
||||
self.yVelocity = self.yVelocity - acceleratedChange * force
|
||||
elseif self.cantDown == false then
|
||||
self.cantDown = false
|
||||
self:changeToDownState()
|
||||
self.yInertia = self.yInertia - (acceleratedChange * 0.007)
|
||||
else
|
||||
self.yVelocity = self.fallSpeed
|
||||
self.yInertia = self.yInertia * self.friction
|
||||
end
|
||||
end
|
||||
|
||||
function Player:changeToDownState()
|
||||
Player.moveRight = false
|
||||
self.yVelocity = self.fallSpeed
|
||||
self.xVelocity = 0
|
||||
self.animation:setState("down")
|
||||
self:setRotation(0)
|
||||
end
|
||||
|
||||
function Player:changeToRunState(direction)
|
||||
if direction == "left" then
|
||||
self.xVelocity = -self.maxXSpeed
|
||||
self.animation.direction = Noble.Animation.DIRECTION_LEFT
|
||||
self.animation:setState("run")
|
||||
elseif direction == "right" then
|
||||
self.xVelocity = self.maxXSpeed
|
||||
self.animation.direction = Noble.Animation.DIRECTION_RIGHT
|
||||
self.animation:setState("run")
|
||||
end
|
||||
@ -129,12 +140,13 @@ function Player:handleMovementAndCollisions()
|
||||
end
|
||||
|
||||
local xVel = self.xVelocity
|
||||
local yVel = self.yVelocity + self.yInertia + self.fallSpeed
|
||||
|
||||
if (self.x < 20 and xVel < 0) or (self.x > 380 and xVel > 0) then -- Screen bounds
|
||||
xVel = 0
|
||||
end
|
||||
|
||||
local _, _, collisions, length = self:checkCollisions(self.x + xVel, self.y + self.yVelocity)
|
||||
local _, _, collisions, length = self:checkCollisions(self.x + xVel, self.y + yVel)
|
||||
|
||||
self.touchingGround = false
|
||||
self.touchingCeiling = false
|
||||
@ -161,12 +173,13 @@ function Player:handleMovementAndCollisions()
|
||||
self:boom()
|
||||
return
|
||||
elseif collisionTag == 154 then -- Baleba
|
||||
-- self:boom(collisionObject)
|
||||
--self:boom(collisionObject)
|
||||
return
|
||||
elseif collisionTag == 2 then -- Tank
|
||||
self:boom()
|
||||
BigBoom()
|
||||
|
||||
self.targetDone = true
|
||||
local particleC = ParticlePoly(collisionObject.x, collisionObject.y)
|
||||
particleC:setThickness(5)
|
||||
particleC:setAngular(-15, 15)
|
||||
@ -180,7 +193,8 @@ function Player:handleMovementAndCollisions()
|
||||
return
|
||||
end
|
||||
end
|
||||
self:moveTo(self.x + xVel, self.y + self.yVelocity)
|
||||
|
||||
self:moveTo(self.x + xVel, self.y + yVel)
|
||||
end
|
||||
|
||||
function Player:handleDischarge(state)
|
||||
@ -190,7 +204,7 @@ function Player:handleDischarge(state)
|
||||
if Player.bat <= 0 then
|
||||
Player.bat = 0
|
||||
self.fallSpeed = 2
|
||||
self:changeToDownState()
|
||||
self.animation:setState("down")
|
||||
return
|
||||
end
|
||||
|
||||
@ -198,6 +212,10 @@ function Player:handleDischarge(state)
|
||||
self.fallSpeed = self.maxFallSpeed
|
||||
end
|
||||
|
||||
if Player.bat < 3000 then
|
||||
self.frictionAccel = 0.4
|
||||
end
|
||||
|
||||
if state == "run" then
|
||||
Player.dischargeRate = 5
|
||||
elseif state == "up" then
|
||||
@ -216,7 +234,6 @@ end
|
||||
function Player:update()
|
||||
self:handleMovementAndCollisions()
|
||||
if Player.dead then
|
||||
print("Player is dead")
|
||||
return
|
||||
end
|
||||
|
||||
|
@ -16,9 +16,14 @@ function Tank:init(x, y, player, ground)
|
||||
Graphics.popContext()
|
||||
|
||||
-- Collision properties
|
||||
self:setZIndex(99)
|
||||
self:setZIndex(ZIndex.enemy)
|
||||
self:setTag(2)
|
||||
self:setCollideRect(4, 56, 147, 65)
|
||||
self:setGroups(CollideGroups.enemy)
|
||||
self:setCollidesWithGroups(
|
||||
{
|
||||
CollideGroups.player
|
||||
})
|
||||
|
||||
-- Main properties
|
||||
Tank.moveSpeed = 2
|
||||
|
Loading…
Reference in New Issue
Block a user