BearNecessities icon indicating copy to clipboard operation
BearNecessities copied to clipboard

Use Matrix for Tile Map?

Open sn3p opened this issue 5 years ago • 3 comments

related #28

Matrices are used in most tile-based games afaik. For Elixir there is the Matrix modules which might be helpful. Not sure if this is something for us.

Some resources on this

Basic example from the demo above

const map = {
  cols: 8,
  rows: 8,
  tsize: 64,
  tiles: [
    1, 3, 3, 3, 1, 1, 3, 1,
    1, 1, 1, 1, 1, 1, 1, 1,
    1, 1, 1, 1, 1, 2, 1, 1,
    1, 1, 1, 1, 1, 1, 1, 1,
    1, 1, 1, 2, 1, 1, 1, 1,
    1, 1, 1, 1, 2, 1, 1, 1,
    1, 1, 1, 1, 2, 1, 1, 1,
    1, 1, 1, 0, 0, 1, 1, 1
  ],
  getTile: (col, row) => {
    return this.tiles[row * map.cols + col]
  }
};

translated to:

no-scroll

sn3p avatar Apr 16 '19 08:04 sn3p