diff --git a/marblegame.hl b/marblegame.hl index 908e9964..1e03d26b 100644 Binary files a/marblegame.hl and b/marblegame.hl differ diff --git a/src/CameraController.hx b/src/CameraController.hx index 253cf8de..c19d065b 100644 --- a/src/CameraController.hx +++ b/src/CameraController.hx @@ -75,7 +75,7 @@ class CameraController extends Object { this.level = level; // level.scene.addEventListener(onEvent); // Sdl.setRelativeMouseMode(true); - level.scene.camera.fovY = 60; + level.scene.camera.fovY = Settings.optionsSettings.fov; lockCursor(); } diff --git a/src/InstanceManager.hx b/src/InstanceManager.hx index f62f7aed..528e4e78 100644 --- a/src/InstanceManager.hx +++ b/src/InstanceManager.hx @@ -56,7 +56,6 @@ class InstanceManager { // minfo.transparencymeshbatch.material.mainPass.setPassName(minfo.mesh.material.mainPass.name); minfo.transparencymeshbatch.shadersChanged = true; minfo.transparencymeshbatch.material.mainPass.enableLights = minfo.mesh.material.mainPass.enableLights; - minfo.transparencymeshbatch.material.receiveShadows = false; // minfo.transparencymeshbatch.material.mainPass.depthWrite = false; // if (dtsShader != null) { // dtsShader.currentOpacity = instance.gameObject.currentOpacity; diff --git a/src/Main.hx b/src/Main.hx index 7aef833e..b76e2377 100644 --- a/src/Main.hx +++ b/src/Main.hx @@ -63,6 +63,11 @@ class Main extends hxd.App { static function main() { // h3d.mat.PbrMaterialSetup.set(); + #if hl + sdl.Sdl.setGLOptions(3, 2, 24, 8, 1, 2); + sdl.Sdl.setHint("SDL_HINT_RENDER_SCALE_QUALITY", "1"); + #end + h3d.Engine.ANTIALIASING = 4; new Main(); } } diff --git a/src/MarbleGame.hx b/src/MarbleGame.hx index 5ff73140..b9f059d8 100644 --- a/src/MarbleGame.hx +++ b/src/MarbleGame.hx @@ -16,6 +16,8 @@ import gui.Canvas; class MarbleGame { static var canvas:Canvas; + static var instance:MarbleGame; + var world:MarbleWorld; var scene2d:h2d.Scene; @@ -29,6 +31,7 @@ class MarbleGame { canvas = new Canvas(scene2d, cast this); this.scene = scene; this.scene2d = scene2d; + MarbleGame.instance = this; #if js // Pause shit @@ -91,10 +94,7 @@ class MarbleGame { world.setCursorLock(false); exitGameDlg = new ExitGameDlg((sender) -> { canvas.popDialog(exitGameDlg); - paused = !paused; - world.dispose(); - world = null; - canvas.setContent(new PlayMissionGui()); + quitMission(); }, (sender) -> { canvas.popDialog(exitGameDlg); paused = !paused; @@ -113,6 +113,14 @@ class MarbleGame { } } + public function quitMission() { + world.setCursorLock(false); + paused = false; + world.dispose(); + world = null; + canvas.setContent(new PlayMissionGui()); + } + public function playMission(mission:Mission) { var musicFileName = [ 'data/sound/groovepolice.ogg', diff --git a/src/MarbleWorld.hx b/src/MarbleWorld.hx index 2801fec9..acba055f 100644 --- a/src/MarbleWorld.hx +++ b/src/MarbleWorld.hx @@ -265,6 +265,7 @@ class MarbleWorld extends Scheduler { this.marble.reset(); var euler = startquat.quat.toEuler(); + this.marble.camera.init(cast this); this.marble.camera.CameraYaw = euler.z + Math.PI / 2; this.marble.camera.CameraPitch = 0.45; this.marble.camera.oob = false; @@ -688,7 +689,6 @@ class MarbleWorld extends Scheduler { this.marbles.push(marble); marble.level = cast this; if (marble.controllable) { - marble.camera.init(cast this); marble.init(cast this); this.scene.addChild(marble.camera); this.marble = marble; @@ -739,7 +739,6 @@ class MarbleWorld extends Scheduler { var func = this.resourceLoadFuncs.pop(); func(); this.loadingGui.setProgress((1 - resourceLoadFuncs.length / _loadingLength)); - MarbleGame.canvas.render(scene2d); } else { if (!_ready) postInit(); diff --git a/src/Settings.hx b/src/Settings.hx index dc3c207b..45afe451 100644 --- a/src/Settings.hx +++ b/src/Settings.hx @@ -26,6 +26,7 @@ typedef OptionsSettings = { var musicVolume:Float; var soundVolume:Float; var vsync:Bool; + var fov:Int; } typedef ControlsSettings = { @@ -57,6 +58,7 @@ class Settings { shadows: false, musicVolume: 1, soundVolume: 0.7, + fov: 60, vsync: #if js true #end #if hl false @@ -171,6 +173,8 @@ class Settings { highScores.set(key, value); } optionsSettings = json.options; + if (optionsSettings.fov == 0 #if js || optionsSettings.fov == null #end) + optionsSettings.fov = 60; controlsSettings = json.controls; progression = json.progression; highscoreName = json.highscoreName; diff --git a/src/gui/GuiProgress.hx b/src/gui/GuiProgress.hx index 1235fcb0..e367e47d 100644 --- a/src/gui/GuiProgress.hx +++ b/src/gui/GuiProgress.hx @@ -5,7 +5,10 @@ import h2d.Scene; import src.MarbleGame; class GuiProgress extends GuiControl { - public var progress:Float = 0; + public var progress(get, set):Float; + + var _progress:Float = 0; + public var progressColor:Int = 0x2C98A264; var progressRect:h2d.Graphics; @@ -45,4 +48,22 @@ class GuiProgress extends GuiControl { MarbleGame.canvas.scene2d.removeChild(progressRect); // Refresh "layer" } } + + function get_progress() { + return this._progress; + } + + function set_progress(value:Float) { + this._progress = value; + if (progressRect != null) { + var renderRect = getRenderRectangle(); + var rgb = progressColor >> 2; + var a = progressColor & 0xFF; + this.progressRect.clear(); + this.progressRect.beginFill(rgb, a / 0xFF); + this.progressRect.drawRect(0, 0, renderRect.extent.x * progress, renderRect.extent.y); + this.progressRect.endFill(); + } + return value; + } } diff --git a/src/gui/LoadingGui.hx b/src/gui/LoadingGui.hx index 88531055..ab9a1a2b 100644 --- a/src/gui/LoadingGui.hx +++ b/src/gui/LoadingGui.hx @@ -3,6 +3,7 @@ package gui; import hxd.res.BitmapFont; import h3d.Vector; import src.ResourceLoader; +import src.MarbleGame; class LoadingGui extends GuiImage { public var setProgress:Float->Void; @@ -51,6 +52,9 @@ class LoadingGui extends GuiImage { var cancelButton = new GuiButton(loadButtonImages("data/ui/loading/cancel")); cancelButton.position = new Vector(320, 233); cancelButton.extent = new Vector(88, 50); + cancelButton.pressedAction = (sender) -> { + MarbleGame.instance.quitMission(); + } var overlay = new GuiImage(ResourceLoader.getImage("data/ui/loading/overlay.png").toTile()); overlay.position = new Vector(151, 131); diff --git a/src/gui/PlayMissionGui.hx b/src/gui/PlayMissionGui.hx index fa253b0a..185bbdb9 100644 --- a/src/gui/PlayMissionGui.hx +++ b/src/gui/PlayMissionGui.hx @@ -26,6 +26,10 @@ class PlayMissionGui extends GuiImage { var currentList:Array; var setSelectedFunc:Int->Void; + var buttonHoldFunc:(dt:Float, mouseState:MouseState) -> Void; + + var buttonCooldown:Float = 0.5; + var maxButtonCooldown:Float = 0.5; public function new() { super(ResourceLoader.getImage("data/ui/background.jpg").toTile()); @@ -181,6 +185,35 @@ class PlayMissionGui extends GuiImage { } pmBox.addChild(pmNext); + buttonHoldFunc = (dt:Float, mouseState:MouseState) -> { + var prevBox = pmPrev.getRenderRectangle(); + var nextBox = pmNext.getRenderRectangle(); + + if (prevBox.inRect(mouseState.position) && mouseState.button == Key.MOUSE_LEFT) { + if (buttonCooldown <= 0) { + pmPrev.pressedAction(pmPrev); + buttonCooldown = maxButtonCooldown; + maxButtonCooldown *= 0.75; + } + } + + if (nextBox.inRect(mouseState.position) && mouseState.button == Key.MOUSE_LEFT) { + if (buttonCooldown <= 0) { + pmNext.pressedAction(pmNext); + buttonCooldown = maxButtonCooldown; + maxButtonCooldown *= 0.75; + } + } + + if (buttonCooldown > 0 && mouseState.button == Key.MOUSE_LEFT) + buttonCooldown -= dt; + + if (mouseState.button != Key.MOUSE_LEFT) { + maxButtonCooldown = 0.5; + buttonCooldown = maxButtonCooldown; + } + } + var pmBack = new GuiButton(loadButtonImages("data/ui/play/back")); pmBack.position = new Vector(102, 260); pmBack.extent = new Vector(79, 61); @@ -428,6 +461,8 @@ class PlayMissionGui extends GuiImage { public override function update(dt:Float, mouseState:MouseState) { super.update(dt, mouseState); + buttonHoldFunc(dt, mouseState); + if (Key.isPressed(Key.LEFT)) setSelectedFunc(currentSelection - 1); if (Key.isPressed(Key.RIGHT))