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
LuxxArt committed Nov 19, 2023
2 parents 5f171f7 + 0d154d7 commit 28da8c6
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 13 deletions.
8 changes: 4 additions & 4 deletions src/components/Trampoline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ export class Trampoline extends Button {
const holdX = 1.0 + 0.2 * this.holdSmooth;
const holdY = 1.0 - 0.1 * this.holdSmooth;
const squish = 0.01;
// this.setScale(
// (1.0 + squish * Math.sin(time / 200)) * holdX,
// (1.0 + squish * Math.sin(-time / 200)) * holdY
// );
this.setScale(
(1.0 + squish * Math.sin(time / 200)) * holdX,
(1.0 + squish * Math.sin(-time / 200)) * holdY
);
}
}
47 changes: 39 additions & 8 deletions src/components/Turtle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class Turtle extends Button {

// Jumping
private trampolineZone?: Phaser.Geom.Rectangle;
public feetOffset: number;
private isStuck: boolean;

constructor(scene: GameScene, x: number, y: number) {
super(scene, x, y);
Expand All @@ -50,9 +50,9 @@ export class Turtle extends Button {
left: 100,
right: scene.W - 100,
top: 0,
bottom: scene.H - 250,
bottom: scene.H - 200,
};
this.feetOffset = 0.4 * this.sprite.displayHeight;
this.isStuck = false;

/* Input */
this.dragOffset = new Phaser.Math.Vector2();
Expand Down Expand Up @@ -96,6 +96,10 @@ export class Turtle extends Button {
else {
this.physicsVelocity.x = 0.97 * this.physicsVelocity.x;
this.physicsVelocity.y += 1;

if (this.physicsVelocity.y > 25) {
this.isStuck = true;
}
}

// Apply velocity
Expand All @@ -121,13 +125,24 @@ export class Turtle extends Button {
const squish = 0.02 * Math.sin((6 * time) / 1000);
this.setScale(1.0 + squish, 1.0 - squish);

// let dangleAngle = 10 * Math.sin((5 * time) / 1000);
this.sprite.angle = this.dragVelocity.x;

if (this.trampolineZone || !this.isGrounded) {
if (this.hold || this.trampolineZone) {
this.sprite.setTexture("turtle_jumping");
} else if (this.isGrounded) {
if (this.isStuck) {
this.sprite.setTexture("turtle_stuck");
this.setSpriteOrigin(0.5, 0.8);
this.sprite.angle = 10 * Math.sin((7 * time) / 1000);
} else {
this.sprite.setTexture("turtle_waiting");
}
} else {
this.sprite.setTexture("turtle_waiting");
if (this.isStuck) {
this.sprite.setTexture("turtle_scared");
} else {
this.sprite.setTexture("turtle_jumping");
}
}
}

Expand All @@ -152,18 +167,34 @@ export class Turtle extends Button {
}
}

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);
}

get isGrounded() {
return this.physicsPosition.y >= this.border.bottom - this.feetOffset;
}

get feetOffset() {
if (!this.isStuck) {
return 0.4 * this.sprite.displayHeight;
} else {
return 0.0 * this.sprite.displayHeight;
}
}

/* Input */

onDragStart(pointer: Phaser.Input.Pointer, dragX: number, dragY: number) {
this.dragOffset.set(dragX, dragY);
this.physicsPosition.set(dragX, dragY);

this.sprite.setOrigin(0.5, 0.4);
this.setSpriteOrigin(0.5, 0.3);
this.sprite.setTexture("turtle_jumping");

this.isStuck = false;
}

onDrag(pointer: Phaser.Input.Pointer, dragX: number, dragY: number) {
Expand All @@ -174,7 +205,7 @@ export class Turtle extends Button {
}

onDragEnd(pointer: Phaser.Input.Pointer, dragX: number, dragY: number) {
this.sprite.setOrigin(0.5);
this.setSpriteOrigin(0.5, 0.5);
// this.y += this.sprite.height / 2;
this.sprite.setTexture("turtle_waiting");

Expand Down
2 changes: 1 addition & 1 deletion src/scenes/OverworldState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class OverworldState extends Phaser.GameObjects.Container {
scene.fitToScreen(this.background);
this.add(this.background);

this.trampoline = new Trampoline(scene, 0.25 * scene.W, 0.9 * scene.H);
this.trampoline = new Trampoline(scene, 0.25 * scene.W, 0.85 * scene.H);
this.add(this.trampoline);

this.turtles = [];
Expand Down

0 comments on commit 28da8c6

Please sign in to comment.