aboutsummaryrefslogtreecommitdiff
path: root/assets/scripts
diff options
context:
space:
mode:
authorArslaan Pathan <[email protected]>2025-06-29 12:58:54 +1200
committerArslaan Pathan <[email protected]>2025-06-29 12:58:54 +1200
commit7620372001ea41abe30f1a14216dda81c1103889 (patch)
tree2337d0d6a7127f5e44a30a06b97257dcbd50b05c /assets/scripts
parent2ca2d786af025689fb4f18800f219bedc97d1ba9 (diff)
downloadshowdownofthesticks-7620372001ea41abe30f1a14216dda81c1103889.tar.xz
showdownofthesticks-7620372001ea41abe30f1a14216dda81c1103889.zip
KO graphics and sound + background music and sound support!
Diffstat (limited to 'assets/scripts')
-rw-r--r--assets/scripts/local2P.lua88
-rw-r--r--assets/scripts/mainMenu.lua8
2 files changed, 72 insertions, 24 deletions
diff --git a/assets/scripts/local2P.lua b/assets/scripts/local2P.lua
index fe3f91e..84ea73d 100644
--- a/assets/scripts/local2P.lua
+++ b/assets/scripts/local2P.lua
@@ -4,6 +4,9 @@ backgrounds = require("assets.backgrounds.backgrounds-data")
sprite_height = 128
sprite_width = 64
+gamePaused = false
+isKO = false
+
groundTiles = {
{ x = 250, y = HEIGHT - 300, width = 200, height = 30 },
{ x = WIDTH - 250 - 200, y = HEIGHT - 300, width = 200, height = 30 },
@@ -27,6 +30,7 @@ function SafeInitCharacter(character, default_x, default_y)
character.combo_chain = 0
character.can_apply_knockback = false
character.facing = "right"
+ character.isDead = false
end
function Setup()
@@ -122,6 +126,7 @@ function IsTouchingWall(character, direction)
end
function HandleP1Input()
+ if player1Character.isDead then return end
if Input.isKeyPressedOnce("W") and player1Character.can_jump then
player1Character.y_velocity = player1Character.jump_strength * -1.0
player1Character.can_jump = false
@@ -150,6 +155,7 @@ function HandleP1Input()
end
function HandleP2Input()
+ if player2Character.isDead then return end
if Input.isKeyPressedOnce("UP") and player2Character.can_jump then
player2Character.y_velocity = player2Character.jump_strength * -1.0
player2Character.can_jump = false
@@ -240,12 +246,27 @@ function ApplyMinimalKnockback(attacker, target)
end
function KillPlayer(character)
- character.lives = character.lives - 1
- character.knockback_counter = 0
- character.combo_chain = 0
- if character.lives > 0 then
- Respawn(character)
- end
+ if gamePaused then return end
+ if character.isDead then return end
+ character.isDead = true
+
+ playSound("assets/sounds/K-O.wav")
+ gamePaused = true
+ isKO = true
+
+ Timer.after(2, function()
+ character.lives = character.lives - 1
+ character.knockback_counter = 0
+ character.combo_chain = 0
+ if character.lives > 0 then
+ Respawn(character)
+ character.isDead = false
+ else
+ -- Handle game over here
+ end
+ gamePaused = false
+ isKO = false
+ end)
end
function RegisterHit(attacker, target, damage)
@@ -310,6 +331,7 @@ function PerformPunch(attacker, target)
end
function ApplyPhysics(character)
+ if character.isDead then return end
character.y_velocity = character.y_velocity + gravity * deltaTime
character.y = character.y + character.y_velocity * deltaTime
character.x = character.x + character.x_velocity * deltaTime
@@ -330,38 +352,56 @@ function ApplyPhysics(character)
character.can_jump = false
end
- if character.y > HEIGHT + 50 then
+ if character.y > HEIGHT + 60 then
KillPlayer(character)
end
- if character.x < -50 then
+ if character.x < -60 then
KillPlayer(character)
end
- if character.x > WIDTH + 50 then
+ if character.x > WIDTH + 60 then
KillPlayer(character)
end
end
+function DrawKOGraphic()
+ queueRectForRender(0, 0, 1280, 720, 0, 0, 0, 150)
+
+ local fontFile = "assets/fonts/OpenSans-Bold.ttf"
+ local fontSize = 96
+ local text = "K.O."
+ local textWidth = getTextWidth(fontFile, fontSize, text)
+ local x = (1280 - textWidth) / 2
+ local y = 720 / 2 - fontSize / 2
+
+ queueTextForRender(text, fontFile, x, y, fontSize, 255, 0, 0, 255)
+ queueTextForRender(text, fontFile, x + 5, y + 5, fontSize, 255, 255, 0, 255)
+end
+
+
function Update()
- -- Apply physics
- ApplyPhysics(player1Character)
- ApplyPhysics(player2Character)
+ local maxDelta = 0.05 -- max 50 ms per frame
+ if deltaTime > maxDelta then
+ deltaTime = maxDelta
+ end
- -- Render characters
- queueTextureForRender(player1Character.current_sprite, math.ceil(player1Character.x), math.ceil(player1Character.y))
- queueTextureForRender(player2Character.current_sprite, math.ceil(player2Character.x), math.ceil(player2Character.y))
+ Timer.update(deltaTime)
- -- Environment
- DrawGroundTiles()
+ if not gamePaused then
+ ApplyPhysics(player1Character)
+ ApplyPhysics(player2Character)
- -- Input
- HandleP1Input()
- HandleP2Input()
+ HandleP1Input()
+ HandleP2Input()
+ end
- -- UI
+ queueTextureForRender(player1Character.current_sprite, math.ceil(player1Character.x), math.ceil(player1Character.y))
+ queueTextureForRender(player2Character.current_sprite, math.ceil(player2Character.x), math.ceil(player2Character.y))
+ DrawGroundTiles()
DrawUI()
- -- Timer
- Timer.update(deltaTime)
-end \ No newline at end of file
+ if isKO then
+ DrawKOGraphic()
+ end
+end
diff --git a/assets/scripts/mainMenu.lua b/assets/scripts/mainMenu.lua
index 4854775..ca290c6 100644
--- a/assets/scripts/mainMenu.lua
+++ b/assets/scripts/mainMenu.lua
@@ -33,6 +33,13 @@ function Timer.after(delay, callback)
})
end
+function Timer.delay(seconds)
+ local start = os.clock()
+ while (os.clock() - start) < seconds do
+ -- Busy wait, blocking here
+ end
+end
+
function Timer.clearAllTimers()
Timer.timers = {}
end
@@ -50,6 +57,7 @@ end
function Setup()
setBgImage("assets/backgrounds/city-background-1.png")
+ playSoundLoop("assets/sounds/Main Menu - Background Music (Knockout).wav")
end
function Local2PButton()