Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
nddrylliog
committed
Jun 4, 2010
1 parent
5acba52
commit a5bde9a
Showing
2 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() | ||
} | ||
} |