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( data.entities.map(
async (entityData: EntityData<unknown>, index: number) => { async (entityData: EntityData<unknown>, index: number) => {
await import(`#/game/entities/${entityData.name}/entity.ts`); 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, Show,
} from "solid-js"; } from "solid-js";
import { render } from "solid-js/web"; import { render } from "solid-js/web";
import type { Entity } from "#/engine/Entity.ts";
import { import {
currentScene, currentScene,
type SceneData, type SceneData,
@@ -73,9 +72,7 @@ const DevTools: Component<{ gameContainer: HTMLElement }> = ({
const [entities, setEntities] = createSignal( const [entities, setEntities] = createSignal(
mapSceneEntities(currentScene.data), mapSceneEntities(currentScene.data),
); );
const [activeEntity, setActiveEntity] = createSignal<null | Entity<object>>( const [activeEntity, setActiveEntity] = createSignal<null | object>(null); // TODO
null,
);
createEffect(() => { createEffect(() => {
setScale(currentScale()); setScale(currentScale());
+2 -2
View File
@@ -7,7 +7,7 @@ export default class MapProxy<K, V> {
this.map = new Map(); this.map = new Map();
} }
get(key: K): V | undefined { get(key: K): Box<V> | undefined {
return this.map.get(key)?.value; 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 { 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";
@@ -19,32 +17,26 @@ const process = defineEntity("hero", {
position: createVector(), position: createVector(),
sprite: createSprite(idleSrc), sprite: createSprite(idleSrc),
playback: createSpritePlayback(500, 2), playback: createSpritePlayback(500, 2),
// body: createCircle(createVector(), 4),
velocity: createVector(), velocity: createVector(),
}); });
process((id, delta) => { process((id, delta) => {
const position = $<Vector>("position").get(id)!; const position = $<Vector>("position").get(id)!;
const velocity = velocityMap.get(id)!; const velocity = $<Vector>("velocity").get(id)!;
// const body = bodyMap.get(id);
if (pointer.isDown) { if (pointer.isDown) {
position.x = pointer.position.x; position.value.x = pointer.position.x;
position.y = pointer.position.y; position.value.y = pointer.position.y;
} }
velocity.x -= keyboardInput.arrowLeft ? speed : 0; velocity.value.x -= keyboardInput.arrowLeft ? speed : 0;
velocity.x += keyboardInput.arrowRight ? speed : 0; velocity.value.x += keyboardInput.arrowRight ? speed : 0;
velocity.y -= keyboardInput.arrowUp ? speed : 0; velocity.value.y -= keyboardInput.arrowUp ? speed : 0;
velocity.y += keyboardInput.arrowDown ? speed : 0; velocity.value.y += keyboardInput.arrowDown ? speed : 0;
// const collision = moveAndCollide(body, velocity, delta); position.value.x = Math.round(velocity.value.x * delta + position.value.x);
// slideOnCollision(velocity, collision); position.value.y = Math.round(velocity.value.y * delta + position.value.y);
// slide(velocity, collision.normal);
position.x = Math.round(velocity.x * delta + position.x); velocity.value.x = 0;
position.y = Math.round(velocity.y * delta + position.y); velocity.value.y = 0;
velocity.x = 0;
velocity.y = 0;
}); });
+8 -12
View File
@@ -1,20 +1,16 @@
import { box } from "#/engine/Box.ts";
import { defineEntity } from "#/engine/Entity.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 { createVector } from "#/engine/Vector.ts";
import portal from "#/game/assets/portal.png"; import portal from "#/game/assets/portal.png";
const portalSheet = await defineSpriteSheet(portal, 3, 1); const portalSrc = await defineSpriteSheet(portal, 3, 1);
const sprite = {
src: portalSheet,
xStart: 0,
yStart: 0,
width: 16,
height: 16,
};
defineEntity("portal", { defineEntity("portal", {
position: createVector(64, 64), position: createVector(64, 64),
sprite, sprite: createSprite(portalSrc),
animation: box(createSpritePlayback(sprite, 400, 0)), 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 { defineEntity } from "#/engine/Entity.ts";
import $ from "#/engine/Scene.ts";
import { import {
createSpritePlayback, createSpritePlayback,
defineSpriteSheet, defineSpriteSheet,
@@ -11,21 +11,21 @@ import { viewport } from "#/engine/Viewport.ts";
import charIdle from "#/game/assets/char-idle.png"; import charIdle from "#/game/assets/char-idle.png";
import charWalk from "#/game/assets/char-walk.png"; import charWalk from "#/game/assets/char-walk.png";
const sheets = { const srcs = {
idle: await defineSpriteSheet(charIdle, 2, 4), idle: await defineSpriteSheet(charIdle, 2, 4),
walk: await defineSpriteSheet(charWalk, 4, 4), walk: await defineSpriteSheet(charWalk, 4, 4),
}; };
const sprites = { const sprites = {
idle: { idle: {
src: sheets.idle, src: srcs.idle,
xStart: 0, xStart: 0,
yStart: 0, yStart: 0,
width: 16, width: 16,
height: 16, height: 16,
}, },
walk: { walk: {
src: sheets.walk, src: srcs.walk,
xStart: 0, xStart: 0,
yStart: 0, yStart: 0,
width: 16, width: 16,
@@ -33,15 +33,15 @@ const sprites = {
}, },
}; };
const animations = { const playbacks = {
idle: createSpritePlayback(sprites.idle, 500, 2), idle: createSpritePlayback(500, 2),
walk: createSpritePlayback(sprites.walk, 250, 2), walk: createSpritePlayback(250, 2),
}; };
const process = defineEntity<{ const process = defineEntity<{
position: Vector; position: Vector;
animation: Box<SpritePlayback>; playback: SpritePlayback;
animations: { playbacks: {
idle: SpritePlayback; idle: SpritePlayback;
walk: SpritePlayback; walk: SpritePlayback;
}; };
@@ -53,22 +53,27 @@ const process = defineEntity<{
stuff: number; stuff: number;
}>("testEntity", { }>("testEntity", {
position: createVector(), position: createVector(),
animation: box(animations.idle), playback: playbacks.idle,
animations, playbacks: playbacks,
sprite: sprites.idle, sprite: sprites.idle,
sprites, sprites,
stuff: 1, stuff: 1,
}); });
process((entity, _delta) => { process((id, _delta) => {
entity.position.x += entity.stuff * 0.5; const position = $<Vector>("position").get(id)!;
if (entity.position.x > viewport.canvas.width - 16) { const stuff = $<number>("stuff").get(id)!;
entity.stuff = -1; const sprite = $<Sprite>("sprite").get(id)!;
entity.animation.value = entity.animations.walk; const playback = $<SpritePlayback>("playback").get(id)!;
entity.sprite = entity.sprites.walk;
} else if (entity.position.x < 0) { position.value.x += stuff.value * 0.5;
entity.stuff = 1; if (position.value.x > viewport.canvas.width - 16) {
entity.animation.value = entity.animations.idle; stuff.value = -1;
entity.sprite = entity.sprites.idle; 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;
} }
}); });