mirror of
https://github.com/RandomityGuy/MBHaxe.git
synced 2026-04-27 13:11:42 +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) {
|
if (position != null) {
|
||||||
var audioSrc = new Spatialization();
|
var audioSrc = new Spatialization();
|
||||||
audioSrc.position = position;
|
audioSrc.position = position;
|
||||||
|
#if hl
|
||||||
|
audioSrc.referenceDistance = 5;
|
||||||
|
#end
|
||||||
|
#if js
|
||||||
|
audioSrc.referenceDistance = 4.5;
|
||||||
|
#end
|
||||||
ch.addEffect(audioSrc);
|
ch.addEffect(audioSrc);
|
||||||
}
|
}
|
||||||
return ch;
|
return ch;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function playShell() {
|
public static function playShell() {
|
||||||
#if js
|
|
||||||
return;
|
|
||||||
#end
|
|
||||||
AudioManager.manager.stopByName("music");
|
AudioManager.manager.stopByName("music");
|
||||||
var snd = ResourceLoader.getAudio("data/sound/shell.ogg");
|
var snd = ResourceLoader.getAudio("data/sound/shell.ogg");
|
||||||
if (snd == null)
|
if (snd == null)
|
||||||
|
|
@ -55,9 +58,6 @@ class AudioManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function playMusic(music:Sound) {
|
public static function playMusic(music:Sound) {
|
||||||
#if js
|
|
||||||
return;
|
|
||||||
#end
|
|
||||||
AudioManager.manager.stopByName("music");
|
AudioManager.manager.stopByName("music");
|
||||||
if (music == null)
|
if (music == null)
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -358,7 +358,6 @@ class DtsObject extends GameObject {
|
||||||
var keyframes = parseIfl(fullName);
|
var keyframes = parseIfl(fullName);
|
||||||
this.materialInfos.set(material, keyframes);
|
this.materialInfos.set(material, keyframes);
|
||||||
iflMaterial = true;
|
iflMaterial = true;
|
||||||
// TODO IFL SHIT
|
|
||||||
} else {
|
} else {
|
||||||
var texture:Texture = ResourceLoader.getTexture(fullName);
|
var texture:Texture = ResourceLoader.getTexture(fullName);
|
||||||
texture.wrap = Wrap.Repeat;
|
texture.wrap = Wrap.Repeat;
|
||||||
|
|
@ -377,11 +376,20 @@ class DtsObject extends GameObject {
|
||||||
// var dtsshader = new DtsTexture();
|
// var dtsshader = new DtsTexture();
|
||||||
// dtsshader.currentOpacity = 1;
|
// dtsshader.currentOpacity = 1;
|
||||||
// Make a 1x1 white texture
|
// Make a 1x1 white texture
|
||||||
|
#if hl
|
||||||
var bitmap = new hxd.BitmapData(1, 1);
|
var bitmap = new hxd.BitmapData(1, 1);
|
||||||
|
bitmap.lock();
|
||||||
bitmap.setPixel(0, 0, 0xFFFFFF);
|
bitmap.setPixel(0, 0, 0xFFFFFF);
|
||||||
bitmap.setPixel(1, 1, 0xFFFFFF);
|
bitmap.unlock();
|
||||||
var texture = new Texture(1, 1);
|
var texture = new Texture(1, 1);
|
||||||
texture.uploadBitmap(bitmap);
|
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;
|
material.texture = texture;
|
||||||
// dtsshader.texture = texture;
|
// dtsshader.texture = texture;
|
||||||
// material.mainPass.addShader(dtsshader);
|
// material.mainPass.addShader(dtsshader);
|
||||||
|
|
|
||||||
|
|
@ -669,11 +669,9 @@ class Marble extends GameObject {
|
||||||
function updateRollSound(contactPct:Float, slipAmount:Float) {
|
function updateRollSound(contactPct:Float, slipAmount:Float) {
|
||||||
var rSpat = rollSound.getEffect(Spatialization);
|
var rSpat = rollSound.getEffect(Spatialization);
|
||||||
rSpat.position = this.getAbsPos().getPosition();
|
rSpat.position = this.getAbsPos().getPosition();
|
||||||
rSpat.referenceDistance = 5;
|
|
||||||
|
|
||||||
var sSpat = slipSound.getEffect(Spatialization);
|
var sSpat = slipSound.getEffect(Spatialization);
|
||||||
sSpat.position = this.getAbsPos().getPosition();
|
sSpat.position = this.getAbsPos().getPosition();
|
||||||
sSpat.referenceDistance = 5;
|
|
||||||
|
|
||||||
var rollVel = bestContact != null ? this.velocity.sub(bestContact.velocity) : this.velocity;
|
var rollVel = bestContact != null ? this.velocity.sub(bestContact.velocity) : this.velocity;
|
||||||
var scale = rollVel.length();
|
var scale = rollVel.length();
|
||||||
|
|
@ -693,6 +691,11 @@ class Marble extends GameObject {
|
||||||
rollVolume = (1 - slipVolume) * rollVolume;
|
rollVolume = (1 - slipVolume) * rollVolume;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (rollVolume < 0)
|
||||||
|
rollVolume = 0;
|
||||||
|
if (slipVolume < 0)
|
||||||
|
slipVolume = 0;
|
||||||
|
|
||||||
rollSound.volume = rollVolume;
|
rollSound.volume = rollVolume;
|
||||||
slipSound.volume = slipVolume;
|
slipSound.volume = slipVolume;
|
||||||
|
|
||||||
|
|
@ -701,9 +704,11 @@ class Marble extends GameObject {
|
||||||
}
|
}
|
||||||
|
|
||||||
var pitch = scale;
|
var pitch = scale;
|
||||||
if (scale > 1.0)
|
#if js
|
||||||
pitch = 1.0;
|
// 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);
|
var rPitch = rollSound.getEffect(Pitch);
|
||||||
rPitch.value = pitch;
|
rPitch.value = pitch;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,7 @@ class MarbleGame {
|
||||||
this.scene2d = scene2d;
|
this.scene2d = scene2d;
|
||||||
|
|
||||||
#if js
|
#if js
|
||||||
|
// Pause shit
|
||||||
js.Browser.document.addEventListener('pointerlockchange', () -> {
|
js.Browser.document.addEventListener('pointerlockchange', () -> {
|
||||||
if (!paused && world != null) {
|
if (!paused && world != null) {
|
||||||
if (world.finishTime == 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
|
#end
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -120,11 +120,33 @@ class Settings {
|
||||||
#if hl
|
#if hl
|
||||||
File.saveContent("settings.json", json);
|
File.saveContent("settings.json", json);
|
||||||
#end
|
#end
|
||||||
|
#if js
|
||||||
|
var localStorage = js.Browser.getLocalStorage();
|
||||||
|
if (localStorage != null) {
|
||||||
|
localStorage.setItem("MBHaxeSettings", json);
|
||||||
|
}
|
||||||
|
#end
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function load() {
|
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());
|
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;
|
var highScoreData:DynamicAccess<Array<Score>> = json.highScores;
|
||||||
for (key => value in highScoreData) {
|
for (key => value in highScoreData) {
|
||||||
highScores.set(key, value);
|
highScores.set(key, value);
|
||||||
|
|
@ -139,8 +161,10 @@ class Settings {
|
||||||
|
|
||||||
public static function init() {
|
public static function init() {
|
||||||
load();
|
load();
|
||||||
|
#if hl
|
||||||
Window.getInstance().resize(optionsSettings.screenWidth, optionsSettings.screenHeight);
|
Window.getInstance().resize(optionsSettings.screenWidth, optionsSettings.screenHeight);
|
||||||
Window.getInstance().displayMode = optionsSettings.isFullScreen ? FullscreenResize : Windowed;
|
Window.getInstance().displayMode = optionsSettings.isFullScreen ? FullscreenResize : Windowed;
|
||||||
|
#end
|
||||||
// @:privateAccess Window.getInstance().window.center();
|
// @:privateAccess Window.getInstance().window.center();
|
||||||
Window.getInstance().addResizeEvent(() -> {
|
Window.getInstance().addResizeEvent(() -> {
|
||||||
var wnd = Window.getInstance();
|
var wnd = Window.getInstance();
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,5 @@ class DuctFan extends ForceObject {
|
||||||
|
|
||||||
var seffect = this.soundChannel.getEffect(Spatialization);
|
var seffect = this.soundChannel.getEffect(Spatialization);
|
||||||
seffect.position = this.getAbsPos().getPosition();
|
seffect.position = this.getAbsPos().getPosition();
|
||||||
seffect.referenceDistance = 5;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,5 @@ class SmallDuctFan extends ForceObject {
|
||||||
|
|
||||||
var seffect = this.soundChannel.getEffect(Spatialization);
|
var seffect = this.soundChannel.getEffect(Spatialization);
|
||||||
seffect.position = this.getAbsPos().getPosition();
|
seffect.position = this.getAbsPos().getPosition();
|
||||||
seffect.referenceDistance = 5;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -57,6 +57,5 @@ class Tornado extends ForceObject {
|
||||||
|
|
||||||
var seffect = this.soundChannel.getEffect(Spatialization);
|
var seffect = this.soundChannel.getEffect(Spatialization);
|
||||||
seffect.position = this.getAbsPos().getPosition();
|
seffect.position = this.getAbsPos().getPosition();
|
||||||
seffect.referenceDistance = 5;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -41,8 +41,6 @@ class Trapdoor extends DtsObject {
|
||||||
if (direction != 0 && direction != this.lastDirection) {
|
if (direction != 0 && direction != this.lastDirection) {
|
||||||
// If the direction has changed, play the sound
|
// If the direction has changed, play the sound
|
||||||
var ch = AudioManager.playSound(ResourceLoader.getAudio("data/sound/trapdooropen.wav"), this.getAbsPos().getPosition());
|
var ch = AudioManager.playSound(ResourceLoader.getAudio("data/sound/trapdooropen.wav"), this.getAbsPos().getPosition());
|
||||||
var spat = ch.getEffect(Spatialization);
|
|
||||||
spat.referenceDistance = 5;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.lastCompletion = currentCompletion;
|
this.lastCompletion = currentCompletion;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue