Raised opponent HP bar.

This commit is contained in:
lightheel 2025-08-05 07:01:39 -04:00
parent 71ba5e0207
commit c404f4f436

View File

@ -473,111 +473,119 @@ fun OpponentBattleView(
var previousAttackPhase by remember { mutableStateOf<Int?>(null) } var previousAttackPhase by remember { mutableStateOf<Int?>(null) }
var isTransitioning by remember { mutableStateOf(false) } var isTransitioning by remember { mutableStateOf(false) }
Column( Box(
modifier = Modifier modifier = Modifier.fillMaxSize()
.fillMaxSize()
.padding(16.dp),
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center
) { ) {
// Opponent Digimon // Top section: Enemy HP bar and HP numbers
Box( Column(
modifier = Modifier modifier = Modifier
.fillMaxWidth() .fillMaxWidth()
.size(80.dp), .padding(16.dp)
contentAlignment = Alignment.CenterEnd
) { ) {
// Determine animation type based on battle state // Enemy HP bar
val animationType = when (battleSystem.attackPhase) { LinearProgressIndicator(
1 -> DigimonAnimationType.IDLE // Player attack on player screen progress = battleSystem.opponentHP / (activeCharacter?.baseHp?.toFloat() ?: 100f),
2 -> DigimonAnimationType.IDLE // Player attack on opponent screen modifier = Modifier
3 -> DigimonAnimationType.ATTACK // Opponent attack on opponent screen .fillMaxWidth()
4 -> DigimonAnimationType.ATTACK // Opponent attack on player screen .height(10.dp),
else -> DigimonAnimationType.IDLE color = Color.Red,
} trackColor = Color.Gray
AnimatedSpriteImage(
characterId = activeCharacter?.charaId ?: "dim011_mon01",
animationType = animationType,
modifier = Modifier.size(80.dp),
contentScale = ContentScale.Fit,
reloadMappings = false
) )
// Attack sprite visibility and positioning based on attack phase // Enemy HP display numbers
val shouldShowAttack = when (battleSystem.attackPhase) { Text(
1 -> false // Player attack on player screen text = "Enemy HP: ${battleSystem.opponentHP.toInt()}/${activeCharacter?.baseHp ?: 100}",
2 -> true // Player attack on opponent screen fontSize = 14.sp,
3 -> true // Opponent attack on opponent screen color = Color.Black
4 -> false // Opponent attack on player screen )
else -> false }
}
if (shouldShowAttack) { // Middle section: Opponent Digimon
val xOffset = when (battleSystem.attackPhase) { Box(
2 -> (attackAnimationProgress * 400 - 350).dp // Player attack on opponent screen - start more to the left modifier = Modifier
3 -> (-attackAnimationProgress * 400 + -50).dp // Opponent attack on opponent screen - start more to the left .fillMaxSize()
else -> 0.dp .padding(16.dp),
contentAlignment = Alignment.Center
) {
// Opponent Digimon
Box(
modifier = Modifier
.fillMaxWidth()
.size(80.dp),
contentAlignment = Alignment.CenterEnd
) {
// Determine animation type based on battle state
val animationType = when (battleSystem.attackPhase) {
1 -> DigimonAnimationType.IDLE // Player attack on player screen
2 -> DigimonAnimationType.IDLE // Player attack on opponent screen
3 -> DigimonAnimationType.ATTACK // Opponent attack on opponent screen
4 -> DigimonAnimationType.ATTACK // Opponent attack on player screen
else -> DigimonAnimationType.IDLE
} }
// Use correct character ID based on attack phase AnimatedSpriteImage(
val characterId = when (battleSystem.attackPhase) { characterId = activeCharacter?.charaId ?: "dim011_mon01",
2 -> playerCharacter?.charaId ?: "dim011_mon01" // Use player's character ID for player attack animationType = animationType,
3 -> activeCharacter?.charaId ?: "dim011_mon01" // Use opponent's character ID for opponent attack modifier = Modifier.size(80.dp),
else -> "dim011_mon01" contentScale = ContentScale.Fit,
reloadMappings = false
)
// Attack sprite visibility and positioning based on attack phase
val shouldShowAttack = when (battleSystem.attackPhase) {
1 -> false // Player attack on player screen
2 -> true // Player attack on opponent screen
3 -> true // Opponent attack on opponent screen
4 -> false // Opponent attack on player screen
else -> false
} }
// Handle sprite transition if (shouldShowAttack) {
LaunchedEffect(characterId, battleSystem.attackPhase) { val xOffset = when (battleSystem.attackPhase) {
if ((previousCharacterId != null && previousCharacterId != characterId) || 2 -> (attackAnimationProgress * 400 - 350).dp // Player attack on opponent screen - start more to the left
(previousAttackPhase != null && previousAttackPhase != battleSystem.attackPhase)) { 3 -> (-attackAnimationProgress * 400 + -50).dp // Opponent attack on opponent screen - start more to the left
// Character ID or attack phase changed, start transition else -> 0.dp
isTransitioning = true
delay(100) // Brief invisibility period
isTransitioning = false
} }
previousCharacterId = characterId
previousAttackPhase = battleSystem.attackPhase
}
println("OpponentBattleView - Attack sprite - Phase: ${battleSystem.attackPhase}, Progress: $attackAnimationProgress, X Offset: $xOffset, CurrentView: ${battleSystem.currentView}") // Use correct character ID based on attack phase
val characterId = when (battleSystem.attackPhase) {
2 -> playerCharacter?.charaId ?: "dim011_mon01" // Use player's character ID for player attack
3 -> activeCharacter?.charaId ?: "dim011_mon01" // Use opponent's character ID for opponent attack
else -> "dim011_mon01"
}
if (!isTransitioning) { // Handle sprite transition
AttackSpriteImage( LaunchedEffect(characterId, battleSystem.attackPhase) {
characterId = characterId, if ((previousCharacterId != null && previousCharacterId != characterId) ||
isLarge = true, (previousAttackPhase != null && previousAttackPhase != battleSystem.attackPhase)) {
modifier = Modifier // Character ID or attack phase changed, start transition
.size(60.dp) isTransitioning = true
.offset( delay(100) // Brief invisibility period
x = xOffset, isTransitioning = false
y = 0.dp }
) previousCharacterId = characterId
.scale(if (battleSystem.attackPhase == 2) -1f else 1f, 1f), // Flip player attacks only previousAttackPhase = battleSystem.attackPhase
contentScale = ContentScale.Fit }
)
println("OpponentBattleView - Attack sprite - Phase: ${battleSystem.attackPhase}, Progress: $attackAnimationProgress, X Offset: $xOffset, CurrentView: ${battleSystem.currentView}")
if (!isTransitioning) {
AttackSpriteImage(
characterId = characterId,
isLarge = true,
modifier = Modifier
.size(60.dp)
.offset(
x = xOffset,
y = 0.dp
)
.scale(if (battleSystem.attackPhase == 2) -1f else 1f, 1f), // Flip player attacks only
contentScale = ContentScale.Fit
)
}
} }
} }
} }
// Enemy HP bar
LinearProgressIndicator(
progress = battleSystem.opponentHP / (activeCharacter?.baseHp?.toFloat() ?: 100f),
modifier = Modifier
.fillMaxWidth()
.height(10.dp),
color = Color.Red,
trackColor = Color.Gray
)
// Enemy HP display numbers
Text(
text = "Enemy HP: ${battleSystem.opponentHP.toInt()}/${activeCharacter?.baseHp ?: 100}",
fontSize = 14.sp,
color = Color.Black
)
// Spacer for layout balance
Spacer(modifier = Modifier.height(120.dp))
} }
} }