From 966e83076f0ea28932c97852810a80745f37d99b Mon Sep 17 00:00:00 2001 From: Schluffe Date: Mon, 16 Feb 2026 23:30:35 +0100 Subject: [PATCH] WIP --- engine/AABB.ts | 4 ++-- game/entities/hero/entity.ts | 13 +++++++------ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/engine/AABB.ts b/engine/AABB.ts index 1ea6ee8..ea32d71 100644 --- a/engine/AABB.ts +++ b/engine/AABB.ts @@ -34,8 +34,8 @@ export function drawAABB( ctx.save(); ctx.strokeStyle = color; ctx.strokeRect( - Math.round(aabb.position.x) - 0.5, - Math.round(aabb.position.y) - 0.5, + aabb.position.x - 0.5, + aabb.position.y - 0.5, aabb.width, aabb.height, ); diff --git a/game/entities/hero/entity.ts b/game/entities/hero/entity.ts index 1c6191a..7c4b0e5 100644 --- a/game/entities/hero/entity.ts +++ b/game/entities/hero/entity.ts @@ -9,6 +9,7 @@ import { createVector } from "#/engine/Vector.ts"; import charIdle from "#/game/assets/char-idle.png"; const idle: Sprite = await fromSrc(charIdle, 2, 4); +const speed = 0.05; const { animate, process } = defineEntity("hero", { animation: createAnimation(idle, 500, 2), @@ -36,13 +37,13 @@ process((entity, delta) => { entity.position.y = pointer.position.y; } - entity.velocity.x -= keyboardInput.arrowLeft ? 0.1 : 0; - entity.velocity.x += keyboardInput.arrowRight ? 0.1 : 0; - entity.velocity.y -= keyboardInput.arrowUp ? 0.1 : 0; - entity.velocity.y += keyboardInput.arrowDown ? 0.1 : 0; + entity.velocity.x -= keyboardInput.arrowLeft ? speed : 0; + entity.velocity.x += keyboardInput.arrowRight ? speed : 0; + entity.velocity.y -= keyboardInput.arrowUp ? speed : 0; + entity.velocity.y += keyboardInput.arrowDown ? speed : 0; - entity.position.x += entity.velocity.x * delta; - entity.position.y += entity.velocity.y * delta; + entity.position.x = Math.round(entity.velocity.x * delta + entity.position.x); + entity.position.y = Math.round(entity.velocity.y * delta + entity.position.y); entity.velocity.x = 0; entity.velocity.y = 0;