Add basic controls

This commit is contained in:
kolaflash
2026-01-23 14:21:21 +01:00
parent 589af23e8c
commit f9a2409dad
19 changed files with 225 additions and 47 deletions
+28
View File
@@ -0,0 +1,28 @@
import charIdle from "#/assets/char-idle.png";
import { createAnimation, playAnimation } from "#/engine/Animation.ts";
import { defineEntity } from "#/engine/Entity.ts";
import { pointer } from "#/engine/Pointer.ts";
import { fromSrc, type Sprite } from "#/lib/Sprite.ts";
const idle: Sprite = await fromSrc(charIdle, 2, 4);
const { animate, process } = defineEntity("hero", {
animation: createAnimation(idle, 500, 2),
});
animate((entity, ctx, delta) => {
playAnimation(
ctx,
entity.animation,
entity.position.x,
entity.position.y,
delta,
);
});
process((entity, delta) => {
if (pointer.isDown) {
entity.position.x = pointer.position.x;
entity.position.y = pointer.position.y;
}
});