diff --git a/screenshots/screenshirt_1.png b/screenshots/screenshirt_1.png new file mode 100644 index 0000000..e26e1a3 Binary files /dev/null and b/screenshots/screenshirt_1.png differ diff --git a/screenshots/screenshirt_2.png b/screenshots/screenshirt_2.png new file mode 100644 index 0000000..54fad98 Binary files /dev/null and b/screenshots/screenshirt_2.png differ diff --git a/screenshots/screenshirt_3.png b/screenshots/screenshirt_3.png new file mode 100644 index 0000000..f9dd38e Binary files /dev/null and b/screenshots/screenshirt_3.png differ diff --git a/screenshots/screenshirt_4.png b/screenshots/screenshirt_4.png new file mode 100644 index 0000000..ebb2c21 Binary files /dev/null and b/screenshots/screenshirt_4.png differ 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/components/Turtle.ts b/src/components/Turtle.ts index 2650e01..ce9eb47 100644 --- a/src/components/Turtle.ts +++ b/src/components/Turtle.ts @@ -354,7 +354,7 @@ export class Turtle extends Button { this.lostBalance = false; this.hasCrashed = false; this.bounceCount = 0; - this.onDrag(pointer, this.x, this.y); + this.onDrag(pointer, 0, 0); } onDrag(pointer: Phaser.Input.Pointer, dragX: number, dragY: number) { diff --git a/src/scenes/ShopState.ts b/src/scenes/ShopState.ts index 2ee416b..7d209df 100644 --- a/src/scenes/ShopState.ts +++ b/src/scenes/ShopState.ts @@ -1,6 +1,10 @@ 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[]; @@ -11,26 +15,36 @@ type Item = { }; 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: [], + 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), @@ -48,6 +62,8 @@ export class ShopState extends Phaser.GameObjects.Container { private itemsForSale: Item[]; private shopper: Shopper; + private selectedItem: ShopItem | undefined; + constructor(scene: GameScene) { super(scene, 0, 0); this.scene = scene; @@ -89,12 +105,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((item) => { + this.add(item); + item.on('click', () => { + this.selectedItem = item; + }); + }); } update(time: number, delta: number) {