diff --git a/src/assets/assets.ts b/src/assets/assets.ts index 9d846dd..2ff796f 100644 --- a/src/assets/assets.ts +++ b/src/assets/assets.ts @@ -34,6 +34,7 @@ const images: Image[] = [ // UI image("ui/hud", "hud"), + image("ui/shop_buy_button", "buy_button"), // Titlescreen image("titlescreen/sky", "title_sky"), diff --git a/src/assets/images/ui/shop_buy_button.png b/src/assets/images/ui/shop_buy_button.png new file mode 100644 index 0000000..06f9e7d Binary files /dev/null and b/src/assets/images/ui/shop_buy_button.png differ diff --git a/src/components/Turtle.ts b/src/components/Turtle.ts index 98dc53d..bb476a0 100644 --- a/src/components/Turtle.ts +++ b/src/components/Turtle.ts @@ -75,7 +75,7 @@ export class Turtle extends Button { this.spriteSize = 200; this.sprite = this.scene.add.sprite(0, 0, "turtle_waiting"); this.sprite.setScale(this.spriteSize / this.sprite.width); - this.add(this.sprite); + // this.add(this.sprite); /* Controls */ this.physicsPosition = new Phaser.Math.Vector2(x, y); @@ -275,6 +275,17 @@ export class Turtle extends Button { this.sprite.setTexture("turtle_jumping"); } } + + // Depth sorting + this.sprite.setPosition(this.x, this.y); + let depth = 100; + if (this.isOnTrampoline) { + depth += this.jumpTarget.y / 100; + } else { + depth += this.walkTarget.y / 100; + } + if (this.hold) depth += 100; + this.sprite.setDepth(depth); } @@ -391,7 +402,7 @@ export class Turtle extends Button { this.lostBalance = false; this.hasCrashed = false; this.bounceCount = 0; - this.onDrag(pointer, 0, 0); + this.onDrag(pointer, this.x, this.y); } onDrag(pointer: Phaser.Input.Pointer, dragX: number, dragY: number) { diff --git a/src/scenes/OverworldState.ts b/src/scenes/OverworldState.ts index 85e54fb..927a3ea 100644 --- a/src/scenes/OverworldState.ts +++ b/src/scenes/OverworldState.ts @@ -77,6 +77,14 @@ export class OverworldState extends Phaser.GameObjects.Container { }); } + setVisible(value: boolean): this { + this.turtles.forEach((turtle) => { + turtle.sprite.setVisible(value); + }); + + return super.setVisible(value); + } + addDust(x: number, y: number) { let xpl = this.scene.add.sprite(x, y, 'dust_explosion'); diff --git a/src/scenes/ShopState.ts b/src/scenes/ShopState.ts index 7d209df..be20fc6 100644 --- a/src/scenes/ShopState.ts +++ b/src/scenes/ShopState.ts @@ -64,6 +64,8 @@ export class ShopState extends Phaser.GameObjects.Container { private selectedItem: ShopItem | undefined; + private buyButton: Button; + constructor(scene: GameScene) { super(scene, 0, 0); this.scene = scene; @@ -96,6 +98,20 @@ export class ShopState extends Phaser.GameObjects.Container { this.shopper = new Shopper(scene, 0.5, 0.5); this.add(this.shopper); + + this.buyButton = new Button(this.scene, this.scene.W * 0.6, this.scene.H * 0.6); + const buySign = this.scene.add.sprite(0, 0, 'buy_button').setOrigin(0.3, 0.35); + this.buyButton.add(buySign); + this.buyButton.add(this.scene.add.text(0, 0, 'BUY', {fontSize: 80, fontStyle: 'bold', align: 'center'})); + this.buyButton.bindInteractive(buySign, true); + this.buyButton.on('click', () => { + if(this.selectedItem) + console.log('Buying', this.selectedItem); + else + console.log('Select item first') + }); + this.add(this.buyButton); + } populateShop() {