Hi. I’m trying to recreate mojang’s Catacomb Snatch, in slick… so I can learn a bit more about game programming. And I have a few problems right now.
I created Tile classes ( Tile, WallTile, FloorTile etc ). Also created Level Class to setTile( initialize tile )… and other stuff. Right now, in my Play class, I’m creating tiles based on color from level image, and store them in array Tile[][]. Then in floortile class I need to determine does the tile next to it cast shadow, if so, set the floortile to be the one with shadow. It works picking up left and top tile from level, but right tile doesn’t. Here is the code :
Play class stuff :
tiles = new Tile[level.getWidth()][level.getHeight()];
for (int y = 0; y < level.getHeight(); y++) {
for (int x = 0; x < level.getWidth(); x++) {
int col;
col = level.getColor(x, y);
if (col == 0xFF0000)
tile = new WallTile();
else if (col == 0x000000) {
if (y > 0) {
if (tiles[x][y - 1] instanceof FloorTile) {
tile = new EdgeTile();
} else
tile = new HoleTile();
}
} else if (col == 0xff7777)
tile = new TreasureTile();
else
tile = new FloorTile();
tiles[x][y] = tile;
level.setTile(tiles, x, y);
}
}
FloorTile:
public void init(Level level, int x, int y) {
super.init(level, x, y);
shadowateTile();
}
private void shadowateTile() {
Tile w = level.getTile(x - 1, y);
Tile n = level.getTile(x, y - 1);
Tile s = level.getTile(x, y + 1);
Tile e = level.getTile(x + 1, y);
tile = randomTile(floortiles, 4, TileSize, TileSize, 0, 0);
if (w != null && w.castShadow())
tile = cutTile(floortiles, TileSize, TileSize, 64, 32);
if (n != null && n.castShadow())
tile = cutTile(floortiles, TileSize, TileSize, 32, 64);
if(e != null && e.castShadow())
tile = cutTile(floortiles, TileSize, TileSize, 96,32);
}
public void render() {
tile.draw(x * 32, y * 32);
}
Level class :
public void setTile(Tile[][] tiles, int x, int y) throws SlickException {
this.tiles = tiles;
this.tiles[x][y].init(this, x, y);
}
public Tile getTile(int x, int y) {
if (x < 0 || y < 0 || x > 47 || y > 47)
return null;
return tiles[x][y];
}
I saw mojang team uses different way of setting the tiles, like Tile[x + y * width]; … I don’t know how to set that up unfortunately…