From bb1e25e753672b8b5ea95a7d3143f530673f16d8 Mon Sep 17 00:00:00 2001 From: "Kacper Kostka (aider)" Date: Sat, 5 Apr 2025 18:49:31 +0200 Subject: [PATCH] refactor: Reduce player size by 50% to improve pixel collision --- js/entities/player.js | 10 +++++----- js/main.js | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/js/entities/player.js b/js/entities/player.js index 893894b..2e1c62c 100644 --- a/js/entities/player.js +++ b/js/entities/player.js @@ -2,8 +2,8 @@ class Player extends Entity { constructor(x, y, options = {}) { super(ENTITY_TYPES.PLAYER, x, y, { - width: 6, // Narrower collision box to match sprite - height: 12, // Shorter collision box to match sprite + width: 3, // 50% smaller collision box width + height: 6, // 50% smaller collision box height ...options }); @@ -128,9 +128,9 @@ class Player extends Entity { ctx.save(); ctx.translate(screenX, screenY); - // Use smaller dimensions for the sprite - const spriteDisplayWidth = 24 * (PIXEL_SIZE / 2); // Smaller sprite (was 32) - const spriteDisplayHeight = 24 * (PIXEL_SIZE / 2); // Smaller sprite (was 32) + // Use 50% smaller dimensions for the sprite + const spriteDisplayWidth = 12 * (PIXEL_SIZE / 2); // 50% smaller sprite + const spriteDisplayHeight = 12 * (PIXEL_SIZE / 2); // 50% smaller sprite // Flip horizontally based on direction if (this.direction < 0) { diff --git a/js/main.js b/js/main.js index afac328..c543ca4 100644 --- a/js/main.js +++ b/js/main.js @@ -103,7 +103,7 @@ function spawnPlayer() { // Create player at specified coordinates // Position adjusted for proper sprite alignment with smaller sprite - player = createEntity(ENTITY_TYPES.PLAYER, 229, 45); + player = createEntity(ENTITY_TYPES.PLAYER, 229, 40); // Adjusted Y position for smaller player // Focus camera on player worldOffsetX = player.x - (canvas.width / PIXEL_SIZE / 2);