Skip to content

Commit

Permalink
Merge branch 'main' of github.com:Chocobois/TurtleTrampoline
Browse files Browse the repository at this point in the history
  • Loading branch information
Golen87 committed Nov 19, 2023
2 parents 6243b4a + de237a5 commit a01fe14
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 18 deletions.
4 changes: 3 additions & 1 deletion src/assets/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ const images: Image[] = [
];

/* Spritesheets */
const spritesheets: SpriteSheet[] = [];
const spritesheets: SpriteSheet[] = [
spritesheet('effects/dustyexplosion', 'dust', 128, 128),
];

/* Audios */
const audios: Audio[] = [
Expand Down
21 changes: 21 additions & 0 deletions src/components/ShopItem.ts
Original file line number Diff line number Diff line change
@@ -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);
}
}
53 changes: 36 additions & 17 deletions src/scenes/ShopState.ts
Original file line number Diff line number Diff line change
@@ -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[];
Expand All @@ -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),
Expand Down Expand Up @@ -89,12 +103,17 @@ 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) {
Expand Down

0 comments on commit a01fe14

Please sign in to comment.