Skip to content

Instantly share code, notes, and snippets.

@komiga
Created June 3, 2010 20:16
Show Gist options
  • Save komiga/424407 to your computer and use it in GitHub Desktop.
Save komiga/424407 to your computer and use it in GitHub Desktop.
Tile: class {
id: Int
init: func (=id)
println: func (x, y: Int) {
"%d, %d: %d" format(x, y, id) println()
}
}
Map: class {
width, height: Int
array: Tile*
init: func (=width, =height) {
array = gc_malloc(width * height) as Tile*
}
setTileAtPos: func (x, y:Int, tile: Tile) {
array[x * width + y] = tile
}
getTileAtPos: func (x, y:Int) -> Tile {
if (checkPos(x, y))
return array[x * width + y]
else
return null
}
checkPos: func (x, y:Int) -> Bool {
if (x > -1 && x < width && y > -1 && y < height)
return true
else
return false
}
}
main: func {
width := 8; height := 8
map := Map new(width, height)
for (x in 0..width) {
for (y in 0..height) {
map setTileAtPos(x, y, Tile new(x * width + y))
}
}
for (x in 0..width) {
for (y in 0..height) {
tile := map getTileAtPos(x, y)
tile println(x, y)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment