recursively update tiles within boxes.
This commit is contained in:
parent
3e4e58e2a2
commit
b389e3b401
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue