diff --git a/compile-js.hxml b/compile-js.hxml index d01a824b..ea0b1daa 100644 --- a/compile-js.hxml +++ b/compile-js.hxml @@ -3,6 +3,7 @@ -lib stb_ogg_sound --js marblegame.js -D windowSize=1280x720 +-D js-es=6 -D keep-inline-positions --main Main -debug \ No newline at end of file diff --git a/marblegame.hl b/marblegame.hl index 331b7983..9252b318 100644 Binary files a/marblegame.hl and b/marblegame.hl differ diff --git a/src/Marble.hx b/src/Marble.hx index 2435f721..993eda09 100644 --- a/src/Marble.hx +++ b/src/Marble.hx @@ -149,6 +149,7 @@ class Marble extends GameObject { public var contactEntities:Array = []; var queuedContacts:Array = []; + var appliedImpulses:Array = []; public var heldPowerup:PowerUp; public var lastContactNormal:Vector; @@ -204,6 +205,8 @@ class Marble extends GameObject { this.rollSound = AudioManager.playSound(ResourceLoader.getAudio("data/sound/rolling_hard.wav"), this.getAbsPos().getPosition(), true); this.slipSound = AudioManager.playSound(ResourceLoader.getAudio("data/sound/sliding.wav"), this.getAbsPos().getPosition(), true); + this.rollSound.volume = 0; + this.slipSound.volume = 0; this.shockabsorberSound = AudioManager.playSound(ResourceLoader.getAudio("data/sound/superbounceactive.wav"), null, true); this.shockabsorberSound.pause = true; this.superbounceSound = AudioManager.playSound(ResourceLoader.getAudio("data/sound/forcefield.wav"), null, true); @@ -620,17 +623,18 @@ class Marble extends GameObject { } function trailEmitter() { - var speed = this.velocity.length(); - if (this._minTrailVel > speed) { - if (this.trailEmitterNode != null) { - this.level.particleManager.removeEmitter(this.trailEmitterNode); - this.trailEmitterNode = null; - } - return; - } - if (this.trailEmitterNode == null) - this.trailEmitterNode = this.level.particleManager.createEmitter(trailParticleOptions, trailEmitterData, null, - () -> this.getAbsPos().getPosition()); + // Trails are bugged + // var speed = this.velocity.length(); + // if (this._minTrailVel > speed) { + // if (this.trailEmitterNode != null) { + // this.level.particleManager.removeEmitter(this.trailEmitterNode); + // this.trailEmitterNode = null; + // } + // return; + // } + // if (this.trailEmitterNode == null) + // this.trailEmitterNode = this.level.particleManager.createEmitter(trailParticleOptions, trailEmitterData, null, + // () -> this.getAbsPos().getPosition()); } function ReportBounce(pos:Vector, normal:Vector, speed:Float) { @@ -703,12 +707,13 @@ class Marble extends GameObject { rollSound.addEffect(new Pitch()); } - var pitch = scale; - #if js - // Apparently audio crashes the whole thing if pitch is less than 0.2 - if (pitch < 0.2) - pitch = 0.2; - #end + var pitch = Util.clamp(rollVel.length() / 15, 0, 1) * 0.75 + 0.75; + + // #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; } @@ -869,6 +874,11 @@ class Marble extends GameObject { this._contactTime += timeStep; } + for (impulse in appliedImpulses) { + this.velocity = this.velocity.add(impulse); + } + appliedImpulses = []; + piTime += timeStep; if (this.controllable) { for (interior in pathedInteriors) { @@ -1014,6 +1024,10 @@ class Marble extends GameObject { } } + public function applyImpulse(impulse:Vector) { + this.appliedImpulses.push(impulse); + } + public function enableSuperBounce(time:Float) { this.superBounceEnableTime = time; } diff --git a/src/Util.hx b/src/Util.hx index 89a552e5..22bd4637 100644 --- a/src/Util.hx +++ b/src/Util.hx @@ -136,12 +136,28 @@ class Util { } if (c == strLiteralToken) inString = true; - else if (StringTools.startsWith(str.substr(i), searchString)) + #if hl + else if (Util.startsWithFromIndex(str, searchString, i)) return i; + #end + #if js + else if ((cast str).startsWith(searchString, i)) + return i; + #end } return -1; } + public static function startsWithFromIndex(str:String, searchString:String, index:Int) { + if (index + searchString.length > str.length) + return false; + for (i in 0...searchString.length) { + if (searchString.charAt(i) != str.charAt(index + i)) + return false; + } + return true; + } + public static function indexIsInStringLiteral(str:String, index:Int, strLiteralToken = '"') { var inString = false; for (i in 0...str.length) { diff --git a/src/shapes/LandMine.hx b/src/shapes/LandMine.hx index ced7e60f..133f965f 100644 --- a/src/shapes/LandMine.hx +++ b/src/shapes/LandMine.hx @@ -125,6 +125,20 @@ class LandMine extends DtsObject { this.level.particleManager.createEmitter(landMineParticle, landMineParticleData, this.getAbsPos().getPosition()); this.level.particleManager.createEmitter(landMineSmokeParticle, landMineSmokeParticleData, this.getAbsPos().getPosition()); this.level.particleManager.createEmitter(landMineSparksParticle, landMineSparkParticleData, this.getAbsPos().getPosition()); + + var marble = this.level.marble; + var minePos = this.getAbsPos().getPosition(); + var off = marble.getAbsPos().getPosition().sub(minePos); + + var strength = computeExplosionStrength(off.length()); + + var impulse = off.normalized().multiply(strength); + marble.applyImpulse(impulse); + + // for (collider in this.colliders) { + // var hull:CollisionHull = cast collider; + // hull.force = strength; + // } } // Normally, we would add a light here, but that's too expensive for THREE, apparently. @@ -153,19 +167,6 @@ class LandMine extends DtsObject { this.setHide(true); } - if (this.isCollideable) { - var marble = this.level.marble; - var minePos = this.getAbsPos().getPosition(); - var off = marble.getAbsPos().getPosition().sub(minePos); - - var strength = computeExplosionStrength(off.length()); - - for (collider in this.colliders) { - var hull:CollisionHull = cast collider; - hull.force = strength; - } - } - var opacity = Util.clamp((timeState.timeSinceLoad - (this.disappearTime + 5)), 0, 1); this.setOpacity(opacity); }