Point at the terrain to push it up.

0:01 / 0:30
Playback speed

Autotile

Raise a patch of terrain, then switch autotiling off. Look at the tiles along its new edge.

Interactive demo#TilesAndWorlds#Tile

Tiles that pick their own edges by looking at their neighbours.

You paint “ground”; the game works out which cells need a grassy top, a corner, or plain dirt. Without it you’d place every edge piece by hand. Turn it off to see the same terrain with no rules applied.

Code

src/demos/autotile.goose
namespace autotile_lesson;
import stage;
import std;
import math;

export "autotile" fn draw(time: f64, dt: f64, px: f64, py: f64, hover: bool) {
    let enabled = toggle("on");
    let t = time * 0.6;
    artwork("valley");
    rect(0, 0, W, H, "rgba(26,43,55,0.43)");
    for i in 20 {
        var height = 4 + 2 * sin(i * 0.6 + t) + 1.5 * sin(i * 0.23 - t * 0.7);
        if hover {
            height += max(0.0, 4.0 - abs(i - px / 8.0)) * (1 - py / H) * 2;
        }
        let rows = clamp(floor(height + 0.5), 1.0, 11.0) as i64;
        for j in rows {
            let kind = if enabled && j == rows - 1 { 0 } else { 1 };
            tile_image(kind, i * 8, H - 8 - j * 8, 1);
        }
    }
}

Stage drawing helpers · All demos on GitHub

Comments

No comments yet.