recursively update tiles within boxes.

This commit is contained in:
HyperOnion 2023-06-28 15:03:22 +02:00
parent b5574e33fa
commit a55eb310b0
2 changed files with 8 additions and 4 deletions

View File

@ -1,5 +1,5 @@
import * as graphics from "./graphics.mjs";
import { BOX_SIZE, get_tile } from "./world.mjs";
import { BOX_SIZE, get_tile, get_root } from "./world.mjs";
import { get_player_box } from "./player.mjs";
import { save_in_browser, load_from_browser } from "./save_load.mjs";
import { tick } from "/js/tile_update.mjs";
@ -21,7 +21,7 @@ function main (timestamp) {
const delta = dt_ms / 1000;
render(delta);
tick(delta);
tick(get_root(), delta);
requestAnimationFrame(main);
}

View File

@ -6,8 +6,7 @@ import * as random from "/js/utils/random.mjs";
// lots of this code is very hacky temporary for testing things out & getting started with tile updates.
export function tick (delta_time) {
const box = get_player_box();
export function tick (box, delta_time) {
world.for_each_tile(box, (x, y, tile) => {
if (tile_tickers.has(tile.type)) {
tile_tickers.get(tile.type)(box, x, y, delta_time);
@ -24,6 +23,11 @@ const dirs = [
[ 0, 1 ],
];
// this might become terrible for performance eventually.
tile_tickers.set("box", (box, x, y, delta_time) => {
tick(world.get_tile(box, x, y).box, delta_time);
});
tile_tickers.set("grass", (box, x, y, delta_time) => {
const tile = world.get_tile(box, x, y);
if (Math.random() > 0.8 ** delta_time) {