Unfinished webgl renderer
This commit is contained in:
@@ -2,25 +2,24 @@ import { get_sprite_region } from "$/common/utils.ts";
|
||||
import { Dimension } from "$/client/components/dimension.ts";
|
||||
import { TEXTURE_SIZE, TILE_SIZE } from "$/common/constants.ts";
|
||||
import { Camera, world_to_screen } from "$/client/components/camera.ts";
|
||||
import { canvas, draw_texture_region } from "../../renderer.ts";
|
||||
|
||||
export function render_dimension(ctx: CanvasRenderingContext2D, tilemap: Dimension, camera: Camera) {
|
||||
ctx.save();
|
||||
|
||||
export function render_dimension(tilemap: Dimension, camera: Camera) {
|
||||
for (const tile of tilemap.tiles) {
|
||||
const region = get_sprite_region(tile.id);
|
||||
|
||||
const x = tile.x * TILE_SIZE;
|
||||
const y = tile.y * TILE_SIZE;
|
||||
|
||||
const screen_position = world_to_screen(x, y, camera, ctx.canvas.width, ctx.canvas.height);
|
||||
const screen_position = world_to_screen(x, y, camera, canvas.width, canvas.height);
|
||||
if (
|
||||
screen_position.x + TILE_SIZE < 0 || screen_position.x > ctx.canvas.width ||
|
||||
screen_position.y + TILE_SIZE < 0 || screen_position.y > ctx.canvas.height
|
||||
screen_position.x + TILE_SIZE < 0 || screen_position.x > canvas.width ||
|
||||
screen_position.y + TILE_SIZE < 0 || screen_position.y > canvas.height
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ctx.drawImage(
|
||||
draw_texture_region(
|
||||
tilemap.image,
|
||||
region.x * TEXTURE_SIZE,
|
||||
region.y * TEXTURE_SIZE,
|
||||
@@ -32,6 +31,4 @@ export function render_dimension(ctx: CanvasRenderingContext2D, tilemap: Dimensi
|
||||
TILE_SIZE,
|
||||
);
|
||||
}
|
||||
|
||||
ctx.restore();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user