31 lines
673 B
Plaintext
31 lines
673 B
Plaintext
// tilemap.js - MUCH SIMPLER
|
|
var tilemap = {
|
|
tiles: [], // Just strings: [['grass', 'dirt'], ['stone', null]]
|
|
offset_x: 0,
|
|
offset_y: 0,
|
|
layer: 0,
|
|
tile_width: 1, // world units
|
|
tile_height: 1,
|
|
at(pos) {
|
|
var x = pos.x - this.offset_x
|
|
var y = pos.y - this.offset_y
|
|
if (!this.tiles[x]) return null
|
|
return this.tiles[x][y]
|
|
},
|
|
set(pos, image) {
|
|
var x = pos.x - this.offset_x
|
|
var y = pos.y - this.offset_y
|
|
|
|
// Expand tiles array if needed
|
|
while (this.tiles.length <= x)
|
|
this.tiles.push([])
|
|
|
|
while (this.tiles[x].length <= y)
|
|
this.tiles[x].push(null)
|
|
|
|
this.tiles[x][y] = image
|
|
},
|
|
}
|
|
|
|
return tilemap
|