some endgamegui and bugfixes

This commit is contained in:
RandomityGuy 2021-06-22 22:55:18 +05:30
parent e5d1083ca1
commit 397a614bb7
5 changed files with 107 additions and 9 deletions

View file

@ -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();

View file

@ -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();

View file

@ -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;

View file

@ -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;

87
src/gui/EndGameGui.hx Normal file
View file

@ -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);
}
}