import { recordJump, recordMove } from '../systems/behavioral.js?v=20260427c';
export class Player {
constructor(scene, x, y) {
this.scene = scene;
this.sprite = scene.add.container(x, y);
this.body = scene.add.ellipse(0, 0, 28, 42, 0xffffff);
this.head = scene.add.circle(0, -30, 13, 0xffffff);
this.eye = scene.add.rectangle(5, -32, 7, 2, 0x111111);
this.sprite.add([this.body, this.head, this.eye]);
scene.physics.add.existing(this.sprite);
this.sprite.body.setSize(28, 70);
this.sprite.body.setOffset(-14, -58);
this.sprite.body.setCollideWorldBounds(true);
this.sprite.body.setMaxVelocity(380, 900);
this.cursors = scene.input.keyboard.createCursorKeys();
this.keys = scene.input.keyboard.addKeys('W,A,S,D,SPACE');
this.jumpWasDown = false;
this.pointerWasDown = false;
this.jumpSuppressed = false;
}
suppressJumpUntilRelease() {
this.jumpSuppressed = true;
this.jumpWasDown = true;
this.pointerWasDown = true;
}
setTint(color) {
this.body.setFillStyle(color);
this.head.setFillStyle(color);
}
update(session) {
const body = this.sprite.body;
const pointerDown = this.scene.input.activePointer.isDown;
if (this.jumpSuppressed && !pointerDown && !this.cursors.up.isDown && !this.keys.W.isDown && !this.keys.SPACE.isDown) {
this.jumpSuppressed = false;
}
const left = this.cursors.left.isDown || this.keys.A.isDown;
const right = this.cursors.right.isDown || this.keys.D.isDown;
const jumpKey = this.cursors.up.isDown || this.keys.W.isDown || this.keys.SPACE.isDown;
const jump = this.jumpSuppressed ? false : (jumpKey || pointerDown);
const speed = 245 + session.currencies.convenience * 18;
if (left) {
body.setVelocityX(-speed);
recordMove(session, -1);
} else if (right) {
body.setVelocityX(speed);
recordMove(session, 1);
} else {
body.setVelocityX(body.velocity.x * 0.82);
}
const touching = body.blocked.down || body.touching.down;
if (jump && !this.jumpWasDown && touching) {
body.setVelocityY(-560 - session.currencies.convenience * 18);
recordJump(session);
this.scene.soundTick?.('jump');
}
if (pointerDown && !this.pointerWasDown && !touching && !this.jumpSuppressed) {
this.scene.onAirTap?.();
}
this.jumpWasDown = jump;
this.pointerWasDown = pointerDown;
}
}