Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
215 changes: 107 additions & 108 deletions src/GameScene.ts
Original file line number Diff line number Diff line change
@@ -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);

});
}
}
2 changes: 2 additions & 0 deletions src/InstructionScene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
19 changes: 10 additions & 9 deletions src/KitchenScene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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;
}
}
}
}

26 changes: 15 additions & 11 deletions src/StoreScene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

}
}