Avoid overflow of the health bar in the overkill situation (#3558)

This commit is contained in:
Jack Rainy 2021-01-23 19:11:41 +02:00 committed by GitHub
parent 68b308dd26
commit 8c0be488bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -309,8 +309,9 @@ class BattleTable(val worldScreen: WorldScreen): Table() {
private fun getHealthBar(currentHealth: Int, maxHealth: Int, expectedDamage:Int): Table {
val healthBar = Table()
val totalWidth = 100f
fun addHealthToBar(image: Image, amount:Int){
healthBar.add(image).size(amount*totalWidth/maxHealth,3f)
fun addHealthToBar(image: Image, amount:Int) {
val width = totalWidth * amount/maxHealth
healthBar.add(image).size(width.coerceIn(0f,totalWidth),3f)
}
addHealthToBar(ImageGetter.getDot(Color.BLACK), maxHealth-currentHealth)