Skip to content
Snippets Groups Projects
Commit b0b6534f authored by Paolo.Brasolin's avatar Paolo.Brasolin
Browse files

feat: #fe atmosphere

parent 37299595
No related branches found
No related tags found
No related merge requests found
...@@ -16,11 +16,29 @@ const LAYERS = { ...@@ -16,11 +16,29 @@ const LAYERS = {
b11: "assets/background_layers/Layer_0000_9.png", b11: "assets/background_layers/Layer_0000_9.png",
}; };
// prettier-ignore
const HSL_COLORS = [
["#170048", "#fbb468"], // 06:00
["#ffefd6", "#b8ffc7"], // 09:00
["#ffffff", "#ffffff"], // 12:00
["#fff9b8", "#b0ff88"], // 15:00
["#def3ff", "#77e176"], // 18:00
["#f490ff", "#fdbf7d"], // 21:00
["#474095", "#2d912d"], // 00:00
["#ff1111", "#ff9bc0"], // 03:00
]
const COLORS = HSL_COLORS.map((pair) =>
pair.map(Phaser.Display.Color.HexStringToColor),
);
export default class BackgroundScene extends Phaser.Scene { export default class BackgroundScene extends Phaser.Scene {
layers: Phaser.GameObjects.TileSprite[]; layers: Phaser.GameObjects.TileSprite[];
atmosphere: Phaser.Tweens.Tween;
curtain: Phaser.GameObjects.Rectangle;
constructor() { constructor() {
super("head"); super("background");
this.layers = []; this.layers = [];
} }
...@@ -28,19 +46,92 @@ export default class BackgroundScene extends Phaser.Scene { ...@@ -28,19 +46,92 @@ export default class BackgroundScene extends Phaser.Scene {
Object.entries(LAYERS).forEach(([key, path]) => this.load.image(key, path)); Object.entries(LAYERS).forEach(([key, path]) => this.load.image(key, path));
} }
interpColor(
source: Phaser.Display.Color,
target: Phaser.Display.Color,
t: number,
) {
return Phaser.Display.Color.GetColor(
source.red + (target.red - source.red) * t,
source.green + (target.green - source.green) * t,
source.blue + (target.blue - source.blue) * t,
);
}
createBackground() { createBackground() {
const scale = this.cameras.main.height / LAYERS_HEIGHT; const scale = this.cameras.main.height / LAYERS_HEIGHT;
const width = this.cameras.main.width / scale; const width = this.cameras.main.width / scale;
const height = this.cameras.main.height / scale; const height = this.cameras.main.height / scale;
Object.keys(LAYERS).forEach((textureKey) => { Object.keys(LAYERS).forEach((textureKey) => {
const tileSprite = this.add.tileSprite(0, 0, width, height, textureKey); const tileSprite = this.add.tileSprite(0, 0, width, height, textureKey);
tileSprite.setOrigin(0).setScale(scale); tileSprite.setOrigin(0).setScale(scale).setTint(
// NOTE: this is a bit lazy but meh.
this.interpColor(COLORS[0][0], COLORS[0][0], 0),
this.interpColor(COLORS[0][0], COLORS[0][0], 0),
this.interpColor(COLORS[0][1], COLORS[0][1], 0),
this.interpColor(COLORS[0][1], COLORS[0][1], 0),
);
this.layers.push(tileSprite); this.layers.push(tileSprite);
}); });
} }
createAtmosphere() {
this.atmosphere = this.tweens.addCounter({
paused: true,
from: 0,
to: 255 * (COLORS.length - 1),
duration: 20 * 60 * 1000, // 3000 * (COLORS.length - 1),
onUpdate: (tween) => {
const value = (tween.getValue() % 256) / 256;
const i = Math.floor(tween.getValue() / 256);
const f = (i + 1) % COLORS.length;
const topCol = this.interpColor(COLORS[i][0], COLORS[f][0], value);
const botCol = this.interpColor(COLORS[i][1], COLORS[f][1], value);
this.layers.forEach((layer) =>
layer.setTint(topCol, topCol, botCol, botCol),
);
},
});
}
createCurtain() {
this.curtain = this.add
.rectangle(
0,
0,
this.cameras.main.displayWidth,
this.cameras.main.displayHeight,
0x000000,
1,
)
.setAlpha(0)
.setOrigin(0, 0);
}
dropCurtain() {
this.tweens.add({
targets: this.curtain,
alpha: 1,
ease: "Linear",
delay: 0,
duration: 200,
});
}
liftCurtain() {
this.tweens.add({
targets: this.curtain,
alpha: 0,
ease: "Linear",
delay: 0,
duration: 200,
});
}
create() { create() {
this.createBackground(); this.createBackground();
this.createAtmosphere();
this.createCurtain();
// this.scale.displaySize.setAspectRatio( // this.scale.displaySize.setAspectRatio(
// this.cameras.main.width / this.cameras.main.height, // this.cameras.main.width / this.cameras.main.height,
// ); // );
......
...@@ -11,6 +11,7 @@ import * as Types from "../../../backend/src/types"; ...@@ -11,6 +11,7 @@ import * as Types from "../../../backend/src/types";
import Foe from "./foe"; import Foe from "./foe";
import Typewriter from "./typewriter"; import Typewriter from "./typewriter";
import HUD from "./hud"; import HUD from "./hud";
import BackgroundScene from "./background_scene";
const DEVICE_KEY = "OETZI/DEVICE_ID"; const DEVICE_KEY = "OETZI/DEVICE_ID";
...@@ -192,6 +193,7 @@ export default class FightScene extends Phaser.Scene { ...@@ -192,6 +193,7 @@ export default class FightScene extends Phaser.Scene {
} }
async create(data: { music: Phaser.Sound.BaseSound }) { async create(data: { music: Phaser.Sound.BaseSound }) {
(this.scene.get("background") as BackgroundScene).atmosphere.play();
this.musicSoftReplace( this.musicSoftReplace(
this.sound.add("bkg_main_1", { loop: true }), this.sound.add("bkg_main_1", { loop: true }),
data.music, data.music,
......
import "phaser"; import "phaser";
import BackgroundScene from "./background_scene";
export default class GameOverScene extends Phaser.Scene { export default class GameOverScene extends Phaser.Scene {
music!: Phaser.Sound.BaseSound; music!: Phaser.Sound.BaseSound;
...@@ -23,6 +24,10 @@ export default class GameOverScene extends Phaser.Scene { ...@@ -23,6 +24,10 @@ export default class GameOverScene extends Phaser.Scene {
} }
create(data: { music?: Phaser.Sound.BaseSound }) { create(data: { music?: Phaser.Sound.BaseSound }) {
(this.scene.get("background") as BackgroundScene).dropCurtain();
(this.scene.get("background") as BackgroundScene).atmosphere
.stop()
.restart();
this.musicHardReplace( this.musicHardReplace(
this.sound.add("bkg_failure", { loop: false }), this.sound.add("bkg_failure", { loop: false }),
data.music, data.music,
...@@ -65,6 +70,7 @@ export default class GameOverScene extends Phaser.Scene { ...@@ -65,6 +70,7 @@ export default class GameOverScene extends Phaser.Scene {
} }
startFight() { startFight() {
(this.scene.get("background") as BackgroundScene).liftCurtain();
this.scene.start("welcome", { music: this.music }); this.scene.start("welcome", { music: this.music });
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment