This commit is contained in:
Schluffe
2026-05-28 19:53:31 +02:00
parent 6a960d7785
commit f8efda0ada
5 changed files with 17 additions and 14 deletions
+7 -7
View File
@@ -8,7 +8,7 @@ export type Viewport = {
canvas: HTMLCanvasElement; canvas: HTMLCanvasElement;
gameContainer: HTMLElement; gameContainer: HTMLElement;
canvasContainer: HTMLElement; canvasContainer: HTMLElement;
bounds: { boundaries: {
minX: number; minX: number;
minY: number; minY: number;
maxX: number; maxX: number;
@@ -27,7 +27,7 @@ export const viewport: Viewport = {
canvas: null as unknown as HTMLCanvasElement, canvas: null as unknown as HTMLCanvasElement,
gameContainer: null as unknown as HTMLElement, gameContainer: null as unknown as HTMLElement,
canvasContainer: null as unknown as HTMLElement, canvasContainer: null as unknown as HTMLElement,
bounds: { boundaries: {
minX: 0, minX: 0,
minY: 0, minY: 0,
maxX: 0, maxX: 0,
@@ -70,7 +70,7 @@ export function resizeCanvas(width: number, height: number): void {
canvasContainer, canvasContainer,
gameContainer, gameContainer,
translation, translation,
bounds, boundaries,
} = viewport; } = viewport;
const containerWidth = (gameContainer.offsetWidth / scale) | 0; 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;`; canvasContainer.style = `width: ${canvasWidth}px; height: ${canvasHeight}px;`;
bounds.minX = translation.x; boundaries.minX = translation.x;
bounds.minY = translation.y; boundaries.minY = translation.y;
bounds.maxX = translation.x + canvas.width; boundaries.maxX = translation.x + canvas.width;
bounds.maxY = translation.x + canvas.height; boundaries.maxY = translation.x + canvas.height;
} }
export function resetCtx() { export function resetCtx() {
+1 -1
View File
@@ -8,9 +8,9 @@ export function createSignal<T>(value: T): [() => T, (value: T) => void] {
const getter = () => { const getter = () => {
current !== null && observers.add(current); current !== null && observers.add(current);
return innerValue; return innerValue;
}; };
const setter = (value: T) => { const setter = (value: T) => {
innerValue = value; innerValue = value;
for (const observer of observers) { for (const observer of observers) {
+5 -5
View File
@@ -29,7 +29,7 @@ sceneChangeSet.add((sceneData) => {
}); });
export function drawSprites(ctx: CanvasRenderingContext2D): void { export function drawSprites(ctx: CanvasRenderingContext2D): void {
const { bounds } = viewport; const { boundaries } = viewport;
visibleDrawables.length = 0; visibleDrawables.length = 0;
for (const drawable of drawables) { for (const drawable of drawables) {
@@ -40,10 +40,10 @@ export function drawSprites(ctx: CanvasRenderingContext2D): void {
const relY = pos.y + sprite.offset.y; const relY = pos.y + sprite.offset.y;
if ( if (
relX + sprite.width > bounds.minX && relX + sprite.width > boundaries.minX &&
relX < bounds.maxX && relX < boundaries.maxX &&
relY + sprite.height > bounds.minY && relY + sprite.height > boundaries.minY &&
relY < bounds.maxY relY < boundaries.maxY
) { ) {
visibleDrawables.push(drawable); visibleDrawables.push(drawable);
} }
+1 -1
View File
@@ -34,7 +34,7 @@ const process = defineEntity("hero", {
}); });
createEffect(() => { createEffect(() => {
console.log(speed()); console.log("speed: ", speed());
}); });
let onceGuard = true; let onceGuard = true;
+3
View File
@@ -83,6 +83,9 @@ process((id, delta) => {
velocity.x = stuff.value * 0.05; velocity.x = stuff.value * 0.05;
position.x += velocity.x * delta; position.x += velocity.x * delta;
// @ts-ignore
window.viewport = viewport;
if (position.x + collider.offset.x > viewport.canvas.width - 16) { if (position.x + collider.offset.x > viewport.canvas.width - 16) {
stuff.value = -1; stuff.value = -1;
animation.value = animations.walk; animation.value = animations.walk;