WIP
This commit is contained in:
@@ -5,15 +5,15 @@
|
|||||||
"": {
|
"": {
|
||||||
"name": "nage",
|
"name": "nage",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@biomejs/biome": "latest",
|
"@biomejs/biome": "2.3.14",
|
||||||
"@types/bun": "latest",
|
"@types/bun": "1.3.8",
|
||||||
"lz-string": "latest",
|
"lz-string": "1.5.0",
|
||||||
"solid-js": "latest",
|
"solid-js": "1.9.11",
|
||||||
"vite": "latest",
|
"vite": "7.3.1",
|
||||||
"vite-plugin-solid": "latest",
|
"vite-plugin-solid": "2.11.10",
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"typescript": "latest",
|
"typescript": "5.9.3",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
import type { Vector } from "#/engine/Vector.ts";
|
||||||
|
|
||||||
|
export type Body<T extends { position: Vector }> = {
|
||||||
|
shape: T;
|
||||||
|
offset: Vector;
|
||||||
|
};
|
||||||
|
|
||||||
|
export function moveAndCollide<T extends { position: Vector }>(
|
||||||
|
body: Body<T>,
|
||||||
|
velocity: Vector,
|
||||||
|
): void {
|
||||||
|
return;
|
||||||
|
}
|
||||||
@@ -1,16 +1,22 @@
|
|||||||
import { createAnimation, playAnimation } from "#/engine/Animation.ts";
|
import { createAnimation, playAnimation } from "#/engine/Animation.ts";
|
||||||
|
import { createCircle, drawCircle } from "#/engine/Circle";
|
||||||
|
import { moveAndCollide } from "#/engine/Collision.ts";
|
||||||
import { defineEntity } from "#/engine/Entity.ts";
|
import { defineEntity } from "#/engine/Entity.ts";
|
||||||
import { keyboardInput } from "#/engine/Keyboard.ts";
|
import { keyboardInput } from "#/engine/Keyboard.ts";
|
||||||
import { pointer } from "#/engine/Pointer.ts";
|
import { pointer } from "#/engine/Pointer.ts";
|
||||||
import { fromSrc, type Sprite } from "#/engine/Sprite.ts";
|
import { fromSrc, type Sprite } from "#/engine/Sprite.ts";
|
||||||
|
import { createVector } from "#/engine/Vector.ts";
|
||||||
import charIdle from "#/game/assets/char-idle.png";
|
import charIdle from "#/game/assets/char-idle.png";
|
||||||
|
|
||||||
// import { moveAndCollide } from "#/some/where.ts";
|
|
||||||
|
|
||||||
const idle: Sprite = await fromSrc(charIdle, 2, 4);
|
const idle: Sprite = await fromSrc(charIdle, 2, 4);
|
||||||
|
|
||||||
const { animate, process } = defineEntity("hero", {
|
const { animate, process } = defineEntity("hero", {
|
||||||
animation: createAnimation(idle, 500, 2),
|
animation: createAnimation(idle, 500, 2),
|
||||||
|
velocity: createVector(),
|
||||||
|
body: {
|
||||||
|
shape: createCircle(createVector(), 4),
|
||||||
|
offset: createVector(8, 10),
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
animate((entity, ctx, delta) => {
|
animate((entity, ctx, delta) => {
|
||||||
@@ -21,6 +27,7 @@ animate((entity, ctx, delta) => {
|
|||||||
entity.position.y,
|
entity.position.y,
|
||||||
delta,
|
delta,
|
||||||
);
|
);
|
||||||
|
drawCircle(ctx, entity.body.shape, "red");
|
||||||
});
|
});
|
||||||
|
|
||||||
process((entity, delta) => {
|
process((entity, delta) => {
|
||||||
@@ -29,8 +36,19 @@ process((entity, delta) => {
|
|||||||
entity.position.y = pointer.position.y;
|
entity.position.y = pointer.position.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
entity.position.x -= keyboardInput.arrowLeft ? 1 : 0;
|
entity.velocity.x -= keyboardInput.arrowLeft ? 0.1 : 0;
|
||||||
entity.position.x += keyboardInput.arrowRight ? 1 : 0;
|
entity.velocity.x += keyboardInput.arrowRight ? 0.1 : 0;
|
||||||
entity.position.y -= keyboardInput.arrowUp ? 1 : 0;
|
entity.velocity.y -= keyboardInput.arrowUp ? 0.1 : 0;
|
||||||
entity.position.y += keyboardInput.arrowDown ? 1 : 0;
|
entity.velocity.y += keyboardInput.arrowDown ? 0.1 : 0;
|
||||||
|
|
||||||
|
entity.position.x += entity.velocity.x * delta;
|
||||||
|
entity.position.y += entity.velocity.y * delta;
|
||||||
|
|
||||||
|
entity.velocity.x = 0;
|
||||||
|
entity.velocity.y = 0;
|
||||||
|
|
||||||
|
moveAndCollide(entity.body, entity.velocity);
|
||||||
|
|
||||||
|
entity.body.shape.position.x = entity.body.offset.x + entity.position.x;
|
||||||
|
entity.body.shape.position.y = entity.body.offset.y + entity.position.y;
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user