This commit is contained in:
Schluffe
2026-02-16 23:30:35 +01:00
parent 31901f53f7
commit 966e83076f
2 changed files with 9 additions and 8 deletions
+2 -2
View File
@@ -34,8 +34,8 @@ export function drawAABB(
ctx.save(); ctx.save();
ctx.strokeStyle = color; ctx.strokeStyle = color;
ctx.strokeRect( ctx.strokeRect(
Math.round(aabb.position.x) - 0.5, aabb.position.x - 0.5,
Math.round(aabb.position.y) - 0.5, aabb.position.y - 0.5,
aabb.width, aabb.width,
aabb.height, aabb.height,
); );
+7 -6
View File
@@ -9,6 +9,7 @@ import { createVector } from "#/engine/Vector.ts";
import charIdle from "#/game/assets/char-idle.png"; import charIdle from "#/game/assets/char-idle.png";
const idle: Sprite = await fromSrc(charIdle, 2, 4); const idle: Sprite = await fromSrc(charIdle, 2, 4);
const speed = 0.05;
const { animate, process } = defineEntity("hero", { const { animate, process } = defineEntity("hero", {
animation: createAnimation(idle, 500, 2), animation: createAnimation(idle, 500, 2),
@@ -36,13 +37,13 @@ process((entity, delta) => {
entity.position.y = pointer.position.y; entity.position.y = pointer.position.y;
} }
entity.velocity.x -= keyboardInput.arrowLeft ? 0.1 : 0; entity.velocity.x -= keyboardInput.arrowLeft ? speed : 0;
entity.velocity.x += keyboardInput.arrowRight ? 0.1 : 0; entity.velocity.x += keyboardInput.arrowRight ? speed : 0;
entity.velocity.y -= keyboardInput.arrowUp ? 0.1 : 0; entity.velocity.y -= keyboardInput.arrowUp ? speed : 0;
entity.velocity.y += keyboardInput.arrowDown ? 0.1 : 0; entity.velocity.y += keyboardInput.arrowDown ? speed : 0;
entity.position.x += entity.velocity.x * delta; entity.position.x = Math.round(entity.velocity.x * delta + entity.position.x);
entity.position.y += entity.velocity.y * delta; entity.position.y = Math.round(entity.velocity.y * delta + entity.position.y);
entity.velocity.x = 0; entity.velocity.x = 0;
entity.velocity.y = 0; entity.velocity.y = 0;