From 755be2f5a4474d33367ef57ca148f54babefa5c5 Mon Sep 17 00:00:00 2001 From: Kacper Kostka Date: Sat, 5 Apr 2025 19:08:24 +0200 Subject: [PATCH] refactor: Update player sprite and camera movement parameters --- js/entities/player.js | 25 ++++--------------------- 1 file changed, 4 insertions(+), 21 deletions(-) diff --git a/js/entities/player.js b/js/entities/player.js index 181bac4..ce5a736 100644 --- a/js/entities/player.js +++ b/js/entities/player.js @@ -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; }