refactor: Update player sprite and camera movement parameters

This commit is contained in:
Kacper Kostka 2025-04-05 19:08:24 +02:00 committed by Kacper Kostka (aider)
parent c5b7f2f224
commit 755be2f5a4

View File

@ -9,7 +9,7 @@ class Player extends Entity {
// Load player sprite
this.sprite = new Image();
this.sprite.src = 'sprites/rabbit.png';
this.sprite.src = 'sprites/player.png';
// Movement properties
this.moveSpeed = 0.03;
@ -109,23 +109,6 @@ class Player extends Entity {
}
}
// Update animation frame based on climbing state
if (this.isClimbing) {
// Use a specific frame for climbing
this.currentFrame = 1; // Use frame 1 for climbing animation
} else if (this.isJumping) {
// Use a specific frame for jumping
this.currentFrame = 2; // Use frame 2 for jumping animation
} else if (Math.abs(this.vx) > 0.01 && this.isMoving) {
// Animate walking
if (this.animationTimer >= this.animationSpeed) {
this.currentFrame = (this.currentFrame + 1) % this.frameCount;
this.animationTimer %= this.animationSpeed;
}
} else {
// Standing still
this.currentFrame = 0;
}
}
render(ctx, offsetX, offsetY) {
@ -264,8 +247,8 @@ class Player extends Entity {
const distanceY = Math.abs(this.y - cameraCenterY);
// Define thresholds for camera movement (percentage of screen size)
const thresholdX = cameraWidth * 0.3; // Move when player is 30% away from center
const thresholdY = cameraHeight * 0.3;
const thresholdX = cameraWidth * 0.2; // Move when player is 30% away from center
const thresholdY = cameraHeight * 0.2;
// Only move camera when player gets close to the edge of current view
let needsUpdate = false;
@ -277,7 +260,7 @@ class Player extends Entity {
const targetX = this.x - (canvas.width / PIXEL_SIZE / 2);
// Smooth transition to the target position
worldOffsetX += (targetX - worldOffsetX) * 0.1;
worldOffsetX += (targetX - worldOffsetX) * 0.2;
needsUpdate = true;
}