diff --git a/src/components/Shopper.ts b/src/components/Shopper.ts new file mode 100644 index 0000000..d8d2abd --- /dev/null +++ b/src/components/Shopper.ts @@ -0,0 +1,39 @@ +import { GameScene } from "@/scenes/GameScene"; +import { Button } from "./Button"; +import { Trampoline } from "./Trampoline"; + +export class Shopper extends Button { + public scene: GameScene; + + // Sprites + private spriteSize: number; + public sprite: Phaser.GameObjects.Sprite; + private tween: Phaser.Tweens.Tween; + + constructor(scene: GameScene, x: number, y: number) { + super(scene, x, y); + scene.add.existing(this); + this.scene = scene; + + /* Sprite */ + this.spriteSize = 800; + this.sprite = this.scene.add.sprite(-40, this.scene.H, "shopper"); + this.sprite.setOrigin(0, 1); + + this.sprite.setScale(this.spriteSize / this.sprite.width); + this.add(this.sprite); + + this.bindInteractive(this.sprite, true); + } + + update(time: number, delta: number) { + } + + + setSpriteOrigin(ox: number, oy: number) { + this.sprite.x += (ox - this.sprite.originX) * this.sprite.displayWidth; + this.sprite.y += (oy - this.sprite.originY) * this.sprite.displayHeight; + this.sprite.setOrigin(ox, oy); + } + +} diff --git a/src/scenes/GameScene.ts b/src/scenes/GameScene.ts index d9dfde2..2f4c2ae 100644 --- a/src/scenes/GameScene.ts +++ b/src/scenes/GameScene.ts @@ -41,6 +41,7 @@ export class GameScene extends BaseScene { setState(state: State) { this.state = state; + this.events.emit(`state_${state}`); this.overworld.setVisible(state == State.Overworld); this.shop.setVisible(state == State.Shop); } diff --git a/src/scenes/ShopState.ts b/src/scenes/ShopState.ts index 90077cd..4819a39 100644 --- a/src/scenes/ShopState.ts +++ b/src/scenes/ShopState.ts @@ -1,5 +1,33 @@ import { GameScene, State } from "@/scenes/GameScene"; import { Button } from "@/components/Button"; +import { Shopper } from "@/components/Shopper"; + +type Item = { + title: string[]; + description: string[]; + image: string[]; + prices: number[], + onBuy: (() => null | null)[] +} + +const shopItems: Item[] = [ + /* + { + name: 'Duct Tape', + description: 'Will fix your trampoline 100% of the time!', + image: 'tape', + prices: [500], + onBuy: [] + }, + */ + { + title: ['Spring'], + description: ['Enhances the bounce'], + image: ['spring'], + prices: [100], + onBuy: [] + } +]; export class ShopState extends Phaser.GameObjects.Container { public scene: GameScene; @@ -7,6 +35,9 @@ export class ShopState extends Phaser.GameObjects.Container { private background: Phaser.GameObjects.Image; private someButton: Button; + private itemsForSale: Item[]; + private shopper: Shopper; + constructor(scene: GameScene) { super(scene, 0, 0); this.scene = scene; @@ -31,6 +62,19 @@ export class ShopState extends Phaser.GameObjects.Container { this.someButton.on("click", () => { this.scene.setState(State.Overworld); }); + + this.itemsForSale = []; + this.scene.events.addListener('state_Shop', () => { + this.populateShop(); + }); + + this.shopper = new Shopper(scene, 0.5, 0.5); + this.add(this.shopper); + } + + populateShop() { + this.itemsForSale = shopItems; + } update(time: number, delta: number) {