Skip to content

Commit

Permalink
Initial import
Browse files Browse the repository at this point in the history
  • Loading branch information
nddrylliog committed Jun 4, 2010
1 parent 5acba52 commit a5bde9a
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
58 changes: 58 additions & 0 deletions Map.ooc
@@ -0,0 +1,58 @@
import Tile

// debug code
d: func (s: String) { fprintf(stderr, "%s\n", s) }

// test code
Map new() redraw()

Map: class {
tiles: Tile[][]

mapw = 32, maph = 32 : static const UInt

init: func {
d("Initializing map")
tiles = Tile[mapw][maph] new()

for (x in 0..mapw) {
for (y in 0..maph) {
this setTileAtPos(x, y, Tile new(x * mapw + y))
}
}
}

setTileAtPos: func (x, y:Int, tile: Tile) {
tiles[x][y] = tile
}

getTileAtPos: func (x, y:Int) -> Tile {
if (checkPos(x, y))
return tiles[x][y]
else
return null
}

checkPos: func (x, y:Int) -> Bool {
if (x > -1 && x < mapw && y > -1 && y < maph)
return true
else
return false
}

redraw: func() {
d("Redraw called")
tile: Tile

d("Mapw %d Maph %d" format(mapw, maph))

for (x in 0..this mapw) {
d("In loop for x %d" format(x))
for (y in 0..this maph) {
tile = getTileAtPos(x, y)
tile println(x, y)
}
}
}
}

13 changes: 13 additions & 0 deletions Tile.ooc
@@ -0,0 +1,13 @@

Drawable: class {}

Tile: class extends Drawable {
id: ULong

init: func (=id)

// println gives a segfault
println: func (x: Int, y: Int) {
"(%d, %d, %ld)" format(x, y, id) println()
}
}

0 comments on commit a5bde9a

Please sign in to comment.