[oden][game] Draw the world

This involved basically a giant rewrite of the renderer because I now
need to share the vertex buffer across textures and it is *a lot* let
me tell you.

There's like a vertical seam which I don't understand yet.
This commit is contained in:
John Doty 2023-08-07 10:05:24 -07:00
parent 22327a71b3
commit f9648d88cd
7 changed files with 936 additions and 595 deletions

View file

@ -2,8 +2,8 @@ import { cls, print, spr, use_texture, Texture } from "./graphics";
import { load_texture } from "./assets";
import { since_start } from "./time";
import { btn, Button } from "./input";
// import { load_string } from "./io";
import { new_v2, vadd, vmul, vnorm } from "./vector";
import { load_world, World, Level, draw_level } from "./level";
/// TODO: Support reload by saving and restoring state from init/update/restore.
@ -11,6 +11,8 @@ import { new_v2, vadd, vmul, vnorm } from "./vector";
let clock = 0;
let bot_sprite: Texture | undefined = undefined;
let world: World | undefined = undefined;
let level: Level | undefined = undefined;
// Note zelda overworld is 16x8 screens
// zelda screen is 16x11 tiles
@ -18,13 +20,6 @@ let bot_sprite: Texture | undefined = undefined;
let loaded = false;
async function load_map(path: string) {
// print("Loading map:", path);
// const blob = await load_string(path);
// const map = JSON.parse(blob);
// print("Loaded map:", map);
}
function load_assets() {
// Start this load, but then...
let texture_load = load_texture("./bot.png").then((n) => {
@ -32,7 +27,16 @@ function load_assets() {
bot_sprite = n;
});
let map_load = load_map("./overworld.ldtk");
let map_load = load_world("./overworld.ldtk").then((w) => {
print("World loaded at", since_start());
world = w;
// Assume we start at 0,0
level = world.levels.find((l) => l.world_x == 0 && l.world_y == 0);
if (!level) {
throw new Error("UNABLE TO FIND LEVEL AT 0,0: CANNOT START");
}
});
Promise.all([texture_load, map_load]).then(() => {
loaded = true;
@ -106,6 +110,10 @@ export function draw() {
return;
}
if (level != undefined) {
draw_level(level, 0, 0);
}
if (bot_sprite != undefined) {
// ...it gets resolved here?
use_texture(bot_sprite);