mirror of
https://github.com/RandomityGuy/MBHaxe.git
synced 2026-03-01 17:40:59 +00:00
js enhancements
This commit is contained in:
parent
144260b22c
commit
7d97a4012d
9 changed files with 58 additions and 19 deletions
|
|
@ -37,15 +37,18 @@ class AudioManager {
|
|||
if (position != null) {
|
||||
var audioSrc = new Spatialization();
|
||||
audioSrc.position = position;
|
||||
#if hl
|
||||
audioSrc.referenceDistance = 5;
|
||||
#end
|
||||
#if js
|
||||
audioSrc.referenceDistance = 4.5;
|
||||
#end
|
||||
ch.addEffect(audioSrc);
|
||||
}
|
||||
return ch;
|
||||
}
|
||||
|
||||
public static function playShell() {
|
||||
#if js
|
||||
return;
|
||||
#end
|
||||
AudioManager.manager.stopByName("music");
|
||||
var snd = ResourceLoader.getAudio("data/sound/shell.ogg");
|
||||
if (snd == null)
|
||||
|
|
@ -55,9 +58,6 @@ class AudioManager {
|
|||
}
|
||||
|
||||
public static function playMusic(music:Sound) {
|
||||
#if js
|
||||
return;
|
||||
#end
|
||||
AudioManager.manager.stopByName("music");
|
||||
if (music == null)
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -358,7 +358,6 @@ class DtsObject extends GameObject {
|
|||
var keyframes = parseIfl(fullName);
|
||||
this.materialInfos.set(material, keyframes);
|
||||
iflMaterial = true;
|
||||
// TODO IFL SHIT
|
||||
} else {
|
||||
var texture:Texture = ResourceLoader.getTexture(fullName);
|
||||
texture.wrap = Wrap.Repeat;
|
||||
|
|
@ -377,11 +376,20 @@ class DtsObject extends GameObject {
|
|||
// var dtsshader = new DtsTexture();
|
||||
// dtsshader.currentOpacity = 1;
|
||||
// Make a 1x1 white texture
|
||||
#if hl
|
||||
var bitmap = new hxd.BitmapData(1, 1);
|
||||
bitmap.lock();
|
||||
bitmap.setPixel(0, 0, 0xFFFFFF);
|
||||
bitmap.setPixel(1, 1, 0xFFFFFF);
|
||||
bitmap.unlock();
|
||||
var texture = new Texture(1, 1);
|
||||
texture.uploadBitmap(bitmap);
|
||||
texture.wrap = Wrap.Repeat;
|
||||
#end
|
||||
// Apparently creating these bitmap datas dont work so we'll just get the snag a white texture in the filesystem
|
||||
#if js
|
||||
var texture:Texture = ResourceLoader.getTexture("data/interiors/parts/white.jpg");
|
||||
texture.wrap = Wrap.Repeat;
|
||||
#end
|
||||
material.texture = texture;
|
||||
// dtsshader.texture = texture;
|
||||
// material.mainPass.addShader(dtsshader);
|
||||
|
|
|
|||
|
|
@ -669,11 +669,9 @@ class Marble extends GameObject {
|
|||
function updateRollSound(contactPct:Float, slipAmount:Float) {
|
||||
var rSpat = rollSound.getEffect(Spatialization);
|
||||
rSpat.position = this.getAbsPos().getPosition();
|
||||
rSpat.referenceDistance = 5;
|
||||
|
||||
var sSpat = slipSound.getEffect(Spatialization);
|
||||
sSpat.position = this.getAbsPos().getPosition();
|
||||
sSpat.referenceDistance = 5;
|
||||
|
||||
var rollVel = bestContact != null ? this.velocity.sub(bestContact.velocity) : this.velocity;
|
||||
var scale = rollVel.length();
|
||||
|
|
@ -693,6 +691,11 @@ class Marble extends GameObject {
|
|||
rollVolume = (1 - slipVolume) * rollVolume;
|
||||
}
|
||||
|
||||
if (rollVolume < 0)
|
||||
rollVolume = 0;
|
||||
if (slipVolume < 0)
|
||||
slipVolume = 0;
|
||||
|
||||
rollSound.volume = rollVolume;
|
||||
slipSound.volume = slipVolume;
|
||||
|
||||
|
|
@ -701,9 +704,11 @@ class Marble extends GameObject {
|
|||
}
|
||||
|
||||
var pitch = scale;
|
||||
if (scale > 1.0)
|
||||
pitch = 1.0;
|
||||
|
||||
#if js
|
||||
// Apparently audio crashes the whole thing if pitch is less than 0.2
|
||||
if (pitch < 0.2)
|
||||
pitch = 0.2;
|
||||
#end
|
||||
var rPitch = rollSound.getEffect(Pitch);
|
||||
rPitch.value = pitch;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ class MarbleGame {
|
|||
this.scene2d = scene2d;
|
||||
|
||||
#if js
|
||||
// Pause shit
|
||||
js.Browser.document.addEventListener('pointerlockchange', () -> {
|
||||
if (!paused && world != null) {
|
||||
if (world.finishTime == null) {
|
||||
|
|
@ -46,6 +47,12 @@ class MarbleGame {
|
|||
}
|
||||
}
|
||||
});
|
||||
// Resize shit
|
||||
js.Browser.window.addEventListener('resize', () -> {
|
||||
var canvasElement = js.Browser.document.getElementById("webgl");
|
||||
canvasElement.style.width = "100%";
|
||||
canvasElement.style.height = "100%";
|
||||
});
|
||||
#end
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -120,11 +120,33 @@ class Settings {
|
|||
#if hl
|
||||
File.saveContent("settings.json", json);
|
||||
#end
|
||||
#if js
|
||||
var localStorage = js.Browser.getLocalStorage();
|
||||
if (localStorage != null) {
|
||||
localStorage.setItem("MBHaxeSettings", json);
|
||||
}
|
||||
#end
|
||||
}
|
||||
|
||||
public static function load() {
|
||||
if (ResourceLoader.fileSystem.exists("settings.json")) {
|
||||
var settingsExists = false;
|
||||
#if hl
|
||||
settingsExists = ResourceLoader.fileSystem.exists("settings.json");
|
||||
#end
|
||||
#if js
|
||||
var localStorage = js.Browser.getLocalStorage();
|
||||
if (localStorage != null) {
|
||||
settingsExists = localStorage.getItem("MBHaxeSettings") != null;
|
||||
}
|
||||
#end
|
||||
|
||||
if (settingsExists) {
|
||||
#if hl
|
||||
var json = Json.parse(ResourceLoader.fileSystem.get("settings.json").getText());
|
||||
#end
|
||||
#if js
|
||||
var json = Json.parse(localStorage.getItem("MBHaxeSettings"));
|
||||
#end
|
||||
var highScoreData:DynamicAccess<Array<Score>> = json.highScores;
|
||||
for (key => value in highScoreData) {
|
||||
highScores.set(key, value);
|
||||
|
|
@ -139,8 +161,10 @@ class Settings {
|
|||
|
||||
public static function init() {
|
||||
load();
|
||||
#if hl
|
||||
Window.getInstance().resize(optionsSettings.screenWidth, optionsSettings.screenHeight);
|
||||
Window.getInstance().displayMode = optionsSettings.isFullScreen ? FullscreenResize : Windowed;
|
||||
#end
|
||||
// @:privateAccess Window.getInstance().window.center();
|
||||
Window.getInstance().addResizeEvent(() -> {
|
||||
var wnd = Window.getInstance();
|
||||
|
|
|
|||
|
|
@ -39,6 +39,5 @@ class DuctFan extends ForceObject {
|
|||
|
||||
var seffect = this.soundChannel.getEffect(Spatialization);
|
||||
seffect.position = this.getAbsPos().getPosition();
|
||||
seffect.referenceDistance = 5;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,6 +39,5 @@ class SmallDuctFan extends ForceObject {
|
|||
|
||||
var seffect = this.soundChannel.getEffect(Spatialization);
|
||||
seffect.position = this.getAbsPos().getPosition();
|
||||
seffect.referenceDistance = 5;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -57,6 +57,5 @@ class Tornado extends ForceObject {
|
|||
|
||||
var seffect = this.soundChannel.getEffect(Spatialization);
|
||||
seffect.position = this.getAbsPos().getPosition();
|
||||
seffect.referenceDistance = 5;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,8 +41,6 @@ class Trapdoor extends DtsObject {
|
|||
if (direction != 0 && direction != this.lastDirection) {
|
||||
// If the direction has changed, play the sound
|
||||
var ch = AudioManager.playSound(ResourceLoader.getAudio("data/sound/trapdooropen.wav"), this.getAbsPos().getPosition());
|
||||
var spat = ch.getEffect(Spatialization);
|
||||
spat.referenceDistance = 5;
|
||||
}
|
||||
|
||||
this.lastCompletion = currentCompletion;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue