From b0256d7ae3ce4f639fa92fa09471b14b27c6ea65 Mon Sep 17 00:00:00 2001 From: assada Date: Mon, 3 Jun 2024 20:08:46 +0300 Subject: [PATCH] bg --- source/assets/sprites/bgTest.png | Bin 0 -> 1327 bytes source/main.lua | 2 ++ source/scenes/Game.lua | 50 +++++++++++++++++++++++++------ source/scripts/player.lua | 5 ++-- 4 files changed, 46 insertions(+), 11 deletions(-) create mode 100644 source/assets/sprites/bgTest.png diff --git a/source/assets/sprites/bgTest.png b/source/assets/sprites/bgTest.png new file mode 100644 index 0000000000000000000000000000000000000000..ff3b8c48243768ccd55fa0a50dde40ed8f15a56d GIT binary patch literal 1327 zcmeAS@N?(olHy`uVBq!ia0y~yU{(OKKX9-C$sfxYZUHH_ByV>YhW{YAVDIwDKoQOY zkH}&M20djEW~^9hUj`IpFY)wsWq-lO%+F`sXqmJGC?r|p8d2h$pPQSSSHj?2l$uzQ znxasiS(2gP?&%v4-pD7;z`!!y)5S5Q;?~={iG9rq0u2|F_WYlEvwrq6&tOr;^osXv zsF)@MCQR6GOxLRnP5qT+icVU=WznR5a!6eMJTa1qYz1j6l;d85{yo zDLCWI=4g;HU8)3J(r^!`B*O2jE!zQ|*&xMkH+2~cg!ivvW?*8miKyPd#xU=&m<|Jj zLjzFq=Zz*-hSwXGip)62!UA-g0s}(>10x#aKt2vpp5(u#3qr(JjaR7M7m!yt1cj!6nIM6|E8GMLNBfz5w#AA|hYP^PEE!Vux^ z`z11FjpP(!bu`?F(P3{%Vgd#r$P}=DVxIAEFdVR&vpLZUgT*;`AixwbD43-`ZwT;l00s;wTHs-i#8|LCi<6;Y<{f4xmxt?^fdN)w zz|7F_IOiZxJqy^Y4L@XD*cp};vav9Hte&^IoI!kM1JFQ_C7|GiGA1-0UdF&+{t@Je zsEWg~%V)q8oj48@doWqo)WKX$;Q==fIJg<^g?ckM_^Sa8IA8!IQ&L~69AL&~Fwlno zdsw*{8pQ5d9M=SC07vMjjX<#i(D|y~n8D_L8Zal} oj3j8p!&3#EL6kKEtjOT7{G$*N&sid!wjh^yy85}Sb4q9e04ChpW&i*H literal 0 HcmV?d00001 diff --git a/source/main.lua b/source/main.lua index 46cd186..4a45f36 100644 --- a/source/main.lua +++ b/source/main.lua @@ -3,6 +3,8 @@ import "CoreLibs/object" import "CoreLibs/sprites" import "CoreLibs/timer" import "CoreLibs/ui" +import "CoreLibs/math" + -- Libraries import 'libraries/noble/Noble' diff --git a/source/scenes/Game.lua b/source/scenes/Game.lua index d8ebdba..d4d4ced 100644 --- a/source/scenes/Game.lua +++ b/source/scenes/Game.lua @@ -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() @@ -76,15 +96,15 @@ function scene:enter() 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() @@ -94,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 diff --git a/source/scripts/player.lua b/source/scripts/player.lua index dcd65f9..922a915 100644 --- a/source/scripts/player.lua +++ b/source/scripts/player.lua @@ -49,7 +49,8 @@ function Player:init(x, y) self.touchingCeiling = false self.touchingWall = false Player.dead = false - Player.bat = 10000 + Player.fullBat = 10000 + Player.bat = Player.fullBat Player.dischargeRate = 1 Player.moveRight = false self.lastDirection = nil @@ -172,7 +173,7 @@ 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()