class Example extends Phaser.Scene {
this.load.setBaseURL("https://assets.codepen.io/9367036/");
this.load.image("morning", "backyard_morning.jpg");
this.load.image("npc2neutral", "Character+01+Class+03+-+Smile.png");
this.load.image("npc2blush", "Character+01+Class+03+-+Blush.png");
this.load.image("npc2sad", "Character+01+Class+03+-+Sad.png");
this.load.image("npc1neutral", "Character+04+Class+03+-+Smile.png");
this.load.image("npc1blush", "Character+04+Class+03+-+Blush.png");
this.load.image("npc1sad", "Character+04+Class+03+-Panic.png");
let savedState = localStorage.getItem("gameState");
let gameState = savedState ? JSON.parse(savedState) : undefined;
let background = this.add.image(0, 0, "morning").setOrigin(0, 0);
background.displayWidth = config.width;
background.displayHeight = config.height;
let buttonGraphics = this.add.graphics();
buttonGraphics.fillStyle(0xffffff, 0.8);
buttonGraphics.fillRoundedRect(
let saveButton = this.add
.text(0, -rectHeight / 2 + 12, "Sauvegarder", {
let buttonContainer = this.add.container(config.width / 2, 35, [
buttonContainer.setSize(rectWidth, rectHeight);
buttonContainer.setInteractive({ useHandCursor: true });
buttonContainer.on("pointerdown", (pointer, localX, localY, event) => {
this.dialogueIndex = gameState ? gameState.dialogueIndex : 0;
let dialogGraphics = this.add.graphics();
let dialogWidth = config.width * 0.8;
let dialogX = config.width * 0.1;
let dialogY = config.height - 120;
dialogGraphics.fillStyle(0x000000, 0.7);
.fillRoundedRect(dialogX, dialogY, dialogWidth, dialogHeight, 10)
this.dialogText = this.add
.text(dialogX + 20, dialogY + 20, "", {
wordWrap: { width: dialogWidth - 40 }
this.input.on("pointerdown", () => {
this.dialogueIndex = (this.dialogueIndex + 1) % dialogue.length;
.image(config.width, config.height, "npc1neutral")
x: this.npc1.x - this.npc1.displayWidth * 0.825,
this.npc1.setTexture(gameState.npc1Expression || "npc1neutral");
.image(0, config.height, "npc2neutral")
x: this.npc2.x + this.npc2.displayWidth * 0.825,
this.npc2.setTexture(gameState.npc2Expression || "npc2neutral");
this.currentNpc = undefined;
let currentDialogue = dialogue[this.dialogueIndex];
let character = currentDialogue.npc === "npc1" ? this.npc1 : this.npc2;
character.setTexture(`${currentDialogue.npc}${currentDialogue.expression}`);
if (this.currentNpc && this.currentNpc != character) {
targets: this.currentNpc,
this.currentNpc = character;
let textColor = currentDialogue.npc === "npc1" ? "#C7D3CD" : "#C7BBDE";
let npcName = currentDialogue.npc === "npc1" ? "Elinora" : "Morwenna";
this.dialogText.setColor(textColor);
this.dialogText.setText(`${npcName}\n${currentDialogue.text}`);
dialogueIndex: this.dialogueIndex,
npc1Expression: this.npc1.texture.key,
npc2Expression: this.npc2.texture.key
localStorage.setItem("gameState", JSON.stringify(gameState));
console.log("Partie sauvegardée");
const game = new Phaser.Game(config);
text: "Sinon, ça va toi?"
text: "Je vais bien oui. Toi aussi ?"
text: "Oui, je suis contente de te voir."
text: "Oh, moi aussi ! Cela fait longtemps."
"Par contre, j'espère juste que tout va s'arranger bientôt. Ça commence à être lourd."
text: "Je suis sûre que ça ira. Nous devons garder espoir."
text: "Alors, que dirais-tu d'aller prendre un café ?"