diff --git a/server/game-modes/battle-royale/game-loop.go b/server/game-modes/battle-royale/game-loop.go index fdfaf81..ede4b95 100644 --- a/server/game-modes/battle-royale/game-loop.go +++ b/server/game-modes/battle-royale/game-loop.go @@ -43,12 +43,14 @@ func RespondToInput(lobbyState *MatchState, messages []runtime.MatchData, logger // Check if the input is within the grace window if update.Tick < tick && tick-update.Tick <= GRACE_WINDOW_TICKS { - // Check the player's death state for all subsequent ticks + // Check the player's collision state for all subsequent ticks + playerSurvives := true for t := update.Tick; t < tick; t++ { - if lobbyState.presences[msg.GetSessionId()].stageState.CheckDeathState(t) == PLAYER_ALIVE { - // Set a flag to cancel death - lobbyState.presences[msg.GetSessionId()].stageState.cancelDeath = true - break + if lobbyState.presences[msg.GetSessionId()].stageState.CheckCollisionState(t) == PLAYER_DEAD { + playerSurvives = false + // Set a flag to cancel death if the player survives all ticks + if playerSurvives { + lobbyState.presences[msg.GetSessionId()].stageState.cancelDeath = true } } } diff --git a/server/game-modes/battle-royale/player-stage.go b/server/game-modes/battle-royale/player-stage.go index e0ed126..31f7197 100644 --- a/server/game-modes/battle-royale/player-stage.go +++ b/server/game-modes/battle-royale/player-stage.go @@ -64,29 +64,36 @@ func (s *PlayerStageState) DeleteBulletsBeyondKillBoundary(tick int64) { } -func (s *PlayerStageState) CheckDeathState(tick int64) int { - // If the player is dead. Decrement the death timer +func (s *PlayerStageState) UpdateDeathTimer() { + // If the player is dead, decrement the death timer if s.deathTimer >= 0 { s.deathTimer -= 1 } - if s.deathTimer == PLAYER_DEATH_RESET { // If the player's death timer has run out, reset them. 0 is a special deathTimer tick that indicates reset to the clients. + if s.deathTimer == PLAYER_DEATH_RESET { s.hitCol.UpdatePos(STAGE_WIDTH*0.5, STAGE_HEIGHT-STAGE_HEIGHT*0.1) s.grazeCol.UpdatePos(STAGE_WIDTH*0.5, STAGE_HEIGHT-STAGE_HEIGHT*0.1) s.updatePlayerPos = true - } else if s.deathTimer == PLAYER_ALIVE { // If the player is alive, check if the player collided with a bullet and kill them if so + } else if s.deathTimer == PLAYER_ALIVE { if slices.ContainsFunc(s.bullets, func(b *ffi.Bullet) bool { return b.CollidesWith(s.hitCol, tick) }) { s.deathTimer = PLAYER_DEATH_TIMER_MAX - } else if slices.ContainsFunc(s.bullets, func(b *ffi.Bullet) bool { // Otherwise, check the graze col and increment the graze and score - return b.CollidesWith(s.grazeCol, tick) - }) { - s.graze += GRAZE_ADDITION_MULTIPLIER } } +} - return s.deathTimer +func (s *PlayerStageState) CheckCollisionState(tick int64) int { + if slices.ContainsFunc(s.bullets, func(b *ffi.Bullet) bool { + return b.CollidesWith(s.hitCol, tick) + }) { + return PLAYER_DEAD + } else if slices.ContainsFunc(s.bullets, func(b *ffi.Bullet) bool { + return b.CollidesWith(s.grazeCol, tick) + }) { + s.graze += GRAZE_ADDITION_MULTIPLIER + } + return PLAYER_ALIVE } func (s *PlayerStageState) AddBullet(b *ffi.Bullet) {