From 29a696e9fa9056ec332ea8408c7e389b85200739 Mon Sep 17 00:00:00 2001 From: Golen Date: Fri, 17 Nov 2023 21:17:10 +0100 Subject: [PATCH] Add trampoline and turtle sprites --- src/components/Turtle.ts | 15 ++++++++++----- src/scenes/GameScene.ts | 7 +++++-- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/components/Turtle.ts b/src/components/Turtle.ts index 9e47d16..771d077 100644 --- a/src/components/Turtle.ts +++ b/src/components/Turtle.ts @@ -21,6 +21,7 @@ export class Turtle extends Button { // Controls public velocity: Phaser.Math.Vector2; private border: { [key: string]: number }; + private isDragged: boolean; private dragOffset: Phaser.Math.Vector2; constructor(scene: GameScene, x: number, y: number) { @@ -46,6 +47,7 @@ export class Turtle extends Button { }; /* Input */ + this.isDragged = false; this.dragOffset = new Phaser.Math.Vector2(); this.bindInteractive(this.sprite, true); } @@ -74,14 +76,14 @@ export class Turtle extends Button { } onDragStart(pointer: Phaser.Input.Pointer, dragX: number, dragY: number) { + this.isDragged = true; this.dragOffset.set(dragX, dragY); + this.sprite.setTexture("turtle_jumping"); } onDrag(pointer: Phaser.Input.Pointer, dragX: number, dragY: number) { - this.setPosition( - dragX + this.dragOffset.x, - dragY + this.dragOffset.y, - ); + super.onDrag(pointer, dragX, dragY); + this.setPosition(dragX + this.dragOffset.x, dragY + this.dragOffset.y); } onDragEnd( @@ -89,7 +91,10 @@ export class Turtle extends Button { dragX: number, dragY: number, dropped: boolean - ) {} + ) { + this.isDragged = false; + this.sprite.setTexture("turtle_waiting"); + } doABarrelRoll() { if (!this.tween || !this.tween.isActive()) { diff --git a/src/scenes/GameScene.ts b/src/scenes/GameScene.ts index d74eb01..eef7c9e 100644 --- a/src/scenes/GameScene.ts +++ b/src/scenes/GameScene.ts @@ -4,6 +4,7 @@ import { UI } from "@/components/UI"; export class GameScene extends BaseScene { private background: Phaser.GameObjects.Image; + private trampoline: Phaser.GameObjects.Image; private turtles: Turtle[]; private ui: UI; @@ -18,6 +19,8 @@ export class GameScene extends BaseScene { this.background.setOrigin(0); this.fitToScreen(this.background); + this.trampoline = this.add.image(0.3 * this.W, 0.75 * this.H, "trampoline"); + this.turtles = []; for (let i = 0; i < 5; i++) { this.addTurtle(); @@ -33,8 +36,8 @@ export class GameScene extends BaseScene { } addTurtle() { - let x = this.W * (0.25 + 0.5 * Math.random()); - let y = this.H * (0.5 + 0.25 * Math.random()); + let x = this.W * (0.5 + 0.4 * Math.random()); + let y = this.H * (0.6 + 0.2 * Math.random()); let turtle = new Turtle(this, x, y); turtle.on("action", () => { turtle.doABarrelRoll();