Tilemap

Watch the magenta cursor rebuild the level. Can you spot two cells that reuse the same drawing?
#TilesAndWorldsF-ZEROSNES era#Tile
A grid of numbers saying which tile goes in each cell of a level.
The level itself isn’t an image. It’s a table: row 5, column 3 holds “grass”. The game reads the table and stamps the matching tile in each cell, which makes levels tiny to store and easy to edit.
Code
namespace tilemap_lesson;
import stage;
import std;
import math;
export "tilemap" fn draw(time: f64, dt: f64, px: f64, py: f64, hover: bool) {
let total = cell_count();
let count = min(total, (time % (total / 14.0 + 2.5) * 14) as i32);
artwork("valley");
rect(0, 0, W, H, "rgba(26,43,55,0.43)");
grid(0.6);
draw_map(count, -1);
if count < total {
box(cell_x(count) * 8 - 1, MY + cell_y(count) * 8 - 1, 10, 10, MAG);
}
}

Comments
No comments yet.