From f20c84447d676bb66e12f392120f01b70f365c5d Mon Sep 17 00:00:00 2001 From: Lumie Date: Sun, 19 Nov 2023 08:31:11 -0800 Subject: [PATCH 1/2] fixed disappearing asset --- src/assets/assets.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/assets/assets.ts b/src/assets/assets.ts index 5047927..8cb45d1 100644 --- a/src/assets/assets.ts +++ b/src/assets/assets.ts @@ -43,7 +43,9 @@ const images: Image[] = [ ]; /* Spritesheets */ -const spritesheets: SpriteSheet[] = []; +const spritesheets: SpriteSheet[] = [ + spritesheet('effects/dustyexplosion', 'dust', 128, 128), +]; /* Audios */ const audios: Audio[] = [ From d34d2a06bac44e7e1bc0894da48ca8fb98135387 Mon Sep 17 00:00:00 2001 From: ArcticFqx Date: Sun, 19 Nov 2023 17:33:57 +0100 Subject: [PATCH 2/2] Add ShopItem component --- src/components/ShopItem.ts | 21 ++++++++++++++++++ src/scenes/ShopState.ts | 45 ++++++++++++++++++++++++++++---------- 2 files changed, 54 insertions(+), 12 deletions(-) create mode 100644 src/components/ShopItem.ts diff --git a/src/components/ShopItem.ts b/src/components/ShopItem.ts new file mode 100644 index 0000000..eb5151c --- /dev/null +++ b/src/components/ShopItem.ts @@ -0,0 +1,21 @@ +import { GameScene } from "@/scenes/GameScene"; +import { Button } from "./Button"; + +export class ShopItem extends Button { + public scene: GameScene; + + // Sprites + public sprite: Phaser.GameObjects.Sprite; + + constructor(scene: GameScene, x: number, y: number, img: string) { + super(scene, 0, 0); + scene.add.existing(this); + this.scene = scene; + + /* Sprite */ + this.sprite = this.scene.add.sprite(x, y, img); + this.add(this.sprite); + + this.bindInteractive(this.sprite, true); + } +} diff --git a/src/scenes/ShopState.ts b/src/scenes/ShopState.ts index fa77874..7346257 100644 --- a/src/scenes/ShopState.ts +++ b/src/scenes/ShopState.ts @@ -2,6 +2,9 @@ import { GameScene, State } from "@/scenes/GameScene"; import { Button } from "@/components/Button"; import { Shopper } from "@/components/Shopper"; import { ShopOwner } from "@/components/ShopOwner"; +import { ShopItem } from "@/components/ShopItem"; + +import Vector2 = Phaser.Math.Vector2; type Item = { title: string[]; @@ -12,26 +15,36 @@ type Item = { } const shopItems: Item[] = [ - /* { - name: 'Duct Tape', - description: 'Will fix your trampoline 100% of the time!', - image: 'tape', - prices: [500], + title: ['Spring'], + description: ['Enhances the bounce'], + image: ['spring'], + prices: [100], + onBuy: [] + }, + { + title: ['Nail'], + description: ['Got to keep the turt down'], + image: ['nail'], + prices: [100], + onBuy: [] + }, + { + title: ['Screw'], + description: ['Tighten those springs'], + image: ['screw'], + prices: [100], onBuy: [] }, - */ { title: ['Spring'], description: ['Enhances the bounce'], image: ['spring'], prices: [100], onBuy: [] - } + }, ]; -import Vector2 = Phaser.Math.Vector2; - const itemPositions: Vector2[] = [ new Vector2( 0, 0 ), new Vector2( 1, 0 ), @@ -95,10 +108,18 @@ export class ShopState extends Phaser.GameObjects.Container { const Wdist = this.scene.W * 0.13; const Hdist = this.scene.H * 0.15; - const items = itemPositions.map((pos, i) => - this.scene.add.image(Wstart + pos.x * Wdist, Hstart + pos.y * Hdist, 'screw').setScale(1.1) + this.itemsForSale = shopItems; + + + const items = this.itemsForSale.map((item, i) => + new ShopItem(this.scene, Wstart + itemPositions[i].x * Wdist, Hstart + itemPositions[i].y * Hdist, item.image[0]) ); - items.forEach(this.add.bind(this)); + + items.forEach((elem) => { + elem.on('click', () => { + console.log("click") + }); + }); } update(time: number, delta: number) {