Adjusted hit effect timing.

This commit is contained in:
lightheel 2025-08-06 18:53:23 -04:00
parent 371a850d45
commit 26fc0ced56
2 changed files with 40 additions and 11 deletions

View File

@ -38,6 +38,9 @@ fun HitEffectOverlay(
if (isVisible) { if (isVisible) {
println("DEBUG: Starting hit effect animation") println("DEBUG: Starting hit effect animation")
// Add delay before starting hit effect animation
delay(400) // Increased from 200ms to 400ms delay before hit effect appears
// Randomly choose between hit_01, hit_02, and hit_02_white // Randomly choose between hit_01, hit_02, and hit_02_white
val hitSpriteName = when (kotlin.random.Random.nextInt(3)) { val hitSpriteName = when (kotlin.random.Random.nextInt(3)) {
0 -> "hit_01" 0 -> "hit_01"

View File

@ -167,12 +167,18 @@ fun BattleScreen(
var showPlayerHitEffect by remember { mutableStateOf(false) } var showPlayerHitEffect by remember { mutableStateOf(false) }
var showOpponentHitEffect by remember { mutableStateOf(false) } var showOpponentHitEffect by remember { mutableStateOf(false) }
// Attack sprite visibility state
var hidePlayerAttackSprite by remember { mutableStateOf(false) }
var hideEnemyAttackSprite by remember { mutableStateOf(false) }
// Reset hit effect states when attack phase returns to idle // Reset hit effect states when attack phase returns to idle
LaunchedEffect(battleSystem.attackPhase) { LaunchedEffect(battleSystem.attackPhase) {
if (battleSystem.attackPhase == 0) { if (battleSystem.attackPhase == 0) {
// Reset hit effect states when returning to idle // Reset hit effect states when returning to idle
showPlayerHitEffect = false showPlayerHitEffect = false
showOpponentHitEffect = false showOpponentHitEffect = false
hidePlayerAttackSprite = false
hideEnemyAttackSprite = false
println("DEBUG: Reset hit effect states - attack phase returned to idle") println("DEBUG: Reset hit effect states - attack phase returned to idle")
} }
} }
@ -221,6 +227,11 @@ fun BattleScreen(
// Show hit effect and damage effect // Show hit effect and damage effect
println("DEBUG: Setting showOpponentHitEffect = true (player attack hits enemy)") println("DEBUG: Setting showOpponentHitEffect = true (player attack hits enemy)")
showOpponentHitEffect = true showOpponentHitEffect = true
// Delay hiding the attack sprite to match hit effect timing
coroutineScope.launch {
delay(400) // Match the hit effect delay
hideEnemyAttackSprite = true
}
// Show damage number when attack reaches enemy // Show damage number when attack reaches enemy
if (pendingOpponentDamage > 0) { if (pendingOpponentDamage > 0) {
showOpponentDamageNumber = true showOpponentDamageNumber = true
@ -278,6 +289,11 @@ fun BattleScreen(
// Show hit effect and damage effect // Show hit effect and damage effect
println("DEBUG: Setting showPlayerHitEffect = true (enemy attack hits player)") println("DEBUG: Setting showPlayerHitEffect = true (enemy attack hits player)")
showPlayerHitEffect = true showPlayerHitEffect = true
// Delay hiding the attack sprite to match hit effect timing
coroutineScope.launch {
delay(400) // Match the hit effect delay
hidePlayerAttackSprite = true
}
// Show damage number when attack reaches player // Show damage number when attack reaches player
if (pendingPlayerDamage > 0) { if (pendingPlayerDamage > 0) {
showPlayerDamageNumber = true showPlayerDamageNumber = true
@ -462,7 +478,9 @@ fun BattleScreen(
pendingPlayerDamage = playerDamage pendingPlayerDamage = playerDamage
pendingOpponentDamage = opponentDamage pendingOpponentDamage = opponentDamage
}, },
coroutineScope = coroutineScope coroutineScope = coroutineScope,
hidePlayerAttackSprite = hidePlayerAttackSprite,
hideEnemyAttackSprite = hideEnemyAttackSprite
) )
} }
1 -> { 1 -> {
@ -482,7 +500,8 @@ fun BattleScreen(
pendingPlayerDamage = playerDamage pendingPlayerDamage = playerDamage
pendingOpponentDamage = opponentDamage pendingOpponentDamage = opponentDamage
}, },
coroutineScope = coroutineScope coroutineScope = coroutineScope,
hidePlayerAttackSprite = hidePlayerAttackSprite
) )
} }
2 -> { 2 -> {
@ -493,7 +512,8 @@ fun BattleScreen(
opponentName = opponentName, opponentName = opponentName,
attackAnimationProgress = battleSystem.attackProgress, attackAnimationProgress = battleSystem.attackProgress,
activeCharacter = opponentCharacter, activeCharacter = opponentCharacter,
playerCharacter = activeCharacter playerCharacter = activeCharacter,
hideEnemyAttackSprite = hideEnemyAttackSprite
) )
} }
} }
@ -524,6 +544,7 @@ fun BattleScreen(
onAnimationComplete = { onAnimationComplete = {
println("DEBUG: Player hit effect animation completed, setting showPlayerHitEffect = false") println("DEBUG: Player hit effect animation completed, setting showPlayerHitEffect = false")
showPlayerHitEffect = false showPlayerHitEffect = false
hidePlayerAttackSprite = false // Show attack sprite again
println("DEBUG: Player hit effect animation completed") println("DEBUG: Player hit effect animation completed")
} }
) )
@ -562,6 +583,7 @@ fun BattleScreen(
onAnimationComplete = { onAnimationComplete = {
println("DEBUG: Enemy hit effect animation completed, setting showOpponentHitEffect = false") println("DEBUG: Enemy hit effect animation completed, setting showOpponentHitEffect = false")
showOpponentHitEffect = false showOpponentHitEffect = false
hideEnemyAttackSprite = false // Show attack sprite again
println("DEBUG: Enemy hit effect animation completed") println("DEBUG: Enemy hit effect animation completed")
} }
) )
@ -584,7 +606,9 @@ fun MiddleBattleView(
opponentCharacter: APIBattleCharacter?, opponentCharacter: APIBattleCharacter?,
context: android.content.Context?, context: android.content.Context?,
onSetPendingDamage: (Float, Float) -> Unit, onSetPendingDamage: (Float, Float) -> Unit,
coroutineScope: kotlinx.coroutines.CoroutineScope coroutineScope: kotlinx.coroutines.CoroutineScope,
hidePlayerAttackSprite: Boolean,
hideEnemyAttackSprite: Boolean
) { ) {
// Track previous character ID to detect transitions // Track previous character ID to detect transitions
var previousCharacterId by remember { mutableStateOf<String?>(null) } var previousCharacterId by remember { mutableStateOf<String?>(null) }
@ -735,7 +759,7 @@ fun MiddleBattleView(
) )
// Enemy attack sprite (Phase 1 only) // Enemy attack sprite (Phase 1 only)
if (battleSystem.attackPhase == 1) { if (battleSystem.attackPhase == 1 && !hideEnemyAttackSprite) {
val xOffset = (-attackAnimationProgress * 400).dp // Start at center, move left off screen val xOffset = (-attackAnimationProgress * 400).dp // Start at center, move left off screen
val yOffset = 30.dp // Lower enemy attack sprite by 30 pixels val yOffset = 30.dp // Lower enemy attack sprite by 30 pixels
@ -817,7 +841,7 @@ fun MiddleBattleView(
) )
// Player attack sprite (Phase 1 only) // Player attack sprite (Phase 1 only)
if (battleSystem.attackPhase == 1) { if (battleSystem.attackPhase == 1 && !hidePlayerAttackSprite) {
val xOffset = (attackAnimationProgress * 400).dp // Start at center, move right off screen val xOffset = (attackAnimationProgress * 400).dp // Start at center, move right off screen
val yOffset = (-30).dp // Raise player attack sprite by 30 pixels val yOffset = (-30).dp // Raise player attack sprite by 30 pixels
@ -1015,7 +1039,8 @@ fun PlayerBattleView(
context: android.content.Context?, context: android.content.Context?,
opponent: APIBattleCharacter?, opponent: APIBattleCharacter?,
onSetPendingDamage: (Float, Float) -> Unit, onSetPendingDamage: (Float, Float) -> Unit,
coroutineScope: kotlinx.coroutines.CoroutineScope coroutineScope: kotlinx.coroutines.CoroutineScope,
hidePlayerAttackSprite: Boolean
) { ) {
// Track previous character ID to detect transitions // Track previous character ID to detect transitions
var previousCharacterId by remember { mutableStateOf<String?>(null) } var previousCharacterId by remember { mutableStateOf<String?>(null) }
@ -1190,7 +1215,7 @@ fun PlayerBattleView(
println("PlayerBattleView - Attack sprite - Phase: ${battleSystem.attackPhase}, Progress: $attackAnimationProgress, X Offset: $xOffset, CurrentView: ${battleSystem.currentView}") println("PlayerBattleView - Attack sprite - Phase: ${battleSystem.attackPhase}, Progress: $attackAnimationProgress, X Offset: $xOffset, CurrentView: ${battleSystem.currentView}")
if (!isTransitioning) { if (!isTransitioning && !hidePlayerAttackSprite) {
AttackSpriteImage( AttackSpriteImage(
characterId = characterId, characterId = characterId,
isLarge = true, isLarge = true,
@ -1200,7 +1225,7 @@ fun PlayerBattleView(
x = xOffset, x = xOffset,
y = 0.dp y = 0.dp
) )
.scale(if (battleSystem.attackPhase == 3) 1f else -1f, 1f), // Don't flip enemy attacks .scale(1f, 1f), // Don't flip enemy attacks on player screen
contentScale = ContentScale.Fit contentScale = ContentScale.Fit
) )
} }
@ -1355,7 +1380,8 @@ fun EnemyBattleView(
opponentName: String, opponentName: String,
attackAnimationProgress: Float, attackAnimationProgress: Float,
activeCharacter: APIBattleCharacter? = null, activeCharacter: APIBattleCharacter? = null,
playerCharacter: APIBattleCharacter? = null playerCharacter: APIBattleCharacter? = null,
hideEnemyAttackSprite: Boolean
) { ) {
// Track previous character ID to detect transitions // Track previous character ID to detect transitions
var previousCharacterId by remember { mutableStateOf<String?>(null) } var previousCharacterId by remember { mutableStateOf<String?>(null) }
@ -1490,7 +1516,7 @@ fun EnemyBattleView(
println("EnemyBattleView - Attack sprite - Phase: ${battleSystem.attackPhase}, Progress: $attackAnimationProgress, X Offset: $xOffset, CurrentView: ${battleSystem.currentView}") println("EnemyBattleView - Attack sprite - Phase: ${battleSystem.attackPhase}, Progress: $attackAnimationProgress, X Offset: $xOffset, CurrentView: ${battleSystem.currentView}")
if (!isTransitioning) { if (!isTransitioning && !hideEnemyAttackSprite) {
AttackSpriteImage( AttackSpriteImage(
characterId = characterId, characterId = characterId,
isLarge = true, isLarge = true,