Add basic controls
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
import { createAnimation, playAnimation } from "#/engine/Animation.ts";
|
||||
import { useEntity } from "#/engine/Entity.ts";
|
||||
import { defineEntity } from "#/engine/Entity.ts";
|
||||
import { fromSrc, type Sprite } from "#/lib/Sprite.ts";
|
||||
|
||||
const idle: Sprite = await fromSrc("/assets/hero/idle.png", 5, 4);
|
||||
|
||||
const { animate, process } = useEntity(import.meta, {
|
||||
const { animate, process } = defineEntity("barEntity", {
|
||||
animation: createAnimation(idle, 200, 0),
|
||||
stuff: 1,
|
||||
});
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
import charIdle from "#/assets/char-idle.png";
|
||||
import { createAnimation, playAnimation } from "#/engine/Animation.ts";
|
||||
import { useEntity } from "#/engine/Entity.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 } = useEntity(import.meta, {
|
||||
const { animate, process } = defineEntity("hero", {
|
||||
animation: createAnimation(idle, 500, 2),
|
||||
});
|
||||
|
||||
@@ -19,4 +20,9 @@ animate((entity, ctx, delta) => {
|
||||
);
|
||||
});
|
||||
|
||||
process((entity, delta) => {});
|
||||
process((entity, delta) => {
|
||||
if (pointer.isDown) {
|
||||
entity.position.x = pointer.position.x;
|
||||
entity.position.y = pointer.position.y;
|
||||
}
|
||||
});
|
||||
@@ -1,10 +1,10 @@
|
||||
import { createAnimation, playAnimation } from "#/engine/Animation.ts";
|
||||
import { useEntity } from "#/engine/Entity.ts";
|
||||
import { defineEntity } from "#/engine/Entity.ts";
|
||||
import { fromSrc, type Sprite } from "#/lib/Sprite.ts";
|
||||
|
||||
const sprite: Sprite = await fromSrc("./assets/portal.png", 3, 1);
|
||||
|
||||
const { animate } = useEntity(import.meta, {
|
||||
const { animate } = defineEntity("portal", {
|
||||
animation: createAnimation(sprite, 400, 0),
|
||||
});
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import {
|
||||
createAnimation,
|
||||
playAnimation,
|
||||
} from "#/engine/Animation.ts";
|
||||
import { useEntity } from "#/engine/Entity.ts";
|
||||
import { defineEntity } from "#/engine/Entity.ts";
|
||||
import { viewport } from "#/engine/Viewport.ts";
|
||||
import { loadImage } from "#/lib/loadImage.ts";
|
||||
import { createSprite } from "#/lib/Sprite.ts";
|
||||
@@ -14,19 +14,20 @@ const sprites = {
|
||||
idle: createSprite(await loadImage(charIdle), 2, 4),
|
||||
walk: createSprite(await loadImage(charWalk), 4, 4),
|
||||
};
|
||||
|
||||
const animations = {
|
||||
idle: createAnimation(sprites.idle, 500, 2),
|
||||
walk: createAnimation(sprites.walk, 250, 2),
|
||||
} as const;
|
||||
};
|
||||
|
||||
const { animate, process } = useEntity<{
|
||||
const { animate, process } = defineEntity<{
|
||||
animation: Animation;
|
||||
animations: {
|
||||
idle: Animation;
|
||||
walk: Animation;
|
||||
};
|
||||
stuff: number;
|
||||
}>(import.meta, {
|
||||
}>("testEntity", {
|
||||
animations,
|
||||
animation: animations.idle,
|
||||
stuff: 1,
|
||||
|
||||
Reference in New Issue
Block a user