mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-15 21:14:04 +09:00
boom sound for the bomb
This commit is contained in:
BIN
assets/mods/basegame/audio/effects/explosion/bang_bomb.ogg
LFS
Normal file
BIN
assets/mods/basegame/audio/effects/explosion/bang_bomb.ogg
LFS
Normal file
Binary file not shown.
BIN
assets/mods/basegame/audio/effects/explosion/bang_small.ogg
LFS
Normal file
BIN
assets/mods/basegame/audio/effects/explosion/bang_small.ogg
LFS
Normal file
Binary file not shown.
@@ -335,6 +335,16 @@ Sound from <https://freesound.org/people/joedeshon>
|
|||||||
℗ 2019 DrinkingWindGames
|
℗ 2019 DrinkingWindGames
|
||||||
Sound from <https://freesound.org/people/DrinkingWindGames>
|
Sound from <https://freesound.org/people/DrinkingWindGames>
|
||||||
|
|
||||||
|
- effects/explosion/bang_bomb.ogg
|
||||||
|
|
||||||
|
℗ 2019 Richwise
|
||||||
|
Sound from <https://freesound.org/people/richwise>
|
||||||
|
|
||||||
|
- effects/explosion/bang_small.ogg
|
||||||
|
|
||||||
|
℗ 2009 Superex1110
|
||||||
|
Sound from <https://freesound.org/people/Superex1110/>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$BULLET Impulse Responses:
|
$BULLET Impulse Responses:
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ class AudioCodex {
|
|||||||
fun getRandomAudio(identifier: String): MusicContainer? {
|
fun getRandomAudio(identifier: String): MusicContainer? {
|
||||||
val file = audio[identifier]?.random()
|
val file = audio[identifier]?.random()
|
||||||
return if (file != null) {
|
return if (file != null) {
|
||||||
MusicContainer(file.nameWithoutExtension(), file.file(), Gdx.audio.newMusic(file)) {
|
MusicContainer(file.nameWithoutExtension(), file.file()) {
|
||||||
it.tryDispose()
|
it.tryDispose()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import com.badlogic.gdx.backends.lwjgl3.audio.Mp3
|
|||||||
import com.badlogic.gdx.backends.lwjgl3.audio.Ogg
|
import com.badlogic.gdx.backends.lwjgl3.audio.Ogg
|
||||||
import com.badlogic.gdx.backends.lwjgl3.audio.OggInputStream
|
import com.badlogic.gdx.backends.lwjgl3.audio.OggInputStream
|
||||||
import com.badlogic.gdx.backends.lwjgl3.audio.Wav
|
import com.badlogic.gdx.backends.lwjgl3.audio.Wav
|
||||||
|
import com.badlogic.gdx.files.FileHandle
|
||||||
import com.badlogic.gdx.utils.Disposable
|
import com.badlogic.gdx.utils.Disposable
|
||||||
import com.jcraft.jorbis.VorbisFile
|
import com.jcraft.jorbis.VorbisFile
|
||||||
import javazoom.jl.decoder.Bitstream
|
import javazoom.jl.decoder.Bitstream
|
||||||
@@ -20,7 +21,7 @@ import javax.sound.sampled.AudioSystem
|
|||||||
data class MusicContainer(
|
data class MusicContainer(
|
||||||
val name: String,
|
val name: String,
|
||||||
val file: File,
|
val file: File,
|
||||||
val gdxMusic: Music,
|
val loop: Boolean = false,
|
||||||
internal var songFinishedHook: (Music) -> Unit = {}
|
internal var songFinishedHook: (Music) -> Unit = {}
|
||||||
): Disposable {
|
): Disposable {
|
||||||
val samplingRate: Int
|
val samplingRate: Int
|
||||||
@@ -29,7 +30,11 @@ data class MusicContainer(
|
|||||||
var samplesRead = 0L; internal set
|
var samplesRead = 0L; internal set
|
||||||
val samplesTotal: Long
|
val samplesTotal: Long
|
||||||
|
|
||||||
|
val gdxMusic = Gdx.audio.newMusic(FileHandle(file))
|
||||||
|
|
||||||
init {
|
init {
|
||||||
|
gdxMusic.isLooping = loop
|
||||||
|
|
||||||
gdxMusic.setOnCompletionListener(songFinishedHook)
|
gdxMusic.setOnCompletionListener(songFinishedHook)
|
||||||
|
|
||||||
samplingRate = when (gdxMusic) {
|
samplingRate = when (gdxMusic) {
|
||||||
|
|||||||
@@ -166,6 +166,7 @@ abstract class Actor : Comparable<Actor>, Runnable {
|
|||||||
it.trackingTarget = this
|
it.trackingTarget = this
|
||||||
it.currentTrack = music
|
it.currentTrack = music
|
||||||
it.maxVolumeFun = { volume }
|
it.maxVolumeFun = { volume }
|
||||||
|
it.volume = volume
|
||||||
doSomethingWithTrack(it)
|
doSomethingWithTrack(it)
|
||||||
it.play()
|
it.play()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ object ExplosionManager {
|
|||||||
private const val CALC_RADIUS = 127
|
private const val CALC_RADIUS = 127
|
||||||
private const val CALC_WIDTH = CALC_RADIUS * 2 + 1
|
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
|
// create a copy of the tilemap
|
||||||
val tilemap = BlockLayerI16(CALC_WIDTH, CALC_WIDTH)
|
val tilemap = BlockLayerI16(CALC_WIDTH, CALC_WIDTH)
|
||||||
|
|
||||||
@@ -23,7 +23,7 @@ object ExplosionManager {
|
|||||||
memcpyFromWorld(world, tx - CALC_RADIUS, ty - CALC_RADIUS, line, tilemap)
|
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) {
|
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 ty tilewise centre-y of the explosive
|
||||||
* @param outWorld world object to write the result to
|
* @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 {
|
return Thread {
|
||||||
// simulate explosion like lightmaprenderer
|
// simulate explosion like lightmaprenderer
|
||||||
|
|
||||||
@@ -74,6 +74,8 @@ object ExplosionManager {
|
|||||||
|
|
||||||
// dispose of the tilemap copy
|
// dispose of the tilemap copy
|
||||||
tilemap.tryDispose()
|
tilemap.tryDispose()
|
||||||
|
|
||||||
|
callback()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -46,8 +46,7 @@ class TerrarumMusicGovernor : MusicGovernor() {
|
|||||||
try {
|
try {
|
||||||
MusicContainer(
|
MusicContainer(
|
||||||
fileToName(it.name),
|
fileToName(it.name),
|
||||||
it,
|
it
|
||||||
Gdx.audio.newMusic(Gdx.files.absolute(it.absolutePath))
|
|
||||||
).also { muscon ->
|
).also { muscon ->
|
||||||
|
|
||||||
printdbg(this, "MusicTitle: ${muscon.name}")
|
printdbg(this, "MusicTitle: ${muscon.name}")
|
||||||
@@ -149,10 +148,8 @@ class TerrarumMusicGovernor : MusicGovernor() {
|
|||||||
MusicContainer(
|
MusicContainer(
|
||||||
fileHandle.nameWithoutExtension().replace('_', ' ').split(" ").map { it.capitalize() }.joinToString(" "),
|
fileHandle.nameWithoutExtension().replace('_', ' ').split(" ").map { it.capitalize() }.joinToString(" "),
|
||||||
fileHandle.file(),
|
fileHandle.file(),
|
||||||
Gdx.audio.newMusic(fileHandle).also {
|
loop = true,
|
||||||
it.isLooping = true
|
)
|
||||||
}
|
|
||||||
) { }
|
|
||||||
}
|
}
|
||||||
catch (e: GdxRuntimeException) {
|
catch (e: GdxRuntimeException) {
|
||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
package net.torvald.terrarum.modulebasegame.gameactors
|
package net.torvald.terrarum.modulebasegame.gameactors
|
||||||
|
|
||||||
|
import com.badlogic.gdx.Gdx
|
||||||
import net.torvald.spriteanimation.SingleImageSprite
|
import net.torvald.spriteanimation.SingleImageSprite
|
||||||
import net.torvald.terrarum.CommonResourcePool
|
import net.torvald.terrarum.*
|
||||||
import net.torvald.terrarum.INGAME
|
import net.torvald.terrarum.audio.MusicContainer
|
||||||
import net.torvald.terrarum.Second
|
import net.torvald.terrarum.audio.decibelsToFullscale
|
||||||
import net.torvald.terrarum.gameactors.ActorWithBody
|
import net.torvald.terrarum.gameactors.ActorWithBody
|
||||||
import net.torvald.terrarum.gameactors.PhysProperties
|
import net.torvald.terrarum.gameactors.PhysProperties
|
||||||
import net.torvald.terrarum.modulebasegame.ExplosionManager
|
import net.torvald.terrarum.modulebasegame.ExplosionManager
|
||||||
@@ -19,6 +20,7 @@ open class ActorPrimedBomb(
|
|||||||
init {
|
init {
|
||||||
renderOrder = RenderOrder.MIDTOP
|
renderOrder = RenderOrder.MIDTOP
|
||||||
physProp = PhysProperties.PHYSICS_OBJECT()
|
physProp = PhysProperties.PHYSICS_OBJECT()
|
||||||
|
elasticity = 0.34
|
||||||
}
|
}
|
||||||
|
|
||||||
protected constructor() : this(1f, 1f) {
|
protected constructor() : this(1f, 1f) {
|
||||||
@@ -26,17 +28,37 @@ open class ActorPrimedBomb(
|
|||||||
physProp = PhysProperties.PHYSICS_OBJECT()
|
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) {
|
override fun updateImpl(delta: Float) {
|
||||||
super.updateImpl(delta)
|
super.updateImpl(delta)
|
||||||
|
|
||||||
fuse -= delta
|
fuse -= delta
|
||||||
|
|
||||||
if (fuse <= 0f) {
|
if (fuse <= 0f && !explosionCalled) {
|
||||||
|
explosionCalled = true
|
||||||
physProp.usePhysics = false
|
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(
|
@Transient val static = MusicContainer("bonfire", ModMgr.getFile("basegame", "audio/effects/static/bonfire.ogg"), true)
|
||||||
ModMgr.getGdxFile("basegame", "audio/effects/static/bonfire.ogg")
|
|
||||||
).also {
|
|
||||||
it.isLooping = 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)))
|
@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")
|
printdbg(this, "Title: $title, artist: $artist")
|
||||||
|
|
||||||
musicNowPlaying = MusicContainer(title, musicFile.file(), Gdx.audio.newMusic(musicFile)) {
|
musicNowPlaying = MusicContainer(title, musicFile.file()) {
|
||||||
unloadEffector(musicNowPlaying)
|
unloadEffector(musicNowPlaying)
|
||||||
discCurrentlyPlaying = null
|
discCurrentlyPlaying = null
|
||||||
musicNowPlaying?.gdxMusic?.tryDispose()
|
musicNowPlaying?.gdxMusic?.tryDispose()
|
||||||
|
|||||||
@@ -119,7 +119,7 @@ class FixtureMusicalTurntable : Electric, PlaysMusic {
|
|||||||
|
|
||||||
App.printdbg(this, "Title: $title, artist: $artist")
|
App.printdbg(this, "Title: $title, artist: $artist")
|
||||||
|
|
||||||
musicNowPlaying = MusicContainer(title, musicFile.file(), Gdx.audio.newMusic(musicFile)) {
|
musicNowPlaying = MusicContainer(title, musicFile.file()) {
|
||||||
unloadEffector(musicNowPlaying)
|
unloadEffector(musicNowPlaying)
|
||||||
musicNowPlaying?.gdxMusic?.tryDispose()
|
musicNowPlaying?.gdxMusic?.tryDispose()
|
||||||
musicNowPlaying = null
|
musicNowPlaying = null
|
||||||
|
|||||||
@@ -81,12 +81,7 @@ class FixtureSmelterBasic : FixtureBase, CraftingStation {
|
|||||||
this.mainUI = UISmelterBasic(this)
|
this.mainUI = UISmelterBasic(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transient val static = MusicContainer("bonfire", ModMgr.getFile("basegame", "audio/effects/static/bonfire.ogg"), Gdx.audio.newMusic(
|
@Transient val static = MusicContainer("bonfire", ModMgr.getFile("basegame", "audio/effects/static/bonfire.ogg"), true)
|
||||||
ModMgr.getGdxFile("basegame", "audio/effects/static/bonfire.ogg")
|
|
||||||
).also {
|
|
||||||
it.isLooping = true
|
|
||||||
})
|
|
||||||
|
|
||||||
@Transient val light = Cvec(0.5f, 0.18f, 0f, 0f)
|
@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)))
|
@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