From fa681da31099f6a982670d9496cb405b074524e1 Mon Sep 17 00:00:00 2001 From: Yoshman29 Date: Fri, 7 Oct 2022 19:20:31 +0200 Subject: [PATCH] stages now works without xmls --- assets/data/stages/philly.hx | 72 ++++++++++++++++ buildnumber.txt | 2 +- source/funkin/game/PlayState.hx | 26 +++--- source/funkin/game/Stage.hx | 140 ++++++++++++++++---------------- 4 files changed, 159 insertions(+), 81 deletions(-) diff --git a/assets/data/stages/philly.hx b/assets/data/stages/philly.hx index 7403ddd5..51cc74cd 100644 --- a/assets/data/stages/philly.hx +++ b/assets/data/stages/philly.hx @@ -1,4 +1,9 @@ +import funkin.game.PlayState; + +// phillyTrain is automatically added by Stage.hx + var curColor:Int = 0; +var trainSound:FlxSound; var colors = [ 0xFF31A2FD, 0xFF31FD8C, @@ -6,9 +11,16 @@ var colors = [ 0xFFFD4531, 0xFFFBA633 ]; +var trainMoving:Bool = false; +var trainFrameTiming:Float = 0; +var trainCars:Int = 8; +var trainFinishing:Bool = false; +var trainCooldown:Int = 0; function create() { + // defaultCamZoom = 0.5; light.color = colors[curColor]; + trainSound = FlxG.sound.load(Paths.sound("train_passes")); } function beatHit(curBeat:Int) { @@ -19,6 +31,15 @@ function beatHit(curBeat:Int) { curColor = newColor; light.color = colors[curColor]; } + + if (!trainMoving) + trainCooldown += 1; + + if (curBeat % 8 == 4 && FlxG.random.bool(30) && !trainMoving && trainCooldown > 8 && !trainSound.playing) + { + trainCooldown = FlxG.random.int(-4, 0); + trainStart(); + } } function update(elapsed:Float) { @@ -26,4 +47,55 @@ function update(elapsed:Float) { light.alpha = 1 - (FlxEase.cubeIn((curBeatFloat / 4) % 1) * 0.85); else light.alpha = 0; + + if (trainMoving) { + updateTrainPos(); + } +} + +function trainStart():Void +{ + trainMoving = true; + if (!trainSound.playing) + trainSound.play(true); +} + +var startedMoving:Bool = false; + +function updateTrainPos():Void +{ + if (trainSound.time >= 4700) + { + startedMoving = true; + gf.playAnim('hairBlow'); + } + + if (startedMoving) + { + phillyTrain.velocity.x = -400 * 24; + if (phillyTrain.x < -2000 && !trainFinishing) + { + phillyTrain.x = -1150; + trainCars -= 1; + + if (trainCars <= 0) + trainFinishing = true; + } + + if (phillyTrain.x < -4000 && trainFinishing) + trainReset(); + } +} + +function trainReset():Void +{ + gf.playAnim('hairFall'); + phillyTrain.x = FlxG.width + 200; + trainMoving = false; + // trainSound.stop(); + // trainSound.time = 0; + trainCars = 8; + trainFinishing = false; + startedMoving = false; + phillyTrain.velocity.x = 0; } \ No newline at end of file diff --git a/buildnumber.txt b/buildnumber.txt index e0d1ea1e..274ccca8 100644 --- a/buildnumber.txt +++ b/buildnumber.txt @@ -1 +1 @@ -205 \ No newline at end of file +209 \ No newline at end of file diff --git a/source/funkin/game/PlayState.hx b/source/funkin/game/PlayState.hx index 1cb40a9c..2dc89397 100644 --- a/source/funkin/game/PlayState.hx +++ b/source/funkin/game/PlayState.hx @@ -91,6 +91,7 @@ class PlayState extends MusicBeatState public var cpuStrums:FlxTypedGroup; public var camZooming:Bool = false; + public var camZoomingInterval:Int = 4; public var curSong:String = ""; public var curStage:String = ""; @@ -777,8 +778,9 @@ class PlayState extends MusicBeatState // FlxG.watch.addQuick('VOL', vocals.amplitudeLeft); // FlxG.watch.addQuick('VOLRight', vocals.amplitudeRight); - iconP1.setGraphicSize(Std.int(FlxMath.lerp(150, iconP1.width, 0.50))); - iconP2.setGraphicSize(Std.int(FlxMath.lerp(150, iconP2.width, 0.50))); + // TODO: FPS-compatible lerping + iconP1.scale.set(FlxMath.lerp(iconP1.scale.x, 1, 0.33), FlxMath.lerp(iconP1.scale.y, 1, 0.33)); + iconP2.scale.set(FlxMath.lerp(iconP2.scale.x, 1, 0.33), FlxMath.lerp(iconP2.scale.y, 1, 0.33)); iconP1.updateHitbox(); iconP2.updateHitbox(); @@ -1336,6 +1338,7 @@ class PlayState extends MusicBeatState { if (!note.wasGoodHit) { + camZooming = true; if (note.mustPress) { // TODO: See TODO above scripts.call("onPlayerHit", [note]); @@ -1434,20 +1437,21 @@ class PlayState extends MusicBeatState } // HARDCODING FOR MILF ZOOMS! - if (curSong.toLowerCase() == 'milf' && curBeat >= 168 && curBeat < 200 && camZooming && FlxG.camera.zoom < 1.35) + // if (curSong.toLowerCase() == 'milf' && curBeat >= 168 && curBeat < 200 && camZooming && FlxG.camera.zoom < 1.35) + // { + // FlxG.camera.zoom += 0.015; + // camHUD.zoom += 0.03; + // } + + if (camZoomingInterval < 1) camZoomingInterval = 1; + if (camZooming && FlxG.camera.zoom < 1.35 && curBeat % camZoomingInterval == 0) { FlxG.camera.zoom += 0.015; camHUD.zoom += 0.03; } - if (camZooming && FlxG.camera.zoom < 1.35 && curBeat % 4 == 0) - { - FlxG.camera.zoom += 0.015; - camHUD.zoom += 0.03; - } - - iconP1.setGraphicSize(Std.int(iconP1.width + 30)); - iconP2.setGraphicSize(Std.int(iconP2.width + 30)); + iconP1.scale.set(1.2, 1.2); + iconP2.scale.set(1.2, 1.2); iconP1.updateHitbox(); iconP2.updateHitbox(); diff --git a/source/funkin/game/Stage.hx b/source/funkin/game/Stage.hx index b2530bf3..e97439eb 100644 --- a/source/funkin/game/Stage.hx +++ b/source/funkin/game/Stage.hx @@ -27,79 +27,81 @@ class Stage extends FlxBasic implements IBeatReceiver { } catch(e) { // TODO: handler trace(e.details()); - return; } - var spritesParentFolder = ""; - if (stageXML.has.zoom) { - var parsed:Null = Std.parseFloat(stageXML.att.zoom); - if (parsed != null) PlayState.instance.defaultCamZoom = parsed; - } - if (stageXML.has.folder) { - spritesParentFolder = stageXML.att.folder; - if (spritesParentFolder.charAt(spritesParentFolder.length-1) != "/") spritesParentFolder = spritesParentFolder + "/"; - } - if (stageXML.has.name) PlayState.instance.curStage = stageXML.att.name; + if (stageXML != null) { + + var spritesParentFolder = ""; + if (stageXML.has.zoom) { + var parsed:Null = Std.parseFloat(stageXML.att.zoom); + if (parsed != null) PlayState.instance.defaultCamZoom = parsed; + } + if (stageXML.has.folder) { + spritesParentFolder = stageXML.att.folder; + if (spritesParentFolder.charAt(spritesParentFolder.length-1) != "/") spritesParentFolder = spritesParentFolder + "/"; + } + if (stageXML.has.name) PlayState.instance.curStage = stageXML.att.name; + + for(node in stageXML.elements) { + switch(node.name) { + case "sprite" | "spr" | "sparrow": + var spr = new FlxSprite(); + spr.antialiasing = true; + if (!node.has.sprite || !node.has.name || !node.has.x || !node.has.y) continue; - for(node in stageXML.elements) { - switch(node.name) { - case "sprite" | "spr" | "sparrow": - var spr = new FlxSprite(); - spr.antialiasing = true; - if (!node.has.sprite || !node.has.name || !node.has.x || !node.has.y) continue; - - if (Assets.exists(Paths.file('images/$spritesParentFolder${node.att.sprite}', TEXT))) { - spr.frames = Paths.getSparrowAtlas('$spritesParentFolder${node.att.sprite}'); - } else { - spr.loadGraphic(Paths.image('$spritesParentFolder${node.att.sprite}')); - } - var x:Null = Std.parseFloat(node.att.x); - var y:Null = Std.parseFloat(node.att.y); - if (x != null) spr.x = x; - if (y != null) spr.y = y; - if (node.has.scroll) { - var scroll:Null = Std.parseFloat(node.att.scroll); - if (scroll != null) spr.scrollFactor.set(scroll, scroll); - } - if (node.has.scale) { - var scale:Null = Std.parseFloat(node.att.scale); - if (scale != null) spr.scale.set(scale, scale); - } - if (node.has.updateHitbox && node.att.updateHitbox == "true") spr.updateHitbox(); - - for(anim in node.nodes.anim) CoolUtil.addXMLAnimation(spr, anim); - - stageSprites.set(node.att.name, spr); - PlayState.instance.add(spr); - case "boyfriend" | "bf": - if (node.has.x) { + if (Assets.exists(Paths.file('images/$spritesParentFolder${node.att.sprite}', TEXT))) { + spr.frames = Paths.getSparrowAtlas('$spritesParentFolder${node.att.sprite}'); + } else { + spr.loadGraphic(Paths.image('$spritesParentFolder${node.att.sprite}')); + } var x:Null = Std.parseFloat(node.att.x); - if (x != null) PlayState.instance.boyfriend.x = x; - } - if (node.has.y) { var y:Null = Std.parseFloat(node.att.y); - if (y != null) PlayState.instance.boyfriend.y = y; - } - PlayState.instance.add(PlayState.instance.boyfriend); - case "girlfriend" | "gf": - if (node.has.x) { - var x:Null = Std.parseFloat(node.att.x); - if (x != null) PlayState.instance.gf.x = x; - } - if (node.has.y) { - var y:Null = Std.parseFloat(node.att.y); - if (y != null) PlayState.instance.gf.y = y; - } - PlayState.instance.add(PlayState.instance.gf); - case "dad" | "opponent": - if (node.has.x) { - var x:Null = Std.parseFloat(node.att.x); - if (x != null) PlayState.instance.dad.x = x; - } - if (node.has.y) { - var y:Null = Std.parseFloat(node.att.y); - if (y != null) PlayState.instance.dad.y = y; - } - PlayState.instance.add(PlayState.instance.dad); + if (x != null) spr.x = x; + if (y != null) spr.y = y; + if (node.has.scroll) { + var scroll:Null = Std.parseFloat(node.att.scroll); + if (scroll != null) spr.scrollFactor.set(scroll, scroll); + } + if (node.has.scale) { + var scale:Null = Std.parseFloat(node.att.scale); + if (scale != null) spr.scale.set(scale, scale); + } + if (node.has.updateHitbox && node.att.updateHitbox == "true") spr.updateHitbox(); + + for(anim in node.nodes.anim) CoolUtil.addXMLAnimation(spr, anim); + + stageSprites.set(node.att.name, spr); + PlayState.instance.add(spr); + case "boyfriend" | "bf": + if (node.has.x) { + var x:Null = Std.parseFloat(node.att.x); + if (x != null) PlayState.instance.boyfriend.x = x; + } + if (node.has.y) { + var y:Null = Std.parseFloat(node.att.y); + if (y != null) PlayState.instance.boyfriend.y = y; + } + PlayState.instance.add(PlayState.instance.boyfriend); + case "girlfriend" | "gf": + if (node.has.x) { + var x:Null = Std.parseFloat(node.att.x); + if (x != null) PlayState.instance.gf.x = x; + } + if (node.has.y) { + var y:Null = Std.parseFloat(node.att.y); + if (y != null) PlayState.instance.gf.y = y; + } + PlayState.instance.add(PlayState.instance.gf); + case "dad" | "opponent": + if (node.has.x) { + var x:Null = Std.parseFloat(node.att.x); + if (x != null) PlayState.instance.dad.x = x; + } + if (node.has.y) { + var y:Null = Std.parseFloat(node.att.y); + if (y != null) PlayState.instance.dad.y = y; + } + PlayState.instance.add(PlayState.instance.dad); + } } } stageScript = Script.create(Paths.script('data/stages/$stage'));