diff options
Diffstat (limited to 'assets/scripts/local2P.lua')
| -rw-r--r-- | assets/scripts/local2P.lua | 79 |
1 files changed, 53 insertions, 26 deletions
diff --git a/assets/scripts/local2P.lua b/assets/scripts/local2P.lua index 61262b2..7413406 100644 --- a/assets/scripts/local2P.lua +++ b/assets/scripts/local2P.lua @@ -4,14 +4,16 @@ 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 = 0, y = HEIGHT - 100, width = WIDTH, height = 100 } } +knockbackMultiplierX = 35.4 +knockbackMultiplierY = 8.73 +minimalKnockbackMultiplierY = 40.3 + function SafeInitCharacter(character, default_x, default_y) character.x = default_x @@ -24,6 +26,7 @@ function SafeInitCharacter(character, default_x, default_y) character.knockback_counter = 0 character.combo_chain = 0 character.can_apply_knockback = false + character.facing = "right" end function Setup() @@ -33,7 +36,7 @@ function Setup() SafeInitCharacter(player2Character, WIDTH - 250 - (250 / 2), 150) end -gravity = 1.2 -- POSITIVE gravity +gravity = 1570 function DrawGroundTiles() for _, tile in ipairs(groundTiles) do @@ -79,7 +82,22 @@ function IsTouchingWall(character, direction) local tileBottom = tile.y + tile.height local tileTop = tile.y - local verticalOverlap = charBottom > tileTop and charTop < tileBottom + local verticalOverlapAmount = math.min(charBottom, tileBottom) - math.max(charTop, tileTop) + local verticalOverlap = verticalOverlapAmount > 12 + + -- New: Check if tile is within a certain horizontal range before collision test + local horizontalDistance + if direction == "left" then + horizontalDistance = character.x - (tile.x + tile.width) + if horizontalDistance > 15 then -- Only check if tile is within 15 pixels to the left + goto continue + end + elseif direction == "right" then + horizontalDistance = tile.x - (character.x + sprite_width) + if horizontalDistance > 15 then -- Only check if tile is within 15 pixels to the right + goto continue + end + end if direction == "left" then local nextX = character.x - character.speed @@ -98,6 +116,7 @@ function IsTouchingWall(character, direction) return true end end + ::continue:: end return false end @@ -111,6 +130,7 @@ function HandleP1Input() if Input.isKeyDown("D") then if not IsTouchingWall(player1Character, "right") then player1Character.x_velocity = player1Character.speed + player1Character.facing = "right" else player1Character.x_velocity = 0 end @@ -118,6 +138,7 @@ function HandleP1Input() if Input.isKeyDown("A") then if not IsTouchingWall(player1Character, "left") then player1Character.x_velocity = -player1Character.speed + player1Character.facing = "left" else player1Character.x_velocity = 0 end @@ -137,6 +158,7 @@ function HandleP2Input() if Input.isKeyDown("RIGHT") then if not IsTouchingWall(player2Character, "right") then player2Character.x_velocity = player2Character.speed + player2Character.facing = "right" else player2Character.x_velocity = 0 end @@ -144,12 +166,13 @@ function HandleP2Input() if Input.isKeyDown("LEFT") then if not IsTouchingWall(player2Character, "left") then player2Character.x_velocity = -player2Character.speed + player2Character.facing = "left" else player2Character.x_velocity = 0 end end - if Input.isKeyPressedOnce("Right Alt") or Input.isKeyPressedOnce("Right Option") then + if Input.isKeyPressedOnce("L") then PerformPunch(player2Character, player1Character) end end @@ -196,27 +219,19 @@ function Respawn(character) 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 + local direction = attacker.facing == "left" and -1 or 1 + local scaledY = -10 - (target.knockback_counter * knockbackMultiplierY) + target.y_velocity = math.max(-950, scaledY) -- clamp Y knockback 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) + target.y_velocity = -10 - (knockbackCountMinimal * minimalKnockbackMultiplierY) local direction = 1 - if target.x < attacker.x then + if attacker.facing == "left" then direction = -1 end @@ -254,7 +269,7 @@ function PerformPunch(attacker, target) local punch_height = 80 -- Determine direction of target relative to attacker - local punch_direction = (target.x > attacker.x) and "right" or "left" + local punch_direction = attacker.facing -- Set punch sprite attacker.current_sprite = attacker.asset_dir .. "/sprites/punch_" .. punch_direction .. ".png" @@ -288,16 +303,20 @@ function PerformPunch(attacker, target) end if isColliding(hitbox, targetHitbox) then - RegisterHit(attacker, target, attacker.hit_strength) + Timer.after(0.05, function () + RegisterHit(attacker, target, attacker.hit_strength) + end) 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 + character.y_velocity = character.y_velocity + gravity * deltaTime + character.y = character.y + character.y_velocity * deltaTime + character.x = character.x + character.x_velocity * deltaTime + character.x_velocity = character.x_velocity * 0.88 + + print(character.name, character.x_velocity) + print(character.name, character.y_velocity) if character.y_velocity > 0 then -- Falling @@ -317,6 +336,14 @@ function ApplyPhysics(character) if character.y > HEIGHT + 50 then KillPlayer(character) end + + if character.x < -50 then + KillPlayer(character) + end + + if character.x > WIDTH + 50 then + KillPlayer(character) + end end function Update() @@ -340,4 +367,4 @@ function Update() -- Timer Timer.update(deltaTime) -end +end
\ No newline at end of file |
