aboutsummaryrefslogtreecommitdiff
path: root/assets/scripts/local2P.lua
diff options
context:
space:
mode:
Diffstat (limited to 'assets/scripts/local2P.lua')
-rw-r--r--assets/scripts/local2P.lua88
1 files changed, 64 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