summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: fd73b6d)
raw | patch | inline | side by side (parent: fd73b6d)
author | fredboy <fredboy@protonmail.com> | |
Sun, 21 Apr 2024 13:11:19 +0000 (20:11 +0700) | ||
committer | fredboy <fredboy@protonmail.com> | |
Sun, 21 Apr 2024 13:11:19 +0000 (20:11 +0700) |
diff --git a/core/src/ru/deadsoftware/cavedroid/game/render/BackgroundBlocksRenderer.kt b/core/src/ru/deadsoftware/cavedroid/game/render/BackgroundBlocksRenderer.kt
index ae02aa407cb432b31a191439c62c2be1025906c0..515ad796f62c8cfa866804f614d0b6d74f834aa9 100644 (file)
drawBackMap(spriteBatch, viewport, x, y)
}
+ drawBlockDamage(spriteBatch, viewport)
+
spriteBatch.end()
Gdx.gl.glEnable(GL20.GL_BLEND)
Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA)
diff --git a/core/src/ru/deadsoftware/cavedroid/game/render/BlocksRenderer.kt b/core/src/ru/deadsoftware/cavedroid/game/render/BlocksRenderer.kt
index 3409fdf363f72ef44043c0ac629ef3e5b919d336..65d9e0ade81636d8855f1c509b51ae13a889f08f 100644 (file)
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import com.badlogic.gdx.graphics.g2d.TextureRegion
import com.badlogic.gdx.graphics.glutils.ShapeRenderer
+import com.badlogic.gdx.math.MathUtils
import com.badlogic.gdx.math.Rectangle
import ru.deadsoftware.cavedroid.game.GameInput
import ru.deadsoftware.cavedroid.game.model.block.Block
return Assets.textureRegions[textureKey]
}
- private fun drawBlockDamage(spriteBatch: SpriteBatch, block: Block, x: Float, y: Float) {
+ protected fun drawBlockDamage(spriteBatch: SpriteBatch, viewport: Rectangle) {
val blockDamage = gameInput.blockDamage
if (blockDamage <= 0) {
return
}
- val index = MAX_BLOCK_DAMAGE_INDEX * (blockDamage / block.params.hitPoints)
+ val block = if (background) {
+ gameWorld.getBackMap(gameInput.curX, gameInput.curY)
+ } else {
+ gameWorld.getForeMap(gameInput.curX, gameInput.curY)
+ }
+
+ val index = (MAX_BLOCK_DAMAGE_INDEX.toFloat() * (blockDamage.toFloat() / block.params.hitPoints.toFloat()))
+ .let(MathUtils::floor)
val texture = blockDamageTexture(index) ?: return
- spriteBatch.draw(texture, x, y)
+ if (gameWorld.hasForeAt(gameInput.curX, gameInput.curY) != background) {
+ spriteBatch.draw(texture, gameInput.curX.px - viewport.x, gameInput.curY.px - viewport.y)
+ }
}
protected fun shadeBackMap(
val drawX = x.px - viewport.x
val drawY = y.px - viewport.y
backgroundBlock.draw(spriteBatch, drawX, drawY)
-
- if (foregroundBlock.isNone()) {
- drawBlockDamage(spriteBatch, backgroundBlock, drawX, drawY)
- }
}
}
val drawX = x.px - viewport.x
val drawY = y.px - viewport.y
foregroundBlock.draw(spriteBatch, drawX, drawY)
-
- if (!foregroundBlock.isNone()) {
- drawBlockDamage(spriteBatch, foregroundBlock, drawX, drawY)
- }
}
}
diff --git a/core/src/ru/deadsoftware/cavedroid/game/render/ForegroundBlocksRenderer.kt b/core/src/ru/deadsoftware/cavedroid/game/render/ForegroundBlocksRenderer.kt
index 3380490a40e3ec6108ca3ea4851147e0885df40b..30736958f36f3f31ec1e8941a11fc4f11e85b25a 100644 (file)
forEachBlockInArea(viewport) { x, y ->
drawForeMap(spriteBatch, viewport, x, y)
}
+ drawBlockDamage(spriteBatch, viewport)
}
companion object {