This commit is contained in:
kolaflash
2025-11-25 19:32:27 +01:00
commit 104f0998e1
36 changed files with 1274 additions and 0 deletions
+36
View File
@@ -0,0 +1,36 @@
import { loadImage } from "#/lib/loadImage.ts";
import { createSprite, type Sprite } from "#/lib/Sprite.ts";
import { createVector, type Vector } from "#/lib/Vector.ts";
export type Entity = {
id: string;
src: string;
width: number;
height: number;
};
export type EntityInstance = {
position: Vector;
width: number;
height: number;
sprite: Sprite;
};
export function createEntity(
id: string,
src: string,
width: number = 16,
height: number = 16,
): Entity {
return { id, width, height, src };
}
export async function loadEntity(name: string): Promise<EntityInstance> {
const entity = (await import(`#/entities/${name}/index.ts`)).default;
const { width, height } = entity;
const sprite = createSprite(await loadImage(entity.src), 2, 4);
const position = createVector();
return { position, width, height, sprite };
}