Skip to content

Commit

Permalink
feat: add vfx to collecting quirk and meteoric shower (#210)
Browse files Browse the repository at this point in the history
* initial commit

* code cleanup

* code cleanup

* fix javavdoc comment
  • Loading branch information
Aleosiss committed Jun 18, 2023
1 parent c74a709 commit 57469b5
Show file tree
Hide file tree
Showing 7 changed files with 417 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/main/kotlin/marisa/action/MeteoricShowerAction.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import com.megacrit.cardcrawl.core.CardCrawlGame
import com.megacrit.cardcrawl.core.Settings
import com.megacrit.cardcrawl.dungeons.AbstractDungeon
import com.megacrit.cardcrawl.ui.panels.EnergyPanel
import marisa.fx.MeteoricShowerEffect

class MeteoricShowerAction(number: Int, damage: Int, val freeToPlay: Boolean) :
AbstractGameAction() {
Expand Down Expand Up @@ -43,7 +44,8 @@ class MeteoricShowerAction(number: Int, damage: Int, val freeToPlay: Boolean) :
}
AbstractDungeon.handCardSelectScreen.wereCardsRetrieved = true
AbstractDungeon.handCardSelectScreen.selectedCards.group.clear()
addToTop(RandomDamageAction(cnt) { dmg })
addToBot(MeteoricShowerEffect.toVfx(cnt))
addToBot(RandomDamageAction(cnt) { dmg })
AbstractDungeon.gridSelectScreen.selectedCards.clear()
AbstractDungeon.player.hand.refreshHandLayout()
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/kotlin/marisa/cards/CollectingQuirk.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import com.megacrit.cardcrawl.relics.Circlet
import com.megacrit.cardcrawl.relics.RedCirclet
import marisa.MarisaContinued
import marisa.action.RandomDamageAction
import marisa.fx.CollectingQuirkEffect
import marisa.patches.AbstractCardEnum

class CollectingQuirk : CustomCard(
Expand Down Expand Up @@ -69,6 +70,7 @@ class CollectingQuirk : CustomCard(
}

override fun use(p: AbstractPlayer, unused: AbstractMonster?) {
addToBot(CollectingQuirkEffect.toVfx())
addToBot(RandomDamageAction(counter) { damage })
}

Expand Down
67 changes: 67 additions & 0 deletions src/main/kotlin/marisa/fx/CollectingQuirkEffect.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package marisa.fx

import com.badlogic.gdx.Gdx
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import com.megacrit.cardcrawl.actions.animations.VFXAction
import com.megacrit.cardcrawl.core.CardCrawlGame.screenShake
import com.megacrit.cardcrawl.core.CardCrawlGame.sound
import com.megacrit.cardcrawl.core.Settings
import com.megacrit.cardcrawl.dungeons.AbstractDungeon.player
import com.megacrit.cardcrawl.dungeons.AbstractDungeon.effectsQueue
import com.megacrit.cardcrawl.dungeons.AbstractDungeon.getMonsters
import com.megacrit.cardcrawl.helpers.ScreenShake
import com.megacrit.cardcrawl.monsters.AbstractMonster
import com.megacrit.cardcrawl.relics.AbstractRelic
import com.megacrit.cardcrawl.vfx.BorderLongFlashEffect
import marisa.fx.lib.FireProjectileEffect.Companion.CollectingQuirkProjectile
import marisa.fx.lib.SOUND_EFFECT_KEY
import marisa.fx.lib.VfxGameEffect

private const val MAX_VFX_PROJECTILES = 50

class CollectingQuirkEffect(private val flipped: Boolean, private val monsterX: Float) : VfxGameEffect() {
private val relics: List<AbstractRelic> = player.relics
private var relicCounter = 0

init {
duration = if (Settings.FAST_MODE) 2.0f else 0.5f
}

override fun update() {
if (isFirstUpdate()) { start() }

duration -= Gdx.graphics.deltaTime
timer -= Gdx.graphics.deltaTime
if (relicCounter < relics.size.coerceAtMost(MAX_VFX_PROJECTILES) && timer < 0.0f) {
timer += 0.03f
effectsQueue.add(CollectingQuirkProjectile(relics[relicCounter].img, relics.size, flipped, monsterX))
relicCounter += 1
}
if (duration < 0.0f) {
isDone = true
}
}

override fun start() {
sound.playA(SOUND_EFFECT_KEY, -0.25f - relics.size.toFloat() / 200.0f)
screenShake.shake(ScreenShake.ShakeIntensity.HIGH, ScreenShake.ShakeDur.MED, true)
effectsQueue.add(BorderLongFlashEffect(Color.SKY))
hasStarted = true
}

override fun render(spriteBatch: SpriteBatch) {}
override fun dispose() {}

companion object {
fun toVfx(): VFXAction {
val duration = if (Settings.FAST_MODE) 0.5f else 1.0f
val monsters = getMonsters()
val avgX = monsters.monsters.stream()
.mapToDouble { m: AbstractMonster -> m.drawX.toDouble() }.average()
.orElse(Settings.WIDTH.toDouble())
.toFloat()
return VFXAction(CollectingQuirkEffect(monsters.shouldFlipVfx(), avgX), duration)
}
}
}
74 changes: 74 additions & 0 deletions src/main/kotlin/marisa/fx/MeteoricShowerEffect.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package marisa.fx

import com.badlogic.gdx.Gdx
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.Texture
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import com.megacrit.cardcrawl.actions.animations.VFXAction
import com.megacrit.cardcrawl.core.CardCrawlGame.screenShake
import com.megacrit.cardcrawl.core.CardCrawlGame.sound
import com.megacrit.cardcrawl.core.Settings
import com.megacrit.cardcrawl.dungeons.AbstractDungeon.effectsQueue
import com.megacrit.cardcrawl.dungeons.AbstractDungeon.getMonsters
import com.megacrit.cardcrawl.helpers.ImageMaster
import com.megacrit.cardcrawl.helpers.ScreenShake
import com.megacrit.cardcrawl.monsters.AbstractMonster
import com.megacrit.cardcrawl.vfx.BorderLongFlashEffect
import marisa.fx.lib.FireProjectileEffect.Companion.MeteoricShowerProjectile
import marisa.fx.lib.SOUND_EFFECT_KEY
import marisa.fx.lib.VfxGameEffect

private const val MAX_VFX_PROJECTILES = 50

class MeteoricShowerEffect(
private val numHits: Int,
private val flipped: Boolean,
private val monsterX: Float
) : VfxGameEffect() {
private var starCounter = 0

init {
duration = if (Settings.FAST_MODE) 2.0f else 0.5f
}

override fun update() {
if (isFirstUpdate()) { start() }

duration -= Gdx.graphics.deltaTime
timer -= Gdx.graphics.deltaTime
if (starCounter < numHits.coerceAtMost(MAX_VFX_PROJECTILES) && timer < 0.0f) {
timer += 0.03f
effectsQueue.add(MeteoricShowerProjectile(numHits, flipped, monsterX))
starCounter += 1
}
if (duration < 0.0f) {
isDone = true
}
}

override fun start() {
sound.playA(SOUND_EFFECT_KEY, -0.25f - numHits.toFloat() / 200.0f)
screenShake.shake(ScreenShake.ShakeIntensity.HIGH, ScreenShake.ShakeDur.MED, true)
effectsQueue.add(BorderLongFlashEffect(Color.SKY))
hasStarted = true
}

override fun render(spriteBatch: SpriteBatch) {}
override fun dispose() {}

companion object {
private const val METEORIC_SHOWER_PROJECTILE_TEXPATH = "img/vfx/star_128.png"
@JvmField
val METEORIC_SHOWER_PROJECTILE: Texture = ImageMaster.loadImage(METEORIC_SHOWER_PROJECTILE_TEXPATH)

fun toVfx(numHits: Int): VFXAction {
val duration = if (Settings.FAST_MODE) 0.5f else 1.0f
val monsters = getMonsters()
val avgX = monsters.monsters.stream()
.mapToDouble { m: AbstractMonster -> m.drawX.toDouble() }.average()
.orElse(Settings.WIDTH.toDouble())
.toFloat()
return VFXAction(MeteoricShowerEffect(numHits, monsters.shouldFlipVfx(), avgX), duration)
}
}
}

0 comments on commit 57469b5

Please sign in to comment.