From ab59e51e24270857383db12f6c112e6284cf24cd Mon Sep 17 00:00:00 2001 From: RandomityGuy <31925790+RandomityGuy@users.noreply.github.com> Date: Mon, 14 Nov 2022 00:51:27 +0530 Subject: [PATCH] easter egg and signs --- src/MarbleWorld.hx | 14 +++++++++++-- src/ResourceLoader.hx | 6 ++---- src/Settings.hx | 22 ++++++++++++++++++++ src/mis/MissionElement.hx | 1 + src/shapes/EasterEgg.hx | 44 +++++++++++++++++++++++++++++++++++++++ src/shapes/Magnet.hx | 1 + src/shapes/PowerUp.hx | 7 ++++++- src/shapes/Sign.hx | 37 ++++++++++++++++++++++++++++++++ src/shapes/SignCaution.hx | 7 ++++--- src/shapes/SignPlain.hx | 11 +++++----- src/shapes/TimeTravel.hx | 3 +++ 11 files changed, 138 insertions(+), 15 deletions(-) create mode 100644 src/shapes/EasterEgg.hx create mode 100644 src/shapes/Sign.hx diff --git a/src/MarbleWorld.hx b/src/MarbleWorld.hx index c802ab0e..17173cd6 100644 --- a/src/MarbleWorld.hx +++ b/src/MarbleWorld.hx @@ -1,5 +1,7 @@ package src; +import shapes.EasterEgg; +import shapes.Sign; import triggers.TeleportTrigger; import triggers.DestinationTrigger; import shapes.Nuke; @@ -600,6 +602,8 @@ class MarbleWorld extends Scheduler { shape = new TriangleBumper(); else if (dataBlockLowerCase == "helicopteritem") shape = new Helicopter(cast element); + else if (dataBlockLowerCase == "easteregg") + shape = new EasterEgg(cast element); else if (dataBlockLowerCase == "ductfan") shape = new DuctFan(); else if (dataBlockLowerCase == "smallductfan") @@ -616,7 +620,7 @@ class MarbleWorld extends Scheduler { shape = new ShockAbsorber(cast element); else if (dataBlockLowerCase == "superspeeditem") shape = new SuperSpeed(cast element); - else if (dataBlockLowerCase == "timetravelitem") + else if (dataBlockLowerCase == "timetravelitem" || dataBlockLowerCase == "timepenaltyitem") shape = new TimeTravel(cast element); else if (dataBlockLowerCase == "tornado") shape = new Tornado(); @@ -624,6 +628,8 @@ class MarbleWorld extends Scheduler { shape = new Trapdoor(); else if (dataBlockLowerCase == "oilslick") shape = new Oilslick(); + else if (dataBlockLowerCase == "arrow" || StringTools.startsWith(dataBlockLowerCase, "sign")) + shape = new Sign(cast element); else { onFinish(); return; @@ -682,6 +688,8 @@ class MarbleWorld extends Scheduler { shape = new TriangleBumper(); else if (dataBlockLowerCase == "helicopteritem") shape = new Helicopter(cast element); + else if (dataBlockLowerCase == "easteregg") + shape = new EasterEgg(cast element); else if (dataBlockLowerCase == "ductfan") shape = new DuctFan(); else if (dataBlockLowerCase == "smallductfan") @@ -698,7 +706,7 @@ class MarbleWorld extends Scheduler { shape = new ShockAbsorber(cast element); else if (dataBlockLowerCase == "superspeeditem") shape = new SuperSpeed(cast element); - else if (dataBlockLowerCase == "timetravelitem") + else if (dataBlockLowerCase == "timetravelitem" || dataBlockLowerCase == "timepenaltyitem") shape = new TimeTravel(cast element); else if (dataBlockLowerCase == "tornado") shape = new Tornado(); @@ -706,6 +714,8 @@ class MarbleWorld extends Scheduler { shape = new Trapdoor(); else if (dataBlockLowerCase == "oilslick") shape = new Oilslick(); + else if (dataBlockLowerCase == "arrow" || StringTools.startsWith(dataBlockLowerCase, "sign")) + shape = new Sign(cast element); else { onFinish(); return; diff --git a/src/ResourceLoader.hx b/src/ResourceLoader.hx index 10197fa4..39869cb0 100644 --- a/src/ResourceLoader.hx +++ b/src/ResourceLoader.hx @@ -266,9 +266,7 @@ class ResourceLoader { } public static function getTexture(path:String) { - #if (js || android) - path = StringTools.replace(path, "data/", ""); - #end + path = getProperFilepath(path); if (textureCache.exists(path)) return textureCache.get(path); if (fileSystem.exists(path)) { @@ -355,7 +353,7 @@ class ResourceLoader { var fname = Path.withoutDirectory(path).toLowerCase(); for (file in files) { var fname2 = file.name; - if (Path.withoutExtension(fname2).toLowerCase() == fname) + if (Path.withoutExtension(fname2).toLowerCase() == fname || fname2.toLowerCase() == fname) names.push(file.path); } return names; diff --git a/src/Settings.hx b/src/Settings.hx index 4a5300b0..4c8c7686 100644 --- a/src/Settings.hx +++ b/src/Settings.hx @@ -63,6 +63,8 @@ typedef TouchSettings = { class Settings { public static var highScores:Map> = []; + public static var easterEggs:Map = []; + public static var optionsSettings:OptionsSettings = { screenWidth: 1280, screenHeight: 720, @@ -153,14 +155,23 @@ class Settings { highscoreName: highscoreName }; var scoreCount = 0; + var eggCount = 0; for (key => value in highScores) { scoreCount++; } + for (key => value in easterEggs) { + eggCount++; + } #if hl if (scoreCount != 0) outputData.highScores = highScores; else outputData.highScores = {}; + if (eggCount != 0) { + outputData.easterEggs = easterEggs; + } else { + outputData.easterEggs = {}; + } #end #if js var kvps:Array = []; @@ -168,6 +179,11 @@ class Settings { kvps.push([key, value]); var jobj = js.lib.Object.fromEntries(kvps); outputData.highScores = jobj; + kvps = []; + for (key => value in easterEggs) + kvps.push([key, value]); + jobj = js.lib.Object.fromEntries(kvps); + outputData.easterEggs = jobj; #end var json = Json.stringify(outputData); #if (hl && !android) @@ -204,6 +220,12 @@ class Settings { for (key => value in highScoreData) { highScores.set(key, value); } + var easterEggData:DynamicAccess = json.easterEggs; + if (easterEggData != null) { + for (key => value in easterEggData) { + easterEggs.set(key, value); + } + } optionsSettings = json.options; if (optionsSettings.fov == 0 #if js || optionsSettings.fov == null #end) optionsSettings.fov = 60; diff --git a/src/mis/MissionElement.hx b/src/mis/MissionElement.hx index 233661af..31165b2b 100644 --- a/src/mis/MissionElement.hx +++ b/src/mis/MissionElement.hx @@ -157,6 +157,7 @@ class MissionElementItem extends MissionElementBase { var rotate:String; var showhelponpickup:String; var timebonus:Null; + var timepenalty:Null; public function new() { _type = MissionElementType.Item; diff --git a/src/shapes/EasterEgg.hx b/src/shapes/EasterEgg.hx new file mode 100644 index 00000000..904c14fc --- /dev/null +++ b/src/shapes/EasterEgg.hx @@ -0,0 +1,44 @@ +package shapes; + +import src.Settings; +import mis.MissionElement.MissionElementItem; +import src.ResourceLoader; + +class EasterEgg extends PowerUp { + public function new(element:MissionElementItem) { + super(element); + this.dtsPath = "data/shapes/items/easteregg.dts"; + this.isCollideable = false; + this.isTSStatic = false; + this.identifier = "EasterEgg"; + this.pickUpName = "Easter Egg"; + this.autoUse = true; + } + + public function pickUp():Bool { + var found:Bool = false; + if (Settings.easterEggs.exists(this.level.mission.path)) { + found = true; + } + if (!found) { + Settings.easterEggs.set(this.level.mission.path, this.level.timeState.currentAttemptTime); + this.pickupSound = ResourceLoader.getResource("data/sound/easter.wav", ResourceLoader.getAudio, this.soundResources); + this.customPickupMessage = "You found an Easter Egg!"; + } else { + this.pickupSound = ResourceLoader.getResource("data/sound/easterfound.wav", ResourceLoader.getAudio, this.soundResources); + this.customPickupMessage = "You already found this Easter Egg."; + } + + return true; + } + + public override function init(level:src.MarbleWorld, onFinish:() -> Void) { + super.init(level, () -> { + ResourceLoader.load("sound/easter.wav").entry.load(() -> { + ResourceLoader.load("data/sound/easterfound.wav").entry.load(onFinish); + }); + }); + } + + public function use(timeState:src.TimeState) {} +} diff --git a/src/shapes/Magnet.hx b/src/shapes/Magnet.hx index 8500bf73..8171c366 100644 --- a/src/shapes/Magnet.hx +++ b/src/shapes/Magnet.hx @@ -16,6 +16,7 @@ class Magnet extends ForceObject { this.isCollideable = true; this.isTSStatic = false; this.identifier = "Magnet"; + this.useInstancing = true; this.forceDatas = [ { forceType: ForceCone, diff --git a/src/shapes/PowerUp.hx b/src/shapes/PowerUp.hx index 4338883c..03c1fd47 100644 --- a/src/shapes/PowerUp.hx +++ b/src/shapes/PowerUp.hx @@ -35,6 +35,8 @@ abstract class PowerUp extends DtsObject { public var element:MissionElementItem; public var pickupSound:Sound; + var customPickupMessage:String = null; + public function new(element:MissionElementItem) { super(); this.isCollideable = false; @@ -54,7 +56,10 @@ abstract class PowerUp extends DtsObject { if (this.autoUse) this.use(timeState); - this.level.displayAlert('You picked up a ${this.pickUpName}!'); + if (customPickupMessage != null) + this.level.displayAlert(customPickupMessage); + else + this.level.displayAlert('You picked up a ${this.pickUpName}!'); if (this.element.showhelponpickup == "1" && !this.autoUse) this.level.displayHelp('Press to use the ${this.pickUpName}!'); diff --git a/src/shapes/Sign.hx b/src/shapes/Sign.hx new file mode 100644 index 00000000..04346214 --- /dev/null +++ b/src/shapes/Sign.hx @@ -0,0 +1,37 @@ +package shapes; + +import hxd.Direction; +import mis.MissionElement.MissionElementStaticShape; +import src.DtsObject; + +class Sign extends DtsObject { + public function new(element:MissionElementStaticShape) { + super(); + this.dtsPath = "data/shapes/signs/sign.dts"; + this.isCollideable = true; + this.useInstancing = true; + + var d = ""; + if (element.datablock.toLowerCase() != 'arrow') { + // Determine the direction to show + var direction = element.datablock.substring("Sign".length).toLowerCase(); + switch (direction) { + case "": + this.dtsPath = "data/shapes/signs/sign.dts"; + case "down": + this.dtsPath = "data/shapes/signs/signdown.dts"; + case "up": + this.dtsPath = "data/shapes/signs/signup.dts"; + case "side": + this.dtsPath = "data/shapes/signs/signside.dts"; + case "downside": + this.dtsPath = "data/shapes/signs/signdown-side.dts"; + case "upside": + this.dtsPath = "data/shapes/signs/signup-side.dts"; + } + d = direction; + } + + this.identifier = "Sign" + d; + } +} diff --git a/src/shapes/SignCaution.hx b/src/shapes/SignCaution.hx index cb83c9c1..7bcb1ee8 100644 --- a/src/shapes/SignCaution.hx +++ b/src/shapes/SignCaution.hx @@ -8,12 +8,13 @@ class SignCaution extends DtsObject { super(); this.dtsPath = "data/shapes/signs/cautionsign.dts"; this.isCollideable = true; + this.useInstancing = true; - var type = element.datablock.substring("SignCaution".length); + var type = element.datablock.substring("SignCaution".length).toLowerCase(); switch (type) { - case "Caution": + case "caution": this.matNameOverride.set("base.cautionsign", "caution.cautionsign"); - case "Danger": + case "danger": this.matNameOverride.set("base.cautionsign", "danger.cautionsign"); } this.identifier = "CautionSign" + type; diff --git a/src/shapes/SignPlain.hx b/src/shapes/SignPlain.hx index 22204a4b..7772fddc 100644 --- a/src/shapes/SignPlain.hx +++ b/src/shapes/SignPlain.hx @@ -9,17 +9,18 @@ class SignPlain extends DtsObject { this.dtsPath = "data/shapes/signs/plainsign.dts"; this.isCollideable = true; + this.useInstancing = true; // Determine the direction to show - var direction = element.datablock.substring("SignPlain".length); + var direction = element.datablock.substring("SignPlain".length).toLowerCase(); switch (direction) { - case "Right": + case "right": this.matNameOverride.set("base.plainsign", "right.plainsign"); - case "Left": + case "left": this.matNameOverride.set("base.plainsign", "left.plainsign"); - case "Up": + case "up": this.matNameOverride.set("base.plainsign", "up.plainsign"); - case "Down": + case "down": this.matNameOverride.set("base.plainsign", "down.plainsign"); } diff --git a/src/shapes/TimeTravel.hx b/src/shapes/TimeTravel.hx index e4b90584..73cdf777 100644 --- a/src/shapes/TimeTravel.hx +++ b/src/shapes/TimeTravel.hx @@ -19,6 +19,9 @@ class TimeTravel extends PowerUp { if (element.timebonus != null) { this.timeBonus = MisParser.parseNumber(element.timebonus) / 1000; } + if (element.timepenalty != null) { + this.timeBonus = -MisParser.parseNumber(element.timepenalty) / 1000; + } this.pickUpName = '${this.timeBonus} second Time ${this.timeBonus >= 0 ? 'Modifier' : 'Penalty'}'; this.cooldownDuration = 1e8;