Skip to content

Commit

Permalink
Change heal powerup effect
Browse files Browse the repository at this point in the history
Signed-off-by: Kirill Leyfer <[email protected]>
  • Loading branch information
BOOtak committed Oct 3, 2022
1 parent fbcfac0 commit 0f89d62
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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") }

Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Player> = 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)
}
}

0 comments on commit 0f89d62

Please sign in to comment.