This commit is contained in:
Schluffe
2026-03-07 13:37:51 +01:00
parent eef8adfa5f
commit 75bbe67730
6 changed files with 52 additions and 59 deletions
+4 -1
View File
@@ -108,7 +108,10 @@ const [loadScene, sceneCache] = useWithAsyncCache(async (name: string) => {
data.entities.map(
async (entityData: EntityData<unknown>, index: number) => {
await import(`#/game/entities/${entityData.name}/entity.ts`);
// TODO
for (const blueprint of entityBlueprintMap
.get(entityData.name)!
.entries()) {
}
},
),
);
+1 -4
View File
@@ -7,7 +7,6 @@ import {
Show,
} from "solid-js";
import { render } from "solid-js/web";
import type { Entity } from "#/engine/Entity.ts";
import {
currentScene,
type SceneData,
@@ -73,9 +72,7 @@ const DevTools: Component<{ gameContainer: HTMLElement }> = ({
const [entities, setEntities] = createSignal(
mapSceneEntities(currentScene.data),
);
const [activeEntity, setActiveEntity] = createSignal<null | Entity<object>>(
null,
);
const [activeEntity, setActiveEntity] = createSignal<null | object>(null); // TODO
createEffect(() => {
setScale(currentScale());
+2 -2
View File
@@ -7,7 +7,7 @@ export default class MapProxy<K, V> {
this.map = new Map();
}
get(key: K): V | undefined {
return this.map.get(key)?.value;
get(key: K): Box<V> | undefined {
return this.map.get(key);
}
}
+11 -19
View File
@@ -1,5 +1,3 @@
// import { createCircle } from "#/engine/Circle.ts";
// import { moveAndCollide } from "#/engine/Collision.ts";
import { defineEntity } from "#/engine/Entity.ts";
import { keyboardInput } from "#/engine/Keyboard.ts";
import { pointer } from "#/engine/Pointer.ts";
@@ -19,32 +17,26 @@ const process = defineEntity("hero", {
position: createVector(),
sprite: createSprite(idleSrc),
playback: createSpritePlayback(500, 2),
// body: createCircle(createVector(), 4),
velocity: createVector(),
});
process((id, delta) => {
const position = $<Vector>("position").get(id)!;
const velocity = velocityMap.get(id)!;
// const body = bodyMap.get(id);
const velocity = $<Vector>("velocity").get(id)!;
if (pointer.isDown) {
position.x = pointer.position.x;
position.y = pointer.position.y;
position.value.x = pointer.position.x;
position.value.y = pointer.position.y;
}
velocity.x -= keyboardInput.arrowLeft ? speed : 0;
velocity.x += keyboardInput.arrowRight ? speed : 0;
velocity.y -= keyboardInput.arrowUp ? speed : 0;
velocity.y += keyboardInput.arrowDown ? speed : 0;
velocity.value.x -= keyboardInput.arrowLeft ? speed : 0;
velocity.value.x += keyboardInput.arrowRight ? speed : 0;
velocity.value.y -= keyboardInput.arrowUp ? speed : 0;
velocity.value.y += keyboardInput.arrowDown ? speed : 0;
// const collision = moveAndCollide(body, velocity, delta);
// slideOnCollision(velocity, collision);
// slide(velocity, collision.normal);
position.value.x = Math.round(velocity.value.x * delta + position.value.x);
position.value.y = Math.round(velocity.value.y * delta + position.value.y);
position.x = Math.round(velocity.x * delta + position.x);
position.y = Math.round(velocity.y * delta + position.y);
velocity.x = 0;
velocity.y = 0;
velocity.value.x = 0;
velocity.value.y = 0;
});
+8 -12
View File
@@ -1,20 +1,16 @@
import { box } from "#/engine/Box.ts";
import { defineEntity } from "#/engine/Entity.ts";
import { createSpritePlayback, defineSpriteSheet } from "#/engine/Sprite.ts";
import {
createSprite,
createSpritePlayback,
defineSpriteSheet,
} from "#/engine/Sprite.ts";
import { createVector } from "#/engine/Vector.ts";
import portal from "#/game/assets/portal.png";
const portalSheet = await defineSpriteSheet(portal, 3, 1);
const sprite = {
src: portalSheet,
xStart: 0,
yStart: 0,
width: 16,
height: 16,
};
const portalSrc = await defineSpriteSheet(portal, 3, 1);
defineEntity("portal", {
position: createVector(64, 64),
sprite,
animation: box(createSpritePlayback(sprite, 400, 0)),
sprite: createSprite(portalSrc),
animation: createSpritePlayback(400, 0),
});
+26 -21
View File
@@ -1,5 +1,5 @@
import { type Box, box } from "#/engine/Box.ts";
import { defineEntity } from "#/engine/Entity.ts";
import $ from "#/engine/Scene.ts";
import {
createSpritePlayback,
defineSpriteSheet,
@@ -11,21 +11,21 @@ import { viewport } from "#/engine/Viewport.ts";
import charIdle from "#/game/assets/char-idle.png";
import charWalk from "#/game/assets/char-walk.png";
const sheets = {
const srcs = {
idle: await defineSpriteSheet(charIdle, 2, 4),
walk: await defineSpriteSheet(charWalk, 4, 4),
};
const sprites = {
idle: {
src: sheets.idle,
src: srcs.idle,
xStart: 0,
yStart: 0,
width: 16,
height: 16,
},
walk: {
src: sheets.walk,
src: srcs.walk,
xStart: 0,
yStart: 0,
width: 16,
@@ -33,15 +33,15 @@ const sprites = {
},
};
const animations = {
idle: createSpritePlayback(sprites.idle, 500, 2),
walk: createSpritePlayback(sprites.walk, 250, 2),
const playbacks = {
idle: createSpritePlayback(500, 2),
walk: createSpritePlayback(250, 2),
};
const process = defineEntity<{
position: Vector;
animation: Box<SpritePlayback>;
animations: {
playback: SpritePlayback;
playbacks: {
idle: SpritePlayback;
walk: SpritePlayback;
};
@@ -53,22 +53,27 @@ const process = defineEntity<{
stuff: number;
}>("testEntity", {
position: createVector(),
animation: box(animations.idle),
animations,
playback: playbacks.idle,
playbacks: playbacks,
sprite: sprites.idle,
sprites,
stuff: 1,
});
process((entity, _delta) => {
entity.position.x += entity.stuff * 0.5;
if (entity.position.x > viewport.canvas.width - 16) {
entity.stuff = -1;
entity.animation.value = entity.animations.walk;
entity.sprite = entity.sprites.walk;
} else if (entity.position.x < 0) {
entity.stuff = 1;
entity.animation.value = entity.animations.idle;
entity.sprite = entity.sprites.idle;
process((id, _delta) => {
const position = $<Vector>("position").get(id)!;
const stuff = $<number>("stuff").get(id)!;
const sprite = $<Sprite>("sprite").get(id)!;
const playback = $<SpritePlayback>("playback").get(id)!;
position.value.x += stuff.value * 0.5;
if (position.value.x > viewport.canvas.width - 16) {
stuff.value = -1;
playback.value = playbacks.walk;
sprite.value = sprites.walk;
} else if (position.value.x < 0) {
stuff.value = 1;
playback.value = playbacks.idle;
sprite.value = sprites.idle;
}
});