aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.DS_Storebin10244 -> 10244 bytes
-rw-r--r--assets/backgrounds/backgrounds-data.lua1
-rw-r--r--assets/backgrounds/city-background-6.pngbin282392 -> 0 bytes
-rw-r--r--assets/characters/.DS_Storebin10244 -> 10244 bytes
-rw-r--r--assets/characters/Cobalt Phantom/.DS_Storebin6148 -> 6148 bytes
-rw-r--r--assets/characters/Cobalt Phantom/sprites/.DS_Storebin0 -> 6148 bytes
-rw-r--r--assets/characters/Cobalt Phantom/sprites/punch_left.pngbin0 -> 1146 bytes
-rw-r--r--assets/characters/Cobalt Phantom/sprites/punch_right.pngbin0 -> 854 bytes
-rw-r--r--assets/characters/Crimson Reaper/.DS_Storebin6148 -> 6148 bytes
-rw-r--r--assets/characters/Crimson Reaper/sprites/.DS_Storebin6148 -> 6148 bytes
-rw-r--r--assets/characters/Crimson Reaper/sprites/punch_left.pngbin0 -> 1043 bytes
-rw-r--r--assets/characters/Crimson Reaper/sprites/punch_right.pngbin0 -> 785 bytes
-rw-r--r--assets/characters/Emerald Venom/.DS_Storebin6148 -> 6148 bytes
-rw-r--r--assets/characters/Emerald Venom/sprites/.DS_Storebin6148 -> 6148 bytes
-rw-r--r--assets/characters/Emerald Venom/sprites/punch_left.pngbin0 -> 1041 bytes
-rw-r--r--assets/characters/Emerald Venom/sprites/punch_right.pngbin0 -> 784 bytes
-rw-r--r--assets/characters/Golden Radiance/.DS_Storebin6148 -> 6148 bytes
-rw-r--r--assets/characters/Golden Radiance/sprites/.DS_Storebin6148 -> 6148 bytes
-rw-r--r--assets/characters/Golden Radiance/sprites/punch_left.pngbin0 -> 1038 bytes
-rw-r--r--assets/characters/Golden Radiance/sprites/punch_right.pngbin0 -> 781 bytes
-rw-r--r--assets/characters/characters-data.lua12
-rw-r--r--assets/scripts/local2P.lua282
-rw-r--r--assets/scripts/mainMenu.lua26
-rw-r--r--src/main.cpp14
24 files changed, 282 insertions, 53 deletions
diff --git a/.DS_Store b/.DS_Store
index 9f33543..b66b013 100644
--- a/.DS_Store
+++ b/.DS_Store
Binary files differ
diff --git a/assets/backgrounds/backgrounds-data.lua b/assets/backgrounds/backgrounds-data.lua
index 087ddf9..8fbaecd 100644
--- a/assets/backgrounds/backgrounds-data.lua
+++ b/assets/backgrounds/backgrounds-data.lua
@@ -4,7 +4,6 @@ return {
"assets/backgrounds/city-background-3.png",
"assets/backgrounds/city-background-4.png",
"assets/backgrounds/city-background-5.png",
- "assets/backgrounds/city-background-6.png",
"assets/backgrounds/city-background-7.png",
"assets/backgrounds/city-background-8.png",
} \ No newline at end of file
diff --git a/assets/backgrounds/city-background-6.png b/assets/backgrounds/city-background-6.png
deleted file mode 100644
index 2947551..0000000
--- a/assets/backgrounds/city-background-6.png
+++ /dev/null
Binary files differ
diff --git a/assets/characters/.DS_Store b/assets/characters/.DS_Store
index a4ae90d..c7a0c24 100644
--- a/assets/characters/.DS_Store
+++ b/assets/characters/.DS_Store
Binary files differ
diff --git a/assets/characters/Cobalt Phantom/.DS_Store b/assets/characters/Cobalt Phantom/.DS_Store
index 9955791..980ecf9 100644
--- a/assets/characters/Cobalt Phantom/.DS_Store
+++ b/assets/characters/Cobalt Phantom/.DS_Store
Binary files differ
diff --git a/assets/characters/Cobalt Phantom/sprites/.DS_Store b/assets/characters/Cobalt Phantom/sprites/.DS_Store
new file mode 100644
index 0000000..5c17d73
--- /dev/null
+++ b/assets/characters/Cobalt Phantom/sprites/.DS_Store
Binary files differ
diff --git a/assets/characters/Cobalt Phantom/sprites/punch_left.png b/assets/characters/Cobalt Phantom/sprites/punch_left.png
new file mode 100644
index 0000000..9b94b65
--- /dev/null
+++ b/assets/characters/Cobalt Phantom/sprites/punch_left.png
Binary files differ
diff --git a/assets/characters/Cobalt Phantom/sprites/punch_right.png b/assets/characters/Cobalt Phantom/sprites/punch_right.png
new file mode 100644
index 0000000..32c641c
--- /dev/null
+++ b/assets/characters/Cobalt Phantom/sprites/punch_right.png
Binary files differ
diff --git a/assets/characters/Crimson Reaper/.DS_Store b/assets/characters/Crimson Reaper/.DS_Store
index 28dde00..bcad01e 100644
--- a/assets/characters/Crimson Reaper/.DS_Store
+++ b/assets/characters/Crimson Reaper/.DS_Store
Binary files differ
diff --git a/assets/characters/Crimson Reaper/sprites/.DS_Store b/assets/characters/Crimson Reaper/sprites/.DS_Store
index 0b5b5e9..a4205a2 100644
--- a/assets/characters/Crimson Reaper/sprites/.DS_Store
+++ b/assets/characters/Crimson Reaper/sprites/.DS_Store
Binary files differ
diff --git a/assets/characters/Crimson Reaper/sprites/punch_left.png b/assets/characters/Crimson Reaper/sprites/punch_left.png
new file mode 100644
index 0000000..9bcfa1d
--- /dev/null
+++ b/assets/characters/Crimson Reaper/sprites/punch_left.png
Binary files differ
diff --git a/assets/characters/Crimson Reaper/sprites/punch_right.png b/assets/characters/Crimson Reaper/sprites/punch_right.png
new file mode 100644
index 0000000..7e965f6
--- /dev/null
+++ b/assets/characters/Crimson Reaper/sprites/punch_right.png
Binary files differ
diff --git a/assets/characters/Emerald Venom/.DS_Store b/assets/characters/Emerald Venom/.DS_Store
index 472db25..8be9c68 100644
--- a/assets/characters/Emerald Venom/.DS_Store
+++ b/assets/characters/Emerald Venom/.DS_Store
Binary files differ
diff --git a/assets/characters/Emerald Venom/sprites/.DS_Store b/assets/characters/Emerald Venom/sprites/.DS_Store
index 0b5b5e9..5c17d73 100644
--- a/assets/characters/Emerald Venom/sprites/.DS_Store
+++ b/assets/characters/Emerald Venom/sprites/.DS_Store
Binary files differ
diff --git a/assets/characters/Emerald Venom/sprites/punch_left.png b/assets/characters/Emerald Venom/sprites/punch_left.png
new file mode 100644
index 0000000..db65c88
--- /dev/null
+++ b/assets/characters/Emerald Venom/sprites/punch_left.png
Binary files differ
diff --git a/assets/characters/Emerald Venom/sprites/punch_right.png b/assets/characters/Emerald Venom/sprites/punch_right.png
new file mode 100644
index 0000000..cbe1c9d
--- /dev/null
+++ b/assets/characters/Emerald Venom/sprites/punch_right.png
Binary files differ
diff --git a/assets/characters/Golden Radiance/.DS_Store b/assets/characters/Golden Radiance/.DS_Store
index 7f88958..086654b 100644
--- a/assets/characters/Golden Radiance/.DS_Store
+++ b/assets/characters/Golden Radiance/.DS_Store
Binary files differ
diff --git a/assets/characters/Golden Radiance/sprites/.DS_Store b/assets/characters/Golden Radiance/sprites/.DS_Store
index 0b5b5e9..5c17d73 100644
--- a/assets/characters/Golden Radiance/sprites/.DS_Store
+++ b/assets/characters/Golden Radiance/sprites/.DS_Store
Binary files differ
diff --git a/assets/characters/Golden Radiance/sprites/punch_left.png b/assets/characters/Golden Radiance/sprites/punch_left.png
new file mode 100644
index 0000000..871da69
--- /dev/null
+++ b/assets/characters/Golden Radiance/sprites/punch_left.png
Binary files differ
diff --git a/assets/characters/Golden Radiance/sprites/punch_right.png b/assets/characters/Golden Radiance/sprites/punch_right.png
new file mode 100644
index 0000000..492eebd
--- /dev/null
+++ b/assets/characters/Golden Radiance/sprites/punch_right.png
Binary files differ
diff --git a/assets/characters/characters-data.lua b/assets/characters/characters-data.lua
index a90849e..8b8ca4b 100644
--- a/assets/characters/characters-data.lua
+++ b/assets/characters/characters-data.lua
@@ -4,31 +4,35 @@ return {
lives = 3,
speed = 5,
moves = {"teleportation", "quick_dashes", "smoke_screens", "strikes_from_the_shadows"},
+ hit_strength = 15,
asset_dir = "assets/characters/Cobalt Phantom",
- jump_strength = 19.4,
+ jump_strength = 23.65,
},
{
name = "Emerald Venom",
lives = 4,
speed = 4,
moves = {"snake_whip", "venom_bite", "poison_of_the_past"},
+ hit_strength = 12,
asset_dir = "assets/characters/Emerald Venom",
- jump_strength = 23.4,
+ jump_strength = 25.4,
},
{
name = "Golden Radiance",
lives = 5,
speed = 8,
moves = {"solar_boom", "flashbang", "flare_frenzy"},
+ hit_strength = 13,
asset_dir = "assets/characters/Golden Radiance",
- jump_strength = 20.2,
+ jump_strength = 23.1,
},
{
name = "Crimson Reaper",
lives = 2,
speed = 2,
moves = {"soul_slash", "deaths_reach", "phantom_step", "grim_harvest"},
+ hit_strength = 17,
asset_dir = "assets/characters/Crimson Reaper",
- jump_strength = 28.4,
+ jump_strength = 27.7,
}
}
diff --git a/assets/scripts/local2P.lua b/assets/scripts/local2P.lua
index 7fd2efa..61262b2 100644
--- a/assets/scripts/local2P.lua
+++ b/assets/scripts/local2P.lua
@@ -1,18 +1,25 @@
---@diagnostic disable: undefined-global
backgrounds = require("assets.backgrounds.backgrounds-data")
+sprite_height = 128
+sprite_width = 64
+
+deltaTimeMultiplier = 60
groundTiles = {
- { x = 250, y = HEIGHT - 300, width = 200, height = 30 },
- { x = WIDTH - 250 - 200, y = HEIGHT - 300, width = 200, height = 30 },
+ { x = 250, y = HEIGHT - 300, width = 200, height = 30 },
+ { x = WIDTH - 250 - 200, y = HEIGHT - 300, width = 200, height = 30 },
+ { x = 0, y = HEIGHT - 100, width = WIDTH, height = 100 }
}
function SafeInitCharacter(character, default_x, default_y)
- character.x = character.x or default_x
- character.y = character.y or default_y
- character.y_velocity = character.y_velocity or 1
+ character.x = default_x
+ character.x_velocity = 1
+ character.y = default_y
+ character.y_velocity = 1
character.current_sprite = character.asset_dir .. "/sprites/idle.png"
+ character.default_sprite = character.current_sprite
character.can_jump = false
character.knockback_counter = 0
character.combo_chain = 0
@@ -36,32 +43,88 @@ end
function IsOnGround(character)
for _, tile in ipairs(groundTiles) do
- local characterFeetY = character.y + 128
+ local characterFeetY = character.y + sprite_height
- local isWithinX = character.x + 64 > tile.x and character.x < tile.x + tile.width
+ local isWithinX = character.x + sprite_width > tile.x and character.x < tile.x + tile.width
local isTouchingY = characterFeetY >= tile.y and characterFeetY <= tile.y + tile.height
+ local isFalling = character.y_velocity >= 0
+
+ if isWithinX and isTouchingY and isFalling then
+ character.y = tile.y - sprite_height
+ return true
+ end
+ end
+ return false
+end
+
+function IsHittingCeiling(character)
+ for _, tile in ipairs(groundTiles) do
+ local characterHeadY = character.y
+ local isWithinX = character.x + sprite_width > tile.x and character.x < tile.x + tile.width
+ local isTouchingY = characterHeadY <= tile.y + tile.height and characterHeadY >= tile.y
if isWithinX and isTouchingY then
- character.y = tile.y - 128
+ character.y = tile.y + tile.height
+ character.y_velocity = 0
return true
end
end
return false
end
+function IsTouchingWall(character, direction)
+ for _, tile in ipairs(groundTiles) do
+ local charBottom = character.y + sprite_height
+ local charTop = character.y
+ local tileBottom = tile.y + tile.height
+ local tileTop = tile.y
+
+ local verticalOverlap = charBottom > tileTop and charTop < tileBottom
+
+ if direction == "left" then
+ local nextX = character.x - character.speed
+ local willCollide = nextX < tile.x + tile.width and character.x >= tile.x + tile.width
+
+ if willCollide and verticalOverlap then
+ character.x = tile.x + tile.width
+ return true
+ end
+ elseif direction == "right" then
+ local nextX = character.x + sprite_width + character.speed
+ local willCollide = nextX > tile.x and character.x + sprite_width <= tile.x
+
+ if willCollide and verticalOverlap then
+ character.x = tile.x - sprite_width
+ return true
+ end
+ end
+ end
+ return false
+end
+
function HandleP1Input()
if Input.isKeyPressedOnce("W") and player1Character.can_jump then
- player1Character.y_velocity = player1Character.jump_strength * -1.0
- player1Character.can_jump = false
+ player1Character.y_velocity = player1Character.jump_strength * -1.0
+ player1Character.can_jump = false
end
+
if Input.isKeyDown("D") then
- player1Character.x = player1Character.x + player1Character.speed
+ if not IsTouchingWall(player1Character, "right") then
+ player1Character.x_velocity = player1Character.speed
+ else
+ player1Character.x_velocity = 0
+ end
end
if Input.isKeyDown("A") then
- player1Character.x = player1Character.x - player1Character.speed
+ if not IsTouchingWall(player1Character, "left") then
+ player1Character.x_velocity = -player1Character.speed
+ else
+ player1Character.x_velocity = 0
+ end
end
+
if Input.isKeyPressedOnce("F") then
-
+ PerformPunch(player1Character, player2Character)
end
end
@@ -70,46 +133,28 @@ function HandleP2Input()
player2Character.y_velocity = player2Character.jump_strength * -1.0
player2Character.can_jump = false
end
+
if Input.isKeyDown("RIGHT") then
- player2Character.x = player2Character.x + player2Character.speed
+ if not IsTouchingWall(player2Character, "right") then
+ player2Character.x_velocity = player2Character.speed
+ else
+ player2Character.x_velocity = 0
+ end
end
if Input.isKeyDown("LEFT") then
- player2Character.x = player2Character.x - player2Character.speed
- end
-end
-
-function Update()
- -- P1 physics
- player1Character.y_velocity = player1Character.y_velocity + gravity
- player1Character.y = player1Character.y + player1Character.y_velocity
-
- if IsOnGround(player1Character) then
- player1Character.y_velocity = 0
- player1Character.can_jump = true
+ if not IsTouchingWall(player2Character, "left") then
+ player2Character.x_velocity = -player2Character.speed
+ else
+ player2Character.x_velocity = 0
+ end
end
- -- P2 physics
- player2Character.y_velocity = player2Character.y_velocity + gravity
- player2Character.y = player2Character.y + player2Character.y_velocity
-
- if IsOnGround(player2Character) then
- player2Character.y_velocity = 0
- player2Character.can_jump = true
+ if Input.isKeyPressedOnce("Right Alt") or Input.isKeyPressedOnce("Right Option") then
+ PerformPunch(player2Character, player1Character)
end
+end
- -- Render
- queueTextureForRender(
- player1Character.current_sprite,
- math.floor(player1Character.x),
- math.floor(player1Character.y)
- )
-
- queueTextureForRender(
- player2Character.current_sprite,
- math.floor(player2Character.x),
- math.floor(player2Character.y)
- )
-
+function DrawUI()
local fontFile = "assets/fonts/OpenSans-Bold.ttf"
local fontSize = 24
local text = player1Character.name
@@ -144,10 +189,155 @@ function Update()
local x = WIDTH - textWidth - 40
queueTextForRender(text, fontFile, x, y, fontSize, 0, 0, 0, 255)
+end
+
+function Respawn(character)
+ SafeInitCharacter(character, 250, 150)
+end
+
+function ApplyKnockback(attacker, target)
+ local knockbackMultiplierX = 0.47
+ local knockbackMultiplierY = 0.01
+ target.y_velocity = -10 - (target.knockback_counter * knockbackMultiplierY)
+
+ local direction = 1
+ if target.x < attacker.x then
+ direction = -1
+ end
+ target.x_velocity = target.knockback_counter * knockbackMultiplierX * direction
+ -- target.x = target.x + direction * (target.knockback_counter * 0.7)
+end
+
+function ApplyMinimalKnockback(attacker, target)
+ local knockbackMultiplierX = 0.47
+ local knockbackMultiplierY = 0.01
+ local knockbackCountMinimal = 5
+ target.y_velocity = -10 - (knockbackCountMinimal * knockbackMultiplierY)
+
+ local direction = 1
+ if target.x < attacker.x then
+ direction = -1
+ end
+
+ target.x_velocity = knockbackCountMinimal * knockbackMultiplierX * direction
+ -- target.x = target.x + direction * (target.knockback_counter * 0.7)
+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
+end
+
+function RegisterHit(attacker, target, damage)
+ target.knockback_counter = target.knockback_counter + damage
+ attacker.combo_chain = attacker.combo_chain + 1
+
+ if attacker.combo_chain >= 4 then
+ ApplyKnockback(attacker, target)
+ attacker.combo_chain = 0
+ else
+ ApplyMinimalKnockback(attacker, target)
+ end
+
+ if target.knockback_counter >= 1000 then
+ KillPlayer(target)
+ end
+end
+
+function PerformPunch(attacker, target)
+ local punch_range = 27
+ local punch_height = 80
+
+ -- Determine direction of target relative to attacker
+ local punch_direction = (target.x > attacker.x) and "right" or "left"
+
+ -- Set punch sprite
+ attacker.current_sprite = attacker.asset_dir .. "/sprites/punch_" .. punch_direction .. ".png"
+
+ -- Reset sprite after a short delay (e.g., 0.15s)
+ Timer.clearAllTimers()
+ Timer.after(0.15, function()
+ attacker.current_sprite = attacker.default_sprite
+ end)
+
+ -- Define hitbox based on punch direction
+ local hitbox = {
+ x = attacker.x + (punch_direction == "right" and sprite_width or -punch_range),
+ y = attacker.y + (sprite_height / 2) - (punch_height / 2),
+ width = punch_range,
+ height = punch_height
+ }
+
+ local targetHitbox = {
+ x = target.x,
+ y = target.y,
+ width = sprite_width,
+ height = sprite_height
+ }
+
+ local function isColliding(a, b)
+ return a.x < b.x + b.width and
+ a.x + a.width > b.x and
+ a.y < b.y + b.height and
+ a.y + a.height > b.y
+ end
+
+ if isColliding(hitbox, targetHitbox) then
+ RegisterHit(attacker, target, attacker.hit_strength)
+ end
+end
+
+function ApplyPhysics(character)
+ local deltaTimeMultiplier = 60 -- Target 60FPS
+ character.y_velocity = character.y_velocity + gravity * deltaTime * deltaTimeMultiplier
+ character.y = character.y + character.y_velocity * deltaTime * deltaTimeMultiplier
+ character.x = character.x + character.x_velocity * deltaTime * deltaTimeMultiplier
+ character.x_velocity = character.x_velocity * 0.99
+
+ if character.y_velocity > 0 then
+ -- Falling
+ if IsOnGround(character) then
+ character.y_velocity = 0
+ character.can_jump = true
+ end
+ elseif character.y_velocity < 0 then
+ -- Going upward
+ IsHittingCeiling(character)
+ end
+
+ if not IsOnGround(character) then
+ character.can_jump = false
+ end
+
+ if character.y > HEIGHT + 50 then
+ KillPlayer(character)
+ end
+end
+
+function Update()
+ -- Apply physics
+ ApplyPhysics(player1Character)
+ ApplyPhysics(player2Character)
+
+ -- Render characters
+ queueTextureForRender(player1Character.current_sprite, math.floor(player1Character.x), math.floor(player1Character.y))
+ queueTextureForRender(player2Character.current_sprite, math.floor(player2Character.x), math.floor(player2Character.y))
+
+ -- Environment
DrawGroundTiles()
-- Input
HandleP1Input()
HandleP2Input()
+
+ -- UI
+ DrawUI()
+
+ -- Timer
+ Timer.update(deltaTime)
end
diff --git a/assets/scripts/mainMenu.lua b/assets/scripts/mainMenu.lua
index 05272af..4854775 100644
--- a/assets/scripts/mainMenu.lua
+++ b/assets/scripts/mainMenu.lua
@@ -22,6 +22,32 @@ Input = {
end
}
+Timer = {
+ timers = {}
+}
+
+function Timer.after(delay, callback)
+ table.insert(Timer.timers, {
+ time = delay,
+ action = callback
+ })
+end
+
+function Timer.clearAllTimers()
+ Timer.timers = {}
+end
+
+function Timer.update(dt)
+ for i = #Timer.timers, 1, -1 do
+ local t = Timer.timers[i]
+ t.time = t.time - dt
+ if t.time <= 0 then
+ t.action()
+ table.remove(Timer.timers, i)
+ end
+ end
+end
+
function Setup()
setBgImage("assets/backgrounds/city-background-1.png")
end
diff --git a/src/main.cpp b/src/main.cpp
index b2a48d9..24a3147 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -357,7 +357,7 @@ int main()
lua_setglobal(L, "HEIGHT");
SDL_Init(SDL_INIT_EVERYTHING);
- SDL_CreateWindowAndRenderer(WIDTH, HEIGHT, 0, &window, &renderer);
+ SDL_CreateWindowAndRenderer(WIDTH, HEIGHT, SDL_RENDERER_PRESENTVSYNC, &window, &renderer);
SDL_SetWindowTitle(window, "Showdown of the Sticks");
SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND);
SDL_RenderSetLogicalSize(renderer, WIDTH, HEIGHT);
@@ -388,6 +388,9 @@ int main()
call_lua_function(L, "Setup");
+ Uint32 lastFrameTime = SDL_GetTicks();
+ float deltaTime = 0.0f;
+
while (running)
{
push_keys_to_lua(L, keys);
@@ -395,6 +398,13 @@ int main()
call_lua_function(L, "Update");
+ Uint32 currentFrameTime = SDL_GetTicks();
+ deltaTime = (currentFrameTime - lastFrameTime) / 1000.0f;
+ lastFrameTime = currentFrameTime;
+
+ lua_pushnumber(L, deltaTime);
+ lua_setglobal(L, "deltaTime");
+
while (SDL_PollEvent(&event))
{
if (event.type == SDL_QUIT)
@@ -538,7 +548,7 @@ int main()
textList.clear();
SDL_RenderPresent(renderer);
- SDL_Delay(10);
+ SDL_Delay(1);
}
lua_close(L);