From 397a614bb72fdb62ba2fc2fd7185c654a952efe4 Mon Sep 17 00:00:00 2001 From: RandomityGuy <31925790+RandomityGuy@users.noreply.github.com> Date: Tue, 22 Jun 2021 22:55:18 +0530 Subject: [PATCH] some endgamegui and bugfixes --- src/Main.hx | 2 +- src/MarbleGame.hx | 7 ++-- src/MarbleWorld.hx | 10 +++++ src/PathedInterior.hx | 10 ++--- src/gui/EndGameGui.hx | 87 +++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 107 insertions(+), 9 deletions(-) create mode 100644 src/gui/EndGameGui.hx diff --git a/src/Main.hx b/src/Main.hx index 5bc96f7c..a4b1378c 100644 --- a/src/Main.hx +++ b/src/Main.hx @@ -15,7 +15,7 @@ class Main extends hxd.App { super.init(); marbleGame = new MarbleGame(s2d, s3d); - marbleGame.canvas.setContent(new MainMenuGui()); + MarbleGame.canvas.setContent(new MainMenuGui()); // world = new MarbleWorld(s3d, s2d, mission); // world.init(); diff --git a/src/MarbleGame.hx b/src/MarbleGame.hx index f6e527f9..532d26dd 100644 --- a/src/MarbleGame.hx +++ b/src/MarbleGame.hx @@ -12,7 +12,8 @@ import gui.Canvas; @:publicFields class MarbleGame { - var canvas:Canvas; + static var canvas:Canvas; + var world:MarbleWorld; var scene2d:h2d.Scene; @@ -23,7 +24,7 @@ class MarbleGame { var exitGameDlg:ExitGameDlg; public function new(scene2d:h2d.Scene, scene:h3d.scene.Scene) { - this.canvas = new Canvas(scene2d, cast this); + canvas = new Canvas(scene2d, cast this); this.scene = scene; this.scene2d = scene2d; } @@ -70,7 +71,7 @@ class MarbleGame { } public function playMission(mission:Mission) { - this.canvas.clearContent(); + canvas.clearContent(); mission.load(); world = new MarbleWorld(scene, scene2d, mission); world.init(); diff --git a/src/MarbleWorld.hx b/src/MarbleWorld.hx index 0d7c9a68..6d2d2279 100644 --- a/src/MarbleWorld.hx +++ b/src/MarbleWorld.hx @@ -1,5 +1,7 @@ package src; +import src.MarbleGame; +import gui.EndGameGui; import sdl.Cursor; import src.ForceObject; import h3d.scene.pbr.DirLight; @@ -782,9 +784,17 @@ class MarbleWorld extends Scheduler { this.marble.camera.finish = true; this.finishYaw = this.marble.camera.CameraYaw; this.finishPitch = this.marble.camera.CameraPitch; + displayAlert("Congratulations! You've finished!"); + this.schedule(this.timeState.currentAttemptTime + 2, () -> cast showFinishScreen()); } } + function showFinishScreen() { + MarbleGame.canvas.pushDialog(new EndGameGui()); + this.setCursorLock(false); + return 0; + } + public function pickUpPowerUp(powerUp:PowerUp) { if (this.marble.heldPowerup == powerUp) return false; diff --git a/src/PathedInterior.hx b/src/PathedInterior.hx index fadd23c3..67826d27 100644 --- a/src/PathedInterior.hx +++ b/src/PathedInterior.hx @@ -192,7 +192,8 @@ class PathedInterior extends InteriorObject { function computeDuration() { var total = 0.0; - for (marker in markerData) { + for (i in 0...(markerData.length - 1)) { + var marker = markerData[i]; total += marker.msToNext; } this.duration = total; @@ -211,7 +212,8 @@ class PathedInterior extends InteriorObject { return Util.adjustedMod(this.currentTime + (externalTime - this.changeTime) * direction, this.duration); } else { var dur = Math.abs(this.currentTime - this.targetTime); - var compvarion = Util.clamp(dur > 0 ? (externalTime - this.changeTime) / dur : 1, 0, 1); + + var compvarion = Util.clamp(dur != 0 ? (externalTime - this.changeTime) / dur : 1, 0, 1); return Util.clamp(Util.lerp(this.currentTime, this.targetTime, compvarion), 0, this.duration); } } @@ -234,8 +236,6 @@ class PathedInterior extends InteriorObject { mat.scale(this.baseScale.x, this.baseScale.y, this.baseScale.z); mat.setPosition(this.basePosition); return mat; - } else { - m1 = this.markerData[0]; } // Find the two markers in question var currentEndTime = m1.msToNext; @@ -253,7 +253,7 @@ class PathedInterior extends InteriorObject { var m2Time = currentEndTime; var duration = m2Time - m1Time; var position:Vector = null; - var compvarion = Util.clamp(duration > 0 ? (time - m1Time) / duration : 1, 0, 1); + var compvarion = Util.clamp(duration != 0 ? (time - m1Time) / duration : 1, 0, 1); if (m1.smoothingType == "Accelerate") { // A simple easing function compvarion = Math.sin(compvarion * Math.PI - (Math.PI / 2)) * 0.5 + 0.5; diff --git a/src/gui/EndGameGui.hx b/src/gui/EndGameGui.hx new file mode 100644 index 00000000..95ef93b9 --- /dev/null +++ b/src/gui/EndGameGui.hx @@ -0,0 +1,87 @@ +package gui; + +import h2d.filter.DropShadow; +import hxd.res.BitmapFont; +import h3d.Vector; +import src.ResourceLoader; + +class EndGameGui extends GuiControl { + public function new() { + super(); + this.horizSizing = Width; + this.vertSizing = Height; + this.position = new Vector(0, 0); + this.extent = new Vector(640, 480); + + function loadButtonImages(path:String) { + var normal = ResourceLoader.getImage('${path}_n.png').toTile(); + var hover = ResourceLoader.getImage('${path}_h.png').toTile(); + var pressed = ResourceLoader.getImage('${path}_d.png').toTile(); + return [normal, hover, pressed]; + } + + var pg = new GuiImage(ResourceLoader.getImage("data/ui/play/playgui.png").toTile()); + pg.horizSizing = Center; + pg.vertSizing = Center; + pg.position = new Vector(77, 9); + pg.extent = new Vector(485, 461); + + var continueButton = new GuiButton(loadButtonImages("data/ui/endgame/continue")); + continueButton.horizSizing = Right; + continueButton.vertSizing = Bottom; + continueButton.position = new Vector(333, 386); + continueButton.extent = new Vector(113, 47); + + var restartButton = new GuiButton(loadButtonImages("data/ui/endgame/replay")); + restartButton.horizSizing = Right; + restartButton.vertSizing = Bottom; + restartButton.position = new Vector(51, 388); + restartButton.extent = new Vector(104, 48); + + var arial14fontdata = ResourceLoader.loader.load("data/font/Arial14.fnt"); + var arial14 = new BitmapFont(arial14fontdata.entry); + @:privateAccess arial14.loader = ResourceLoader.loader; + + var domcasual32fontdata = ResourceLoader.loader.load("data/font/DomCasual32px.fnt"); + var domcasual32 = new BitmapFont(domcasual32fontdata.entry); + @:privateAccess domcasual32.loader = ResourceLoader.loader; + + var expo50fontdata = ResourceLoader.loader.load("data/font/Expo50.fnt"); + var expo50 = new BitmapFont(expo50fontdata.entry); + @:privateAccess expo50.loader = ResourceLoader.loader; + + var expo32fontdata = ResourceLoader.loader.load("data/font/Expo32.fnt"); + var expo32 = new BitmapFont(expo32fontdata.entry); + @:privateAccess expo32.loader = ResourceLoader.loader; + + var congrats = new GuiText(expo50); + congrats.text.textColor = 0xffff00; + congrats.text.text = "Final Time:"; + congrats.text.filter = new DropShadow(1.414, 0.785, 0, 1, 0, 0.4, 1, true); + congrats.position = new Vector(43, 17); + congrats.extent = new Vector(208, 50); + pg.addChild(congrats); + + var finishMessage = new GuiText(expo32); + finishMessage.text.textColor = 0x00ff00; + finishMessage.text.text = "You've qualified!"; + finishMessage.text.filter = new DropShadow(1, 0.785, 0, 1, 0, 0.4, 1, true); + finishMessage.justify = Center; + finishMessage.position = new Vector(155, 65); + finishMessage.extent = new Vector(200, 100); + pg.addChild(finishMessage); + + var leftColumn = new GuiText(domcasual32); + leftColumn.text.textColor = 0x000000; + leftColumn.text.text = "Qualify Time:\nGold Time:\nElapsed Time:\nBonus Time:"; + leftColumn.text.filter = new DropShadow(1.414, 0.785, 0xffffff, 1, 0, 0.4, 1, true); + leftColumn.position = new Vector(108, 103); + leftColumn.extent = new Vector(208, 50); + pg.addChild(leftColumn); + + pg.addChild(continueButton); + pg.addChild(restartButton); + + this.addChild(pg); + } +}