Skip to content

tilemap.um

Marek Maskarinec edited this page Oct 9, 2022 · 6 revisions

tilemap.um

 Tilemaps allow for easy level construction and fast collisions. You can even
 use them for some games instead of entities (tetris comes to mind)

struct Tilemap*

type Tilemap* = struct {
	atlas: atlas.Atlas
	pos: th.Vf2
	w: th.uu // width of tilemap
	cells: []th.uu // all cells (this will draw the tile in tiles with number in cells - 1)
	collMask: []bool // if true, the tile collides
	scale: th.fu
}

Tilemap struct

fn mk*

fn mk*(cells: []th.uu, w: th.uu, at: atlas.Atlas, scale: th.fu = 1): Tilemap {

fn edit*

fn (t: ^Tilemap) edit*(x, y, tile: int) {

Sets tile at [x, y] to tile.

fn draw*

fn (t: ^Tilemap) draw*(cam: rect.Rect) {

Draws the tilemap.

fn getColl*

fn (t: ^Tilemap) getColl*(e: ent.Ent, vert: ^th.uu, pos: ^th.Vf2): bool {

Checks, if t collides with e. pos is the tile index where the collision happened vert is which index collided You need to pass a valid pointer (TODO)

fn autotile*

fn (t: ^Tilemap) autotile*(src, tileCfg: []th.uu, tile: th.uu) {

Autotile turns all tile tiles in src into tiles in tileCfg, so they follow up correctly. tileCfg is an array of 16 tiles. They are placed in a way where OR of all the places where the tile continues (top, right bot, right). The constants for them are defined in this file. Example: tileCfg[top | bot] = 21 top | bot would look something like this: |

Clone this wiki locally