mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-14 12:34:05 +09:00
boom sound for the bomb
This commit is contained in:
@@ -14,7 +14,7 @@ object ExplosionManager {
|
||||
private const val CALC_RADIUS = 127
|
||||
private const val CALC_WIDTH = CALC_RADIUS * 2 + 1
|
||||
|
||||
fun goBoom(world: GameWorld, tx: Int, ty: Int, power: Float) {
|
||||
fun goBoom(world: GameWorld, tx: Int, ty: Int, power: Float, callback: () -> Unit) {
|
||||
// create a copy of the tilemap
|
||||
val tilemap = BlockLayerI16(CALC_WIDTH, CALC_WIDTH)
|
||||
|
||||
@@ -23,7 +23,7 @@ object ExplosionManager {
|
||||
memcpyFromWorld(world, tx - CALC_RADIUS, ty - CALC_RADIUS, line, tilemap)
|
||||
}
|
||||
|
||||
createExplosionWorker(tilemap, tx, ty, power, world).start()
|
||||
createExplosionWorker(tilemap, tx, ty, power, world, callback).start()
|
||||
}
|
||||
|
||||
private fun memcpyFromWorld(world: GameWorld, xStart: Int, yStart: Int, yOff: Int, out: BlockLayerI16) {
|
||||
@@ -64,7 +64,7 @@ object ExplosionManager {
|
||||
* @param ty tilewise centre-y of the explosive
|
||||
* @param outWorld world object to write the result to
|
||||
*/
|
||||
private fun createExplosionWorker(tilemap: BlockLayerI16, tx: Int, ty: Int, power: Float, outWorld: GameWorld): Thread {
|
||||
private fun createExplosionWorker(tilemap: BlockLayerI16, tx: Int, ty: Int, power: Float, outWorld: GameWorld, callback: () -> Unit): Thread {
|
||||
return Thread {
|
||||
// simulate explosion like lightmaprenderer
|
||||
|
||||
@@ -74,6 +74,8 @@ object ExplosionManager {
|
||||
|
||||
// dispose of the tilemap copy
|
||||
tilemap.tryDispose()
|
||||
|
||||
callback()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -46,8 +46,7 @@ class TerrarumMusicGovernor : MusicGovernor() {
|
||||
try {
|
||||
MusicContainer(
|
||||
fileToName(it.name),
|
||||
it,
|
||||
Gdx.audio.newMusic(Gdx.files.absolute(it.absolutePath))
|
||||
it
|
||||
).also { muscon ->
|
||||
|
||||
printdbg(this, "MusicTitle: ${muscon.name}")
|
||||
@@ -149,10 +148,8 @@ class TerrarumMusicGovernor : MusicGovernor() {
|
||||
MusicContainer(
|
||||
fileHandle.nameWithoutExtension().replace('_', ' ').split(" ").map { it.capitalize() }.joinToString(" "),
|
||||
fileHandle.file(),
|
||||
Gdx.audio.newMusic(fileHandle).also {
|
||||
it.isLooping = true
|
||||
}
|
||||
) { }
|
||||
loop = true,
|
||||
)
|
||||
}
|
||||
catch (e: GdxRuntimeException) {
|
||||
e.printStackTrace()
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
package net.torvald.terrarum.modulebasegame.gameactors
|
||||
|
||||
import com.badlogic.gdx.Gdx
|
||||
import net.torvald.spriteanimation.SingleImageSprite
|
||||
import net.torvald.terrarum.CommonResourcePool
|
||||
import net.torvald.terrarum.INGAME
|
||||
import net.torvald.terrarum.Second
|
||||
import net.torvald.terrarum.*
|
||||
import net.torvald.terrarum.audio.MusicContainer
|
||||
import net.torvald.terrarum.audio.decibelsToFullscale
|
||||
import net.torvald.terrarum.gameactors.ActorWithBody
|
||||
import net.torvald.terrarum.gameactors.PhysProperties
|
||||
import net.torvald.terrarum.modulebasegame.ExplosionManager
|
||||
@@ -19,6 +20,7 @@ open class ActorPrimedBomb(
|
||||
init {
|
||||
renderOrder = RenderOrder.MIDTOP
|
||||
physProp = PhysProperties.PHYSICS_OBJECT()
|
||||
elasticity = 0.34
|
||||
}
|
||||
|
||||
protected constructor() : this(1f, 1f) {
|
||||
@@ -26,17 +28,37 @@ open class ActorPrimedBomb(
|
||||
physProp = PhysProperties.PHYSICS_OBJECT()
|
||||
}
|
||||
|
||||
private var explosionCalled = false
|
||||
|
||||
@Transient private val boomSound = MusicContainer(
|
||||
"boom", ModMgr.getFile("basegame", "audio/effects/explosion/bang_bomb.ogg")
|
||||
) {
|
||||
this.flagDespawn()
|
||||
}
|
||||
|
||||
override fun updateImpl(delta: Float) {
|
||||
super.updateImpl(delta)
|
||||
|
||||
fuse -= delta
|
||||
|
||||
if (fuse <= 0f) {
|
||||
if (fuse <= 0f && !explosionCalled) {
|
||||
explosionCalled = true
|
||||
physProp.usePhysics = false
|
||||
ExplosionManager.goBoom(INGAME.world, intTilewiseHitbox.centeredX.toInt(), intTilewiseHitbox.centeredY.toInt(), explosionPower)
|
||||
flagDespawn()
|
||||
|
||||
this.isVisible = false // or play explosion anim
|
||||
startAudio(boomSound, 10.0)
|
||||
|
||||
ExplosionManager.goBoom(INGAME.world, intTilewiseHitbox.centeredX.toInt(), intTilewiseHitbox.centeredY.toInt(), explosionPower) {
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun dispose() {
|
||||
super.dispose()
|
||||
boomSound.dispose()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -60,11 +60,7 @@ class FixtureFurnaceAndAnvil : FixtureBase, CraftingStation {
|
||||
}
|
||||
}
|
||||
|
||||
@Transient val static = MusicContainer("bonfire", ModMgr.getFile("basegame", "audio/effects/static/bonfire.ogg"), Gdx.audio.newMusic(
|
||||
ModMgr.getGdxFile("basegame", "audio/effects/static/bonfire.ogg")
|
||||
).also {
|
||||
it.isLooping = true
|
||||
})
|
||||
@Transient val static = MusicContainer("bonfire", ModMgr.getFile("basegame", "audio/effects/static/bonfire.ogg"), true)
|
||||
|
||||
@Transient override var lightBoxList = arrayListOf(Lightbox(Hitbox(0.0, 0.0, TerrarumAppConfiguration.TILE_SIZED * 2, TerrarumAppConfiguration.TILE_SIZED * 2), Cvec(0.5f, 0.18f, 0f, 0f)))
|
||||
|
||||
|
||||
@@ -127,7 +127,7 @@ class FixtureJukebox : Electric, PlaysMusic {
|
||||
|
||||
printdbg(this, "Title: $title, artist: $artist")
|
||||
|
||||
musicNowPlaying = MusicContainer(title, musicFile.file(), Gdx.audio.newMusic(musicFile)) {
|
||||
musicNowPlaying = MusicContainer(title, musicFile.file()) {
|
||||
unloadEffector(musicNowPlaying)
|
||||
discCurrentlyPlaying = null
|
||||
musicNowPlaying?.gdxMusic?.tryDispose()
|
||||
|
||||
@@ -119,7 +119,7 @@ class FixtureMusicalTurntable : Electric, PlaysMusic {
|
||||
|
||||
App.printdbg(this, "Title: $title, artist: $artist")
|
||||
|
||||
musicNowPlaying = MusicContainer(title, musicFile.file(), Gdx.audio.newMusic(musicFile)) {
|
||||
musicNowPlaying = MusicContainer(title, musicFile.file()) {
|
||||
unloadEffector(musicNowPlaying)
|
||||
musicNowPlaying?.gdxMusic?.tryDispose()
|
||||
musicNowPlaying = null
|
||||
|
||||
@@ -81,12 +81,7 @@ class FixtureSmelterBasic : FixtureBase, CraftingStation {
|
||||
this.mainUI = UISmelterBasic(this)
|
||||
}
|
||||
|
||||
@Transient val static = MusicContainer("bonfire", ModMgr.getFile("basegame", "audio/effects/static/bonfire.ogg"), Gdx.audio.newMusic(
|
||||
ModMgr.getGdxFile("basegame", "audio/effects/static/bonfire.ogg")
|
||||
).also {
|
||||
it.isLooping = true
|
||||
})
|
||||
|
||||
@Transient val static = MusicContainer("bonfire", ModMgr.getFile("basegame", "audio/effects/static/bonfire.ogg"), true)
|
||||
@Transient val light = Cvec(0.5f, 0.18f, 0f, 0f)
|
||||
|
||||
@Transient override var lightBoxList = arrayListOf(Lightbox(Hitbox(0.0, 2*TILE_SIZED, TILE_SIZED * 2, TILE_SIZED * 2), Cvec(0.5f, 0.18f, 0f, 0f)))
|
||||
|
||||
Reference in New Issue
Block a user