From bcd2a7b2e0b137fee37f3328181f289c6ffbb75d Mon Sep 17 00:00:00 2001 From: RandomityGuy <31925790+RandomityGuy@users.noreply.github.com> Date: Wed, 30 Jun 2021 16:43:36 +0530 Subject: [PATCH] More sounds + some gui fixes --- src/AudioManager.hx | 17 ++++++++++++++--- src/Marble.hx | 8 ++++++++ src/MarbleWorld.hx | 14 ++++++++++++++ src/PathedInterior.hx | 16 ++++++++++++++++ src/gui/GuiAnim.hx | 2 +- src/gui/GuiImage.hx | 2 +- src/shapes/DuctFan.hx | 20 ++++++++++++++++++++ src/shapes/EndPad.hx | 2 +- src/shapes/Helicopter.hx | 5 +---- src/shapes/ShockAbsorber.hx | 4 ---- src/shapes/SmallDuctFan.hx | 20 ++++++++++++++++++++ src/shapes/Tornado.hx | 15 +++++++++++++++ src/shapes/Trapdoor.hx | 5 ++++- 13 files changed, 115 insertions(+), 15 deletions(-) diff --git a/src/AudioManager.hx b/src/AudioManager.hx index b50b1b7b..161ed44c 100644 --- a/src/AudioManager.hx +++ b/src/AudioManager.hx @@ -1,5 +1,6 @@ package src; +import h3d.scene.Scene; import hxd.snd.effect.Spatialization; import h3d.Vector; import hxd.res.Sound; @@ -19,12 +20,22 @@ class AudioManager { musicChannel.volume = Settings.optionsSettings.musicVolume; } - public static function playSound(sound:Sound, ?position:Vector) { - AudioManager.manager.play(sound, soundChannel); + public static function update(scene3d:Scene) { + manager.listener.syncCamera(scene3d.camera); + } + + public static function playSound(sound:Sound, ?position:Vector, ?loop:Bool = false) { + var ch = AudioManager.manager.play(sound, soundChannel); + ch.loop = loop; if (position != null) { var audioSrc = new Spatialization(); audioSrc.position = position; - soundChannel.addEffect(audioSrc); + ch.addEffect(audioSrc); } + return ch; + } + + public static function stopAllSounds() { + manager.stopByName("sound"); } } diff --git a/src/Marble.hx b/src/Marble.hx index 57a142aa..2bfe006d 100644 --- a/src/Marble.hx +++ b/src/Marble.hx @@ -1,5 +1,7 @@ package src; +import shapes.TriangleBumper; +import shapes.RoundBumper; import src.Util; import src.AudioManager; import src.Settings; @@ -260,6 +262,12 @@ class Marble extends GameObject { for (contact in contacts) { if (contact.force != 0 && !forceObjects.contains(contact.otherObject)) { + if (contact.otherObject is RoundBumper) { + AudioManager.playSound(ResourceLoader.getAudio("data/sound/bumperding1.wav")); + } + if (contact.otherObject is TriangleBumper) { + AudioManager.playSound(ResourceLoader.getAudio("data/sound/bumper1.wav")); + } forceObjectCount++; contactNormal = contactNormal.add(contact.normal); contactForce += contact.force; diff --git a/src/MarbleWorld.hx b/src/MarbleWorld.hx index 4cee148c..24792d4a 100644 --- a/src/MarbleWorld.hx +++ b/src/MarbleWorld.hx @@ -1,5 +1,7 @@ package src; +import hxd.snd.Channel; +import hxd.res.Sound; import src.ResourceLoader; import src.AudioManager; import src.Settings; @@ -108,6 +110,8 @@ class MarbleWorld extends Scheduler { public var cursorLock:Bool = true; + var timeTravelSound:Channel; + var helpTextTimeState:Float = -1e8; var alertTextTimeState:Float = -1e8; @@ -643,6 +647,7 @@ class MarbleWorld extends Scheduler { this.instanceManager.update(dt); this.particleManager.update(1000 * timeState.timeSinceLoad, dt); this.playGui.update(timeState); + AudioManager.update(this.scene); this.updateTexts(); } @@ -659,7 +664,15 @@ class MarbleWorld extends Scheduler { this.timeState.gameplayClock -= this.bonusTime; this.bonusTime = 0; } + if (timeTravelSound == null) { + var ttsnd = ResourceLoader.getAudio("data/sound/timetravelactive.wav"); + timeTravelSound = AudioManager.playSound(ttsnd, null, true); + } } else { + if (timeTravelSound != null) { + timeTravelSound.stop(); + timeTravelSound = null; + } if (this.timeState.currentAttemptTime >= 3.5) this.timeState.gameplayClock += dt; else if (this.timeState.currentAttemptTime + dt >= 3.5) { @@ -982,6 +995,7 @@ class MarbleWorld extends Scheduler { this.playGui.dispose(); scene.removeChildren(); this._disposed = true; + AudioManager.stopAllSounds(); } } diff --git a/src/PathedInterior.hx b/src/PathedInterior.hx index a4cc7970..8fb76c5c 100644 --- a/src/PathedInterior.hx +++ b/src/PathedInterior.hx @@ -1,5 +1,9 @@ package src; +import hxd.snd.effect.Spatialization; +import src.ResourceLoader; +import src.AudioManager; +import hxd.snd.Channel; import src.DifBuilder; import mis.MisParser; import mis.MissionElement; @@ -53,6 +57,8 @@ class PathedInterior extends InteriorObject { var previousState:PIState; + var soundChannel:Channel; + public static function createFromSimGroup(simGroup:MissionElementSimGroup, level:MarbleWorld) { var interiorElement:MissionElementPathedInterior = cast simGroup.elements.filter((element) -> element._type == MissionElementType.PathedInterior)[0]; var difFile = level.mission.getDifPath(interiorElement.interiorresource); @@ -123,6 +129,11 @@ class PathedInterior extends InteriorObject { var trigger = new MustChangeTrigger(te, cast this); this.triggers.push(trigger); } + + if (this.element.datablock.toLowerCase() == "pathedmovingblock") { + this.soundChannel = AudioManager.playSound(ResourceLoader.getAudio("data/sound/movingblockloop.wav"), new Vector(), true); + } + this.reset(); } @@ -224,6 +235,11 @@ class PathedInterior extends InteriorObject { this.setTransform(tform); this.collider.setTransform(tform); this.collider.velocity = this.velocity; + + if (this.soundChannel != null) { + var spat = this.soundChannel.getEffect(Spatialization); + spat.position = this.currentPosition; + } } function getTransformAtTime(time:Float) { diff --git a/src/gui/GuiAnim.hx b/src/gui/GuiAnim.hx index aeeb4fe3..3ed53c79 100644 --- a/src/gui/GuiAnim.hx +++ b/src/gui/GuiAnim.hx @@ -17,7 +17,7 @@ class GuiAnim extends GuiControl { public override function render(scene2d:Scene) { var renderRect = this.getRenderRectangle(); - anim.setPosition(renderRect.position.x, renderRect.position.y); + anim.setPosition(Math.round(renderRect.position.x), Math.round(renderRect.position.y)); anim.scaleX = renderRect.extent.x / anim.getFrame().width; anim.scaleY = renderRect.extent.y / anim.getFrame().height; if (scene2d.contains(anim)) { diff --git a/src/gui/GuiImage.hx b/src/gui/GuiImage.hx index 8af2ac69..9fcd6264 100644 --- a/src/gui/GuiImage.hx +++ b/src/gui/GuiImage.hx @@ -19,7 +19,7 @@ class GuiImage extends GuiControl { public override function render(scene2d:Scene) { var renderRect = this.getRenderRectangle(); - bmp.setPosition(renderRect.position.x, renderRect.position.y); + bmp.setPosition(Math.round(renderRect.position.x), Math.round(renderRect.position.y)); // bmp.scaleX = renderRect.extent.x / bmp.tile.width; // bmp.scaleY = renderRect.extent.y / bmp.tile.height; bmp.width = renderRect.extent.x; diff --git a/src/shapes/DuctFan.hx b/src/shapes/DuctFan.hx index b29f03c3..d63b566b 100644 --- a/src/shapes/DuctFan.hx +++ b/src/shapes/DuctFan.hx @@ -1,9 +1,15 @@ package shapes; +import hxd.snd.effect.Spatialization; +import src.ResourceLoader; +import src.AudioManager; +import hxd.snd.Channel; import h3d.Vector; import src.ForceObject; class DuctFan extends ForceObject { + var soundChannel:Channel; + public function new() { super(); this.dtsPath = "data/shapes/hazards/ductfan.dts"; @@ -21,4 +27,18 @@ class DuctFan extends ForceObject { } ]; } + + public override function init(level:src.MarbleWorld) { + super.init(level); + + this.soundChannel = AudioManager.playSound(ResourceLoader.getAudio("data/sound/fan_loop.wav"), this.getAbsPos().getPosition(), true); + } + + public override function update(timeState:src.TimeState) { + super.update(timeState); + + var seffect = this.soundChannel.getEffect(Spatialization); + seffect.position = this.getAbsPos().getPosition(); + seffect.referenceDistance = 5; + } } diff --git a/src/shapes/EndPad.hx b/src/shapes/EndPad.hx index 385b5641..7a098e26 100644 --- a/src/shapes/EndPad.hx +++ b/src/shapes/EndPad.hx @@ -45,7 +45,7 @@ class EndPad extends DtsObject { function spawnFirework(time:TimeState) { var firework = new Firework(this.getAbsPos().getPosition(), time.timeSinceLoad, this.level); this.fireworks.push(firework); - // AudioManager.playSound(ResourceLoader.getAudio("data/sound/firewrks.wav")); + AudioManager.playSound(ResourceLoader.getAudio("data/sound/firewrks.wav"), this.getAbsPos().getPosition()); // AudioManager.play(this.sounds[0], 1, AudioManager.soundGain, this.worldPosition); } diff --git a/src/shapes/Helicopter.hx b/src/shapes/Helicopter.hx index 01c5394c..4f9dccc0 100644 --- a/src/shapes/Helicopter.hx +++ b/src/shapes/Helicopter.hx @@ -4,6 +4,7 @@ import src.ResourceLoader; import mis.MissionElement.MissionElementItem; import src.TimeState; import src.DtsObject; +import src.AudioManager; class Helicopter extends PowerUp { public function new(element:MissionElementItem) { @@ -24,10 +25,6 @@ class Helicopter extends PowerUp { public function use(timeState:TimeState) { var marble = this.level.marble; marble.enableHelicopter(timeState.currentAttemptTime); - // marble.body.addLinearVelocity(this.level.currentUp.scale(20)); // Simply add to vertical velocity - // if (!this.level.rewinding) - // AudioManager.play(this.sounds[1]); - // this.level.particles.createEmitter(superJumpParticleOptions, null, () => Util.vecOimoToThree(marble.body.getPosition())); this.level.deselectPowerUp(); } } diff --git a/src/shapes/ShockAbsorber.hx b/src/shapes/ShockAbsorber.hx index 1172ab55..0fba3b12 100644 --- a/src/shapes/ShockAbsorber.hx +++ b/src/shapes/ShockAbsorber.hx @@ -23,10 +23,6 @@ class ShockAbsorber extends PowerUp { public function use(timeState:TimeState) { var marble = this.level.marble; marble.enableShockAbsorber(timeState.currentAttemptTime); - // marble.body.addLinearVelocity(this.level.currentUp.scale(20)); // Simply add to vertical velocity - // if (!this.level.rewinding) - // AudioManager.play(this.sounds[1]); - // this.level.particles.createEmitter(superJumpParticleOptions, null, () => Util.vecOimoToThree(marble.body.getPosition())); this.level.deselectPowerUp(); } } diff --git a/src/shapes/SmallDuctFan.hx b/src/shapes/SmallDuctFan.hx index ea858a42..d0dc057c 100644 --- a/src/shapes/SmallDuctFan.hx +++ b/src/shapes/SmallDuctFan.hx @@ -1,9 +1,15 @@ package shapes; +import hxd.snd.effect.Spatialization; +import hxd.snd.Channel; +import src.ResourceLoader; +import src.AudioManager; import h3d.Vector; import src.ForceObject; class SmallDuctFan extends ForceObject { + var soundChannel:Channel; + public function new() { super(); this.dtsPath = "data/shapes/hazards/ductfan.dts"; @@ -21,4 +27,18 @@ class SmallDuctFan extends ForceObject { } ]; } + + public override function init(level:src.MarbleWorld) { + super.init(level); + + this.soundChannel = AudioManager.playSound(ResourceLoader.getAudio("data/sound/fan_loop.wav"), this.getAbsPos().getPosition(), true); + } + + public override function update(timeState:src.TimeState) { + super.update(timeState); + + var seffect = this.soundChannel.getEffect(Spatialization); + seffect.position = this.getAbsPos().getPosition(); + seffect.referenceDistance = 5; + } } diff --git a/src/shapes/Tornado.hx b/src/shapes/Tornado.hx index 6315c704..7ed07db2 100644 --- a/src/shapes/Tornado.hx +++ b/src/shapes/Tornado.hx @@ -1,9 +1,15 @@ package shapes; +import hxd.snd.effect.Spatialization; +import hxd.snd.Channel; import h3d.Vector; import src.ForceObject; +import src.ResourceLoader; +import src.AudioManager; class Tornado extends ForceObject { + var soundChannel:Channel; + public function new() { super(); this.dtsPath = "data/shapes/hazards/tornado.dts"; @@ -40,8 +46,17 @@ class Tornado extends ForceObject { public override function init(level:src.MarbleWorld) { super.init(level); + this.soundChannel = AudioManager.playSound(ResourceLoader.getAudio("data/sound/tornado.wav"), this.getAbsPos().getPosition(), true); for (material in this.materials) { // material.mainPass.setPassName("overlay"); } } + + public override function update(timeState:src.TimeState) { + super.update(timeState); + + var seffect = this.soundChannel.getEffect(Spatialization); + seffect.position = this.getAbsPos().getPosition(); + seffect.referenceDistance = 5; + } } diff --git a/src/shapes/Trapdoor.hx b/src/shapes/Trapdoor.hx index fb4a11f0..a204fce6 100644 --- a/src/shapes/Trapdoor.hx +++ b/src/shapes/Trapdoor.hx @@ -1,5 +1,6 @@ package shapes; +import hxd.snd.effect.Spatialization; import src.TimeState; import collision.CollisionInfo; import src.Util; @@ -39,7 +40,9 @@ class Trapdoor extends DtsObject { direction = -1; if (direction != 0 && direction != this.lastDirection) { // If the direction has changed, play the sound - // AudioManager.playSound(this.sounds[0], 1, AudioManager.soundGain, this.worldPosition); + var ch = AudioManager.playSound(ResourceLoader.getAudio("data/sound/trapdooropen.wav"), this.getAbsPos().getPosition()); + var spat = ch.getEffect(Spatialization); + spat.referenceDistance = 5; } this.lastCompletion = currentCompletion;