From 0f89d624d36e420c17b504dbf4ff14652531f32d Mon Sep 17 00:00:00 2001 From: Kirill Leyfer Date: Mon, 3 Oct 2022 23:42:52 +0300 Subject: [PATCH] Change heal powerup effect Signed-off-by: Kirill Leyfer --- .../alyoep/game/entities/CollisionsSystem.kt | 10 ++++++ .../alyoep/game/entities/Player.kt | 36 +++++++++++++++++++ .../game/entities/powerups/HealPowerUp.kt | 7 +--- 3 files changed, 47 insertions(+), 6 deletions(-) diff --git a/game/src/main/kotlin/org/catinthedark/alyoep/game/entities/CollisionsSystem.kt b/game/src/main/kotlin/org/catinthedark/alyoep/game/entities/CollisionsSystem.kt index 395b43b..5660b62 100644 --- a/game/src/main/kotlin/org/catinthedark/alyoep/game/entities/CollisionsSystem.kt +++ b/game/src/main/kotlin/org/catinthedark/alyoep/game/entities/CollisionsSystem.kt @@ -7,6 +7,7 @@ import org.catinthedark.alyoep.game.entities.powerups.PowerUp import org.catinthedark.alyoep.lib.IOC import org.catinthedark.alyoep.lib.atOrFail import org.slf4j.LoggerFactory +import kotlin.math.min import kotlin.math.pow fun intersectCircles(center1: Vector2, radius1: Float, center2: Vector2, radius2: Float): Boolean { @@ -69,6 +70,15 @@ class CollisionsSystem { it.apply(player) } powerUps.removeAll(collidedPowerUps) + + players.forEach { other -> + player.healNova?.apply { + if (other.healAnimationTime <= 0.01f && intersectTriangleCircle(p1, p2, p3, other.center, other.width)) { + other.playHealAnimation = true + other.currentHP = min(other.stats.maxHP, other.currentHP + other.stats.maxHP / 2f) + } + } + } } enemies.forEach { enemy -> diff --git a/game/src/main/kotlin/org/catinthedark/alyoep/game/entities/Player.kt b/game/src/main/kotlin/org/catinthedark/alyoep/game/entities/Player.kt index 720049d..6a9689a 100644 --- a/game/src/main/kotlin/org/catinthedark/alyoep/game/entities/Player.kt +++ b/game/src/main/kotlin/org/catinthedark/alyoep/game/entities/Player.kt @@ -48,6 +48,12 @@ class Player( ), override var shouldDestroy: Boolean = false, ) : ITransform, ICollisionRect, IDestructible { + var playHealAnimation: Boolean = false + set(value) { + field = value + healAnimationTime = 0f + } + var healAnimationTime: Float = 0f private val logger = LoggerFactory.getLogger(javaClass) private val render: ShapeRenderer by lazy { IOC.atOrFail("shapeRenderer") } @@ -135,6 +141,30 @@ class Player( val p3Hp = p3Cached.cpy().sub(p1Cached).scl(hpScale).add(p1Cached) it.triangle2(p2Hp, p2Cached, p3Cached) it.triangle2(p2Hp, p3Hp, p3Cached) + + if (playHealAnimation) { + val colorBottom = Color(Color.CHARTREUSE) + val colorTop = Color(Color.CHARTREUSE) + colorTop.a = 0f + + val effectHeight = height * 2 + val tm = healAnimationTime * 1.5f + val heightProgress = MathUtils.clamp(tm, 0f, 1f).pow(1f / 2) * effectHeight + val alphaProgress = MathUtils.map(0f, 1f, 1f, 0f, MathUtils.clamp(tm, 0f, 1f).pow(3f)) + + colorBottom.a = alphaProgress + + it.rect( + p2Cached.x, + p2Cached.y - heightProgress, + width, + heightProgress, + colorTop, + colorTop, + colorBottom, + colorBottom + ) + } } Gdx.gl.glDisable(GL20.GL_BLEND) } @@ -172,6 +202,12 @@ class Player( fun update() { time += Gdx.graphics.deltaTime + if (playHealAnimation) { + healAnimationTime += Gdx.graphics.deltaTime + if (healAnimationTime > 1.0f) { + playHealAnimation = false + } + } updateNova() if (currentHP > 0) { updatePos() diff --git a/game/src/main/kotlin/org/catinthedark/alyoep/game/entities/powerups/HealPowerUp.kt b/game/src/main/kotlin/org/catinthedark/alyoep/game/entities/powerups/HealPowerUp.kt index 9358c30..5e5f4de 100644 --- a/game/src/main/kotlin/org/catinthedark/alyoep/game/entities/powerups/HealPowerUp.kt +++ b/game/src/main/kotlin/org/catinthedark/alyoep/game/entities/powerups/HealPowerUp.kt @@ -13,18 +13,13 @@ import kotlin.math.min class HealPowerUp(override var pos: Vector2) : PowerUp(pos, Color.LIME) { private val bgm: Bgm by lazy { IOC.atOrFail("bgm") } - private val players: List = IOC.atOrFail("players") private val tower: Tower = IOC.atOrFail("tower") override fun apply(player: Player) { - players.forEach { - it.currentHP = min(it.stats.maxHP, it.currentHP + it.stats.maxHP / 2f) - } - tower.currentHP = min(Const.Balance.Tower.MAX_HP, tower.currentHP + Const.Balance.Tower.MAX_HP / 2f) bgm.collectPowerup(true) - player.healNova = HealNova(player.center.cpy(), player.height) + player.healNova = HealNova(tower.pos, player.height) } }