From a5bde9aa720dd9de70e5a9d917e106ee577c2ea9 Mon Sep 17 00:00:00 2001 From: nddrylliog Date: Fri, 4 Jun 2010 10:09:33 +0200 Subject: [PATCH] Initial import --- Map.ooc | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Tile.ooc | 13 +++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 Map.ooc create mode 100644 Tile.ooc diff --git a/Map.ooc b/Map.ooc new file mode 100644 index 0000000..fae1622 --- /dev/null +++ b/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) + } + } + } +} + diff --git a/Tile.ooc b/Tile.ooc new file mode 100644 index 0000000..6681975 --- /dev/null +++ b/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() + } +}