Skip to content

Commit

Permalink
Add shopper
Browse files Browse the repository at this point in the history
  • Loading branch information
ArcticFqx committed Nov 19, 2023
1 parent 2af0bbb commit b3bed13
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/components/Shopper.ts
Original file line number Diff line number Diff line change
@@ -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);
}

}
1 change: 1 addition & 0 deletions src/scenes/GameScene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
44 changes: 44 additions & 0 deletions src/scenes/ShopState.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,43 @@
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;

private background: Phaser.GameObjects.Image;
private someButton: Button;

private itemsForSale: Item[];
private shopper: Shopper;

constructor(scene: GameScene) {
super(scene, 0, 0);
this.scene = scene;
Expand All @@ -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) {
Expand Down

0 comments on commit b3bed13

Please sign in to comment.