Skip to content

Commit

Permalink
ADD #231 fade effect on win
Browse files Browse the repository at this point in the history
  • Loading branch information
mkraenz committed May 24, 2020
1 parent a77db4d commit 8e21e56
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 52 deletions.
1 change: 1 addition & 0 deletions src/dev-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const isProd = window.location.hostname !== "localhost";
export const DEV = isProd
? {}
: {
startInWinScene: false,
skipTitle: true,
showPaths: false,
loseDisabled: false,
Expand Down
101 changes: 52 additions & 49 deletions src/scenes/GoodEndScene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,57 +23,60 @@ export class GoodEndScene extends Scene {

public create(): void {
new BackgroundImage(this, "goodEnd").setAlpha(0.2);
const worldSavedText = getWorldSavedText(getLevel(this.registry));
const fursorger = "— Der Fürsorger —";
const turns = `Turns: ${this.turns || "unknown"}`;
const halfWidth = this.scale.width / 2;
const halfHeight = this.scale.height / 2;
const buttonHeight = halfHeight + 100;
const worldSavedTextComp = this.add
.text(halfWidth, halfHeight - 150, "", TextConfig.xl)
.setColor(Color.WhiteSilver)
.setOrigin(0.5);
this.sound.play("scribbling", { loop: true });
typeWriter(worldSavedText, worldSavedTextComp, () =>
this.events.emit("quote-scribbling-finished")
);

this.events.once("quote-scribbling-finished", () => {
this.sound.stopByKey("scribbling");
const fursorgerText = this.add
.text(halfWidth, halfHeight - 100, fursorger, TextConfig.md)
.setColor(Color.WhiteSilver)
.setOrigin(0.5)
.setAlpha(0);
const turnsText = this.add
.text(halfWidth, halfHeight, turns, TextConfig.lg)
this.cameras.main.fadeIn(200);
this.cameras.main.once("camerafadeincomplete", () => {
const worldSavedText = getWorldSavedText(getLevel(this.registry));
const fursorger = "— Der Fürsorger —";
const turns = `Turns: ${this.turns || "unknown"}`;
const halfWidth = this.scale.width / 2;
const halfHeight = this.scale.height / 2;
const buttonHeight = halfHeight + 120;
const worldSavedTextComp = this.add
.text(halfWidth, halfHeight - 80, "", TextConfig.xl)
.setColor(Color.WhiteSilver)
.setOrigin(0.5)
.setAlpha(0);
const xCenterOffset = 125;
const restartButton = RestartButton(
this,
() => this.startMainScene(false),
halfWidth - xCenterOffset,
buttonHeight
).setAlpha(0);
const nextLevelButton = NextLevelButton(
this,
() => this.startMainScene(true),
halfWidth + xCenterOffset,
buttonHeight
).setAlpha(0);
.setOrigin(0.5);
this.sound.play("scribbling", { loop: true });
typeWriter(worldSavedText, worldSavedTextComp, () =>
this.events.emit("quote-scribbling-finished")
);

this.events.once("quote-scribbling-finished", () => {
this.sound.stopByKey("scribbling");
const fursorgerText = this.add
.text(halfWidth, halfHeight - 40, fursorger, TextConfig.md)
.setColor(Color.WhiteSilver)
.setOrigin(0.5)
.setAlpha(0);
const turnsText = this.add
.text(halfWidth, halfHeight + 20, turns, TextConfig.lg)
.setColor(Color.WhiteSilver)
.setOrigin(0.5)
.setAlpha(0);
const xCenterOffset = 100;
const restartButton = RestartButton(
this,
() => this.startMainScene(false),
halfWidth - xCenterOffset,
buttonHeight
).setAlpha(0);
const nextLevelButton = NextLevelButton(
this,
() => this.startMainScene(true),
halfWidth + xCenterOffset,
buttonHeight
).setAlpha(0);

this.tweens.add({
targets: [
fursorgerText,
turnsText,
restartButton,
nextLevelButton,
],
ease: "Cubic",
alpha: 1,
duration: 1500,
this.tweens.add({
targets: [
fursorgerText,
turnsText,
restartButton,
nextLevelButton,
],
ease: "Cubic",
alpha: 1,
duration: 1500,
});
});
});
}
Expand Down
5 changes: 4 additions & 1 deletion src/scenes/LoadingScene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { DEV } from "../dev-config";
import { setLevel } from "../registry/level";
import { Color, toHex } from "../styles/Color";
import { setDefaultTextStyle, TextConfig } from "../styles/Text";
import { GoodEndScene } from "./GoodEndScene";
import { MainScene } from "./mainScene";
import { TitleScene } from "./TitleScene";

Expand Down Expand Up @@ -121,7 +122,9 @@ export class LoadingScene extends Scene {
this.load.on("progress", this.getProgressBarFiller(progressBar));
this.load.on("fileprogress", this.getAssetTextWriter(assetText));
this.load.on("complete", () => {
if (DEV.skipTitle) {
if (DEV.startInWinScene) {
this.scene.add("GoodEndScene", GoodEndScene, true);
} else if (DEV.skipTitle) {
this.scene.add("MainScene", MainScene, true);
} else {
this.scene.add("TitleScene", TitleScene, true);
Expand Down
7 changes: 5 additions & 2 deletions src/scenes/mainScene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,11 @@ export class MainScene extends Scene {
sceneClass: new (name: string) => Scene,
data?: { [key: string]: {} }
) {
this.scene.add(key, sceneClass, true, data);
this.scene.remove("MainScene");
this.cameras.main.once("camerafadeoutcomplete", () => {
this.scene.add(key, sceneClass, true, data);
this.scene.remove(this);
});
this.cameras.main.fadeOut(100);
}

private toggleLevel(selectedLevel?: number) {
Expand Down

0 comments on commit 8e21e56

Please sign in to comment.