From f8efda0ada411024b65cd669ba24d439f5a62ad1 Mon Sep 17 00:00:00 2001 From: Schluffe Date: Thu, 28 May 2026 19:53:31 +0200 Subject: [PATCH] WIP --- engine/Viewport.ts | 14 +++++++------- engine/lib/Signal.ts | 2 +- engine/system/drawSprites.ts | 10 +++++----- game/entities/hero/entity.ts | 2 +- game/entities/testEntity/entity.ts | 3 +++ 5 files changed, 17 insertions(+), 14 deletions(-) diff --git a/engine/Viewport.ts b/engine/Viewport.ts index 1d46dac..7af503b 100644 --- a/engine/Viewport.ts +++ b/engine/Viewport.ts @@ -8,7 +8,7 @@ export type Viewport = { canvas: HTMLCanvasElement; gameContainer: HTMLElement; canvasContainer: HTMLElement; - bounds: { + boundaries: { minX: number; minY: number; maxX: number; @@ -27,7 +27,7 @@ export const viewport: Viewport = { canvas: null as unknown as HTMLCanvasElement, gameContainer: null as unknown as HTMLElement, canvasContainer: null as unknown as HTMLElement, - bounds: { + boundaries: { minX: 0, minY: 0, maxX: 0, @@ -70,7 +70,7 @@ export function resizeCanvas(width: number, height: number): void { canvasContainer, gameContainer, translation, - bounds, + boundaries, } = viewport; const containerWidth = (gameContainer.offsetWidth / scale) | 0; @@ -87,10 +87,10 @@ export function resizeCanvas(width: number, height: number): void { canvasContainer.style = `width: ${canvasWidth}px; height: ${canvasHeight}px;`; - bounds.minX = translation.x; - bounds.minY = translation.y; - bounds.maxX = translation.x + canvas.width; - bounds.maxY = translation.x + canvas.height; + boundaries.minX = translation.x; + boundaries.minY = translation.y; + boundaries.maxX = translation.x + canvas.width; + boundaries.maxY = translation.x + canvas.height; } export function resetCtx() { diff --git a/engine/lib/Signal.ts b/engine/lib/Signal.ts index b871e6d..69f9dd1 100644 --- a/engine/lib/Signal.ts +++ b/engine/lib/Signal.ts @@ -8,9 +8,9 @@ export function createSignal(value: T): [() => T, (value: T) => void] { const getter = () => { current !== null && observers.add(current); - return innerValue; }; + const setter = (value: T) => { innerValue = value; for (const observer of observers) { diff --git a/engine/system/drawSprites.ts b/engine/system/drawSprites.ts index 60db4f3..c1dba60 100644 --- a/engine/system/drawSprites.ts +++ b/engine/system/drawSprites.ts @@ -29,7 +29,7 @@ sceneChangeSet.add((sceneData) => { }); export function drawSprites(ctx: CanvasRenderingContext2D): void { - const { bounds } = viewport; + const { boundaries } = viewport; visibleDrawables.length = 0; for (const drawable of drawables) { @@ -40,10 +40,10 @@ export function drawSprites(ctx: CanvasRenderingContext2D): void { const relY = pos.y + sprite.offset.y; if ( - relX + sprite.width > bounds.minX && - relX < bounds.maxX && - relY + sprite.height > bounds.minY && - relY < bounds.maxY + relX + sprite.width > boundaries.minX && + relX < boundaries.maxX && + relY + sprite.height > boundaries.minY && + relY < boundaries.maxY ) { visibleDrawables.push(drawable); } diff --git a/game/entities/hero/entity.ts b/game/entities/hero/entity.ts index 74ad4cf..d5c7167 100644 --- a/game/entities/hero/entity.ts +++ b/game/entities/hero/entity.ts @@ -34,7 +34,7 @@ const process = defineEntity("hero", { }); createEffect(() => { - console.log(speed()); + console.log("speed: ", speed()); }); let onceGuard = true; diff --git a/game/entities/testEntity/entity.ts b/game/entities/testEntity/entity.ts index a02da56..7706917 100644 --- a/game/entities/testEntity/entity.ts +++ b/game/entities/testEntity/entity.ts @@ -83,6 +83,9 @@ process((id, delta) => { velocity.x = stuff.value * 0.05; position.x += velocity.x * delta; + // @ts-ignore + window.viewport = viewport; + if (position.x + collider.offset.x > viewport.canvas.width - 16) { stuff.value = -1; animation.value = animations.walk;