From 57f9c018b0709f99284d963eace1a9985f00fb2e Mon Sep 17 00:00:00 2001 From: printemps25 <124960699+printemps25@users.noreply.github.com> Date: Fri, 14 Apr 2023 13:52:38 -0400 Subject: [PATCH 1/4] Update GameScene.ts --- src/GameScene.ts | 215 +++++++++++++++++++++++------------------------ 1 file changed, 107 insertions(+), 108 deletions(-) diff --git a/src/GameScene.ts b/src/GameScene.ts index dc8a1dd..226df7c 100644 --- a/src/GameScene.ts +++ b/src/GameScene.ts @@ -1,114 +1,113 @@ import Phaser from 'phaser' - - export default class GameScene extends Phaser.Scene { - constructor() { - super("GameScene") - } - preload() { - this.load.image('bakery2','assets/bakery.png') - this.load.image('blue-liner', 'assets/liner-blue.png') - this.load.image('pink-liner', 'assets/liner-pink.png') - this.load.image('pink-frosting', 'assets/pink-frosting.png') - this.load.image('blue-frosting', 'assets/blue-frosting.png') - this.load.image('yellow-frosting', 'assets/yellow-frosting.png') - this.load.image('coin','assets/coin.png') - } - - create() { - this.add.image(545, 305,'bakery2'); - - const bluefrost = this.add.sprite(900, 320,'blue-frosting').setScale(.15).setInteractive(); - const pinkfrost = this.add.sprite(820, 320,'pink-frosting').setScale(.15).setInteractive(); - const yellowfrost = this.add.sprite(740, 320,'yellow-frosting').setScale(.15).setInteractive(); - const pinkliner = this.add.sprite(150, 570,'pink-liner').setScale(.5).setInteractive(); - const blueliner = this.add.sprite(250, 570,'blue-liner').setScale(.5).setInteractive(); - let coins = 0; - const coinImage = this.add.image(20, 20, 'coin').setScale(0.05); - const coinCounterText = this.add.text(40, 10, `x ${coins}`, { fontSize: '24px', fill: '#000' }); - - this.input.setDraggable(pinkfrost); - this.input.setDraggable(bluefrost); - this.input.setDraggable(yellowfrost); - this.input.setDraggable(pinkliner); - this.input.setDraggable(blueliner); - - pinkfrost.depth = 100 - bluefrost.depth = 100 - yellowfrost.depth = 100 - - - this.input.on('drag', function (pointer: any, gameObject: { x: any; y: any },dragX: any, dragY: any){ - gameObject.x = dragX; - gameObject.y = dragY; - }) - this.input.on('dragenter', function (pointer: any, gameObject: any, dropZone: any) { - - graphics.clear(); - graphics.lineStyle(2, 0x00ffff); - graphics.strokeRect(zone.x - zone.input.hitArea.width / 2, zone.y - zone.input.hitArea.height / 2, zone.input.hitArea.width, zone.input.hitArea.height); - - }); - this.input.on('dragleave', function (pointer: any, gameObject: any, dropZone: any) { - - graphics.clear(); - graphics.lineStyle(2, 0xffff00); - graphics.strokeRect(zone.x - zone.input.hitArea.width / 2, zone.y - zone.input.hitArea.height / 2, zone.input.hitArea.width, zone.input.hitArea.height); - - }); - this.input.on('drop', function (pointer: any, gameObject: { x: any; y: any; input: { enabled: boolean } }, dropZone: { x: any; y: any }) { - - gameObject.x = dropZone.x; - gameObject.y = dropZone.y; - - gameObject.input.enabled = true; - - }); - - this.input.on('dragend', function (pointer: any, gameObject: { x: any; input: { dragStartX: any; dragStartY: any }; y: any }, dropped: any) { - - if (!dropped) - { - gameObject.x = gameObject.input.dragStartX; - gameObject.y = gameObject.input.dragStartY; - } - - graphics.clear(); - graphics.lineStyle(2, 0xffff00); - graphics.strokeRect(zone.x - zone.input.hitArea.width / 2, zone.y - zone.input.hitArea.height / 2, zone.input.hitArea.width, zone.input.hitArea.height); - - }); - - const zone = this.add.zone(400, 350, 90, 70).setRectangleDropZone(90, 70); - const graphics = this.add.graphics(); - graphics.lineStyle(2, 0xffff00); - graphics.strokeRect(zone.x - zone.input.hitArea.width / 2, zone.y - zone.input.hitArea.height / 2, zone.input.hitArea.width, zone.input.hitArea.height); - const zone2 = this.add.zone(400, 275, 90, 70).setRectangleDropZone(90, 70); - const graphics2 = this.add.graphics(); - graphics2.lineStyle(2, 0xffff00); - graphics2.strokeRect(zone2.x - zone2.input.hitArea.width / 2, zone2.y - zone2.input.hitArea.height / 2, zone2.input.hitArea.width, zone2.input.hitArea.height); - - function updateCoinCounter() { - coins++; - coinCounterText.setText(`x ${coins}`); + constructor() { + super("GameScene") } - - this.input.on('drop', (pointer, gameObject, dropZone) => { - gameObject.x = dropZone.x; - gameObject.y = dropZone.y; - gameObject.input.enabled = true; - - if ((gameObject === pinkfrost || gameObject === bluefrost || gameObject === yellowfrost) && (dropZone === zone || dropZone === zone2)) { - updateCoinCounter(); + preload() { + this.load.image('bakery2', 'assets/bakery.png') + this.load.image('blue-liner', 'assets/liner-blue.png') + this.load.image('pink-liner', 'assets/liner-pink.png') + this.load.image('pink-frosting', 'assets/pink-frosting.png') + this.load.image('blue-frosting', 'assets/blue-frosting.png') + this.load.image('yellow-frosting', 'assets/yellow-frosting.png') + this.load.image('purple-frosting', 'assets/purple-frosting.png'); + this.load.image('coin', 'assets/coin.png') + } + create() { + this.add.image(545, 305, 'bakery2'); + const bluefrost = this.add.sprite(900, 320, 'blue-frosting').setScale(.15).setInteractive(); + const pinkfrost = this.add.sprite(820, 320, 'pink-frosting').setScale(.15).setInteractive(); + const yellowfrost = this.add.sprite(740, 320, 'yellow-frosting').setScale(.15).setInteractive(); + const purplefrost = this.add.sprite(660, 320, 'purple-frosting').setScale(.15).setInteractive(); + const pinkliner = this.add.sprite(150, 570, 'pink-liner').setScale(.5).setInteractive(); + const blueliner = this.add.sprite(250, 570, 'blue-liner').setScale(.5).setInteractive(); + let coins = 0; + const coinImage = this.add.image(490, 30, 'coin').setScale(0.05); + const coinCounterText = this.add.text(520, 20, `x ${coins}`, { + fontSize: '24px', + fill: '#000' + }); + this.input.setDraggable(pinkfrost); + this.input.setDraggable(bluefrost); + this.input.setDraggable(yellowfrost); + this.input.setDraggable(purplefrost); + this.input.setDraggable(pinkliner); + this.input.setDraggable(blueliner); + pinkfrost.depth = 100 + bluefrost.depth = 100 + yellowfrost.depth = 100 + purplefrost.depth = 100 + this.input.on('drag', function(pointer: any, gameObject: { + x: any;y: any + }, dragX: any, dragY: any) { + gameObject.x = dragX; + gameObject.y = dragY; + }) + this.input.on('drop', function(pointer: any, gameObject: { + x: any;y: any;input: { + enabled: boolean + } + }, dropZone: { + x: any;y: any + }) { + gameObject.x = dropZone.x; + gameObject.y = dropZone.y; + gameObject.input.enabled = true; + }); + this.input.on('dragend', function(pointer: any, gameObject: { + x: any;input: { + dragStartX: any;dragStartY: any + };y: any + }, dropped: any) { + if (!dropped) { + gameObject.x = gameObject.input.dragStartX; + gameObject.y = gameObject.input.dragStartY; + } + }); + const zone = this.add.zone(400, 350, 90, 70).setRectangleDropZone(90, 70); + const graphics = this.add.graphics(); + graphics.lineStyle(1, 0xffffff); + graphics.strokeRect(zone.x - zone.input.hitArea.width / 2, zone.y - zone.input.hitArea.height / 2, zone.input.hitArea.width, zone.input.hitArea.height); + const zone2 = this.add.zone(400, 275, 90, 70).setRectangleDropZone(90, 70); + const graphics2 = this.add.graphics(); + graphics2.lineStyle(1, 0xffffff); + graphics2.strokeRect(zone2.x - zone2.input.hitArea.width / 2, zone2.y - zone2.input.hitArea.height / 2, zone2.input.hitArea.width, zone2.input.hitArea.height); + + function updateCoinCounter() { + coins++; + coinCounterText.setText(`x ${coins}`); + } + this.input.on('drop', (pointer, gameObject, dropZone) => { + gameObject.x = dropZone.x; + gameObject.y = dropZone.y; + gameObject.input.enabled = true; + if ((gameObject === pinkfrost || gameObject === bluefrost || gameObject === yellowfrost || gameObject === purplefrost) && (dropZone === zone || dropZone === zone2)) { + updateCoinCounter(); + } + const graphics1 = this.add.graphics(); + graphics1.fillStyle(0xfdadac, 1); + graphics1.fillRoundedRect(5, 5, 150, 60, 30); + graphics1.setInteractive(); + const startGame = this.add.text(35, 20, "Restart").setFont("20px Arial").setColor("#ffffff").setInteractive(); + const renderStart = this.add.renderTexture(10, 5, 110, 40).setInteractive(); + renderStart.draw(graphics1); + renderStart.draw(startGame); + renderStart.setInteractive(); + renderStart.on('pointerdown', () => { + blueliner.setPosition(250, 570) + pinkliner.setPosition(150, 570) + pinkfrost.setPosition(820, 320) + purplefrost.setPosition(660, 320) + yellowfrost.setPosition(740, 320) + bluefrost.setPosition(900, 320) + }, this); + startGame.destroy(); + const storeButton = this.add.text(960, 20, 'Store').setFont("32px Arial").setColor("#ffffff").setInteractive(); + storeButton.on('pointerdown', () => { + this.scene.start('StoreScene'); + }, this); + }); } - - - const storeButton = this.add.text(960, 20, 'Store').setFont("32px Arial").setColor("#ffffff").setInteractive(); + } - storeButton.on('pointerdown', () => { - this.scene.start('StoreScene'); - }, this); - - }); - } } From fd80c33516f963111b722cd637394b73127f4deb Mon Sep 17 00:00:00 2001 From: printemps25 <124960699+printemps25@users.noreply.github.com> Date: Fri, 14 Apr 2023 13:53:05 -0400 Subject: [PATCH 2/4] Update KitchenScene.ts --- src/KitchenScene.ts | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/KitchenScene.ts b/src/KitchenScene.ts index 6998f6a..61858e8 100644 --- a/src/KitchenScene.ts +++ b/src/KitchenScene.ts @@ -35,14 +35,9 @@ export default class KitchenScene extends Phaser.Scene { this.promptText.setVisible(false); this.physics.add.overlap(this.player, this.zone, () => { - this.promptText?.setVisible(true); - this.input.keyboard.once('keydown', (event: KeyboardEvent) => { - if (event.key === 'e') { - this.scene.start('GameScene'); - } - }); + this.promptText?.setVisible(true); + this.inZone = true; }, undefined, this); - } update() { @@ -60,7 +55,13 @@ export default class KitchenScene extends Phaser.Scene { } if (this.cursors.up.isDown && this.player?.body.touching.down) { - this.player.setVelocityY(-400); + this.player.setVelocityY(-330); + } + + if (this.inZone && Phaser.Input.Keyboard.JustDown(this.interactKey!)) { + this.scene.start('GameScene'); + this.inZone = false; } } -} +} + From 4cb7bf8d6bb728bc9fea6a6cacdfef0610f6ce4c Mon Sep 17 00:00:00 2001 From: printemps25 <124960699+printemps25@users.noreply.github.com> Date: Fri, 14 Apr 2023 13:53:22 -0400 Subject: [PATCH 3/4] Update InstructionScene.ts --- src/InstructionScene.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/InstructionScene.ts b/src/InstructionScene.ts index b876251..fcb60b4 100644 --- a/src/InstructionScene.ts +++ b/src/InstructionScene.ts @@ -16,5 +16,7 @@ export default class InstructionsScene extends Phaser.Scene { backButton.on('pointerdown', () => { this.scene.start("bootGame"); }, this); + + const instructionsText = this.add.text(300, 160, "Welcome to the bakery!\n\nHere are some instructions:\n\n1. Drag the frosting and liner together to make a cupcake.\n\n2. Earns coins to use at the store.\n\n3. Enjoy your gaming experience!").setFont("25px Arial").setAlign("center").setColor("#000000"); } } From cc42d7495d281566b4ca44ea9d3d8ac9ec9fcf79 Mon Sep 17 00:00:00 2001 From: printemps25 <124960699+printemps25@users.noreply.github.com> Date: Fri, 14 Apr 2023 13:53:50 -0400 Subject: [PATCH 4/4] Update StoreScene.ts --- src/StoreScene.ts | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/StoreScene.ts b/src/StoreScene.ts index bf26f1b..499a20a 100644 --- a/src/StoreScene.ts +++ b/src/StoreScene.ts @@ -7,23 +7,27 @@ export default class StoreScene extends Phaser.Scene { preload() { this.load.image('store', 'assets/dessertbackground.png'); + this.load.image('purple-frosting', 'assets/purple-frosting.png'); } - create() { - const storeButton = this.add.text(320, 20, 'Store').setFont('25px Arial').setColor('#ffffff').setInteractive(); - + create() { this.add.image(545, 305, 'store'); + + const purpleFrosting = this.add.image(300, 250, 'purple-frosting'); + purpleFrosting.setScale(0.3); + purpleFrosting.setDepth(1); + purpleFrosting.setInteractive(); - storeButton.on('pointerdown', () => { - this.scene.start('StoreScene'); - }, this); - + purpleFrosting.on('pointerdown', () => { + this.scene.get('GameScene').data.set('purpleFrosting', true); + this.scene.get('GameScene').data.set('coins', this.scene.get('GameScene').data.get('coins') - 1); + this.scene.start('GameScene'); + }); + const backButton = this.add.text(20, 20, 'Back').setFont('23px Arial').setColor('#ffffff').setInteractive(); - backButton.on('pointerdown', () => { - this.scene.start('KitchenScene'); + this.scene.switch('GameScene'); }, this); - + } } -