Tile

Pick out one grass tile. Move sideways until the highlight jumps to its neighbour.
Interactive demo#TilesAndWorlds
A small square image made to sit in a grid next to others.
Most 2D levels are built like a mosaic: a few dozen small squares repeated thousands of times. Tiles are the same size, so the game can find “what’s at this spot?” with simple arithmetic.
Code
namespace tile_lesson;
import stage;
import std;
import math;
export "tile" fn draw(time: f64, dt: f64, px: f64, py: f64, hover: bool) {
artwork("valley");
rect(0, 0, W, H, "rgba(26,43,55,0.43)");
draw_map(cell_count(), -1);
grid(0.35);
let col = clamp(floor(px / 8.0), 0.0, 19.0);
let row = clamp(floor((py - MY) / 8.0), 0.0, 6.0);
let kind = tile_at(col, row);
box(col * 8 - 1, MY + row * 8 - 1, 10, 10, MAG);
checker(6, 6, 32, 32, 8);
if kind >= 0 {
tile_image(kind, 6, 6, 4);
}
box(5, 5, 34, 34, MAG);
}

Comments
No comments yet.