More sounds + some gui fixes

This commit is contained in:
RandomityGuy 2021-06-30 16:43:36 +05:30
parent eb59030a76
commit bcd2a7b2e0
13 changed files with 115 additions and 15 deletions

View file

@ -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");
}
}

View file

@ -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;

View file

@ -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();
}
}

View file

@ -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) {

View file

@ -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)) {

View file

@ -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;

View file

@ -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;
}
}

View file

@ -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);
}

View file

@ -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();
}
}

View file

@ -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();
}
}

View file

@ -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;
}
}

View file

@ -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;
}
}

View file

@ -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;