Skip to content

Commit

Permalink
minor bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
GitPaulo committed Jan 10, 2025
1 parent f54cf33 commit 06eb9c6
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 36 deletions.
50 changes: 30 additions & 20 deletions src/entities/fighter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ function Fighter:handlePlayerInput(dt, other)
local startState = self.state
-- Check conditions
local isAttacking = self.isAttacking
local isDead = self.state == ANIM_STATE_DEATH
local isJumping = self.state == ANIM_STATE_JUMP
local isDashing = self.state == ANIM_STATE_DASHING
local isStunned = self.state == ANIM_STATE_STUNNED
Expand All @@ -316,7 +317,7 @@ function Fighter:handlePlayerInput(dt, other)
end

-- Block (new) input in blocked states
if isDashing or isHit or isStunned or isGrabbing or self.isClashing or self.knockbackActive or self.isStunned or self.isAttacking then
if isDead or isDashing or isHit or isStunned or isGrabbing or self.isClashing or self.knockbackActive or self.isStunned or self.isAttacking then
return
end

Expand Down Expand Up @@ -947,36 +948,41 @@ end

function Fighter:takeDamage(damage)
self.health = self.health - damage

-- Check if the fighter is dead
if self.health <= 0 then
-- Dead
self.health = 0
-- Helps ensure the death animation is played only once
self.health = 0 -- Clamp health to 0

-- Handle death state
if self.state ~= ANIM_STATE_DEATH then
self:setAnimState(ANIM_STATE_DEATH)

-- Play death animation
self.currentAnimation = self.animations.death
self.currentAnimation:gotoFrame(1)

-- Play death sound
-- Play death animation and sound
if self.animations.death then
self.currentAnimation = self.animations.death
self.currentAnimation:gotoFrame(1)
end
SoundManager:playSound(self.sounds.death)

-- Set the start time for the death animation
-- Mark the start of the death animation
self.deathAnimationStartTime = love.timer.getTime()
end
else
self:setAnimState(ANIM_STATE_HIT)
return -- Exit after handling death
end

self.isBlockingDamage = false -- Reset blocking flag
self:setAnimState(ANIM_STATE_HIT)

-- Play hit animation
-- Play hit animation and sound
if self.animations.hit then
self.currentAnimation = self.animations.hit
self.currentAnimation:gotoFrame(1)
end
SoundManager:playSound(self.sounds.hit)

-- Play hit sound effect if available
SoundManager:playSound(self.sounds.hit)

-- Set state back to idle after hit animation duration
local hitDuration = self.currentAnimation.totalDuration
self.hitEndTime = love.timer.getTime() + hitDuration
-- Set the duration for the hit animation
if self.currentAnimation and self.currentAnimation.totalDuration then
self.hitEndTime = love.timer.getTime() + self.currentAnimation.totalDuration
end
end

Expand All @@ -997,7 +1003,7 @@ function Fighter:applyKnockback(other)
self.lostClash = false -- Reset lost clash flag

if not self.knockbackApplied and not other.knockbackApplied then
SoundManager:playSound(self.sounds.clash, {clone = true})
SoundManager:playSound(self.sounds.clash, {preventOverlap = true})
end
end

Expand Down Expand Up @@ -1093,6 +1099,10 @@ function Fighter:drawSprite()
local posX = self.x + offsetX + (self.scale.ox * self.direction)
local posY = self.y + offsetY + self.scale.oy

if self.isBlockingDamage then
love.graphics.setColor(0, .1, .7, 1) -- Blue color for the outline
end

-- Flash white if stunned
if self.state == ANIM_STATE_STUNNED then
-- Alternate between full white and normal color for flashing effect
Expand Down
51 changes: 35 additions & 16 deletions src/states/game.lua
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function Game:enter(params)
self.gameOverFont = love.graphics.newFont(32)
self.winnerFont = love.graphics.newFont(20)
self.instructionsFont = love.graphics.newFont(16)
self.eventFont = love.graphics.newFont(20)
self.eventFont = love.graphics.newFont(19)
end

function Game:exit()
Expand Down Expand Up @@ -106,15 +106,6 @@ function Game:update(dt)
-- Check for game over - leave this block last
local hasFighterDied = self.fighter1.state == 'death' or self.fighter2.state == 'death'
if hasFighterDied then
-- Check if death animation is still playing
if self.fighter1.state == 'death' then
self.fighter1:checkDeathAnimationFinished()
end
if self.fighter2.state == 'death' then
self.fighter2:checkDeathAnimationFinished()
end

-- Only set game over when death animations are finished
if self.fighter1.deathAnimationFinished or self.fighter2.deathAnimationFinished then
self.gameOver = true
if self.fighter1.deathAnimationFinished and self.fighter2.deathAnimationFinished then
Expand Down Expand Up @@ -171,32 +162,60 @@ end
function Game:drawBlock()
if self.fighter1.isBlockingDamage then
love.graphics.setFont(self.eventFont)
love.graphics.setColor(1, 1, 0, 1)

-- Draw shadow
love.graphics.setColor(0, 0, 0, 0.5)
love.graphics.print('Blocked', self.fighter1.x - 17, self.fighter1.y - 23)

-- Draw main text
love.graphics.setColor(.3, .3, 1, 1) -- Blue
love.graphics.print('Blocked', self.fighter1.x - 18, self.fighter1.y - 22)

love.graphics.setColor(1, 1, 1, 1) -- Reset color
end

if self.fighter2.isBlockingDamage then
love.graphics.setFont(self.eventFont)
love.graphics.setColor(1, 1, 0, 1)

-- Draw shadow
love.graphics.setColor(0, 0, 0, 0.5)
love.graphics.print('Blocked', self.fighter2.x - 17, self.fighter2.y - 23)

-- Draw main text
love.graphics.setColor(.3, .3, 1, 1)
love.graphics.print('Blocked', self.fighter2.x - 18, self.fighter2.y - 22)
love.graphics.setColor(1, 1, 1, 1) -- Reset color

love.graphics.setColor(1, 1, 1, 1)
end
end

function Game:drawStunText()
if self.fighter1.state == ANIM_STATE_STUNNED then
love.graphics.setFont(self.eventFont)
love.graphics.setColor(1, 0, 0, 1)

-- Draw shadow
love.graphics.setColor(0, 0, 0, 0.5)
love.graphics.print('Stunned', self.fighter1.x - 17, self.fighter1.y - 22)

-- Draw main text
love.graphics.setColor(1, 0, 0, 1) -- Red
love.graphics.print('Stunned', self.fighter1.x - 18, self.fighter1.y - 22)
love.graphics.setColor(1, 1, 1, 1) -- Reset color

love.graphics.setColor(1, 1, 1, 1)
end

if self.fighter2.state == ANIM_STATE_STUNNED then
love.graphics.setFont(self.eventFont)

-- Draw shadow
love.graphics.setColor(0, 0, 0, 0.5)
love.graphics.print('Stunned', self.fighter2.x - 17, self.fighter2.y - 23)

-- Draw main text
love.graphics.setColor(1, 0, 0, 1)
love.graphics.print('Stunned', self.fighter2.x - 18, self.fighter2.y - 22)
love.graphics.setColor(1, 1, 1, 1) -- Reset color

love.graphics.setColor(1, 1, 1, 1)
end
end

Expand Down

0 comments on commit 06eb9c6

Please sign in to comment.