strange behavior w/ graphics
Posted: Sat Mar 10, 2012 7:35 am
The issue I seem to be having is when I'm determining which tile to display based on the underlying map generated.
The "problem" seems to be cropping up here:
Specifically,
Now, it seems to me that some of the tiles with 3 adjacent walls should display tile 0 and some should display tile 2. But, they will all display only one tile. So if the rng randoms 1, ALL of the tiles will be 2. If the RNG randoms 2 ALL of the tiles switch to 0.
For a simple illustration, run the program a few times and you'll see the walls will either ALL display or NONE of them will display. Completely randomly (like the function is set up to do - just it should be doing it tile by tile)
I've attached the LOVE file
The "problem" seems to be cropping up here:
Code: Select all
function orzia_map:determineTileGraphics(tile_config)
for x = 0, self.size_x - 1 do
for y = 0, self.size_y - 1 do
if self.tiles[x][y]:countWalls(self.tiles) == 9 then
self.tiles[x][y].graphic = tile_config["empty"]
else
if self.tiles[x][y].blocked == true then
local adjacentWalls = self.tiles[x][y]:countWallsAdjacent(self.tiles)
if adjacentWalls == 0 then
self.tiles[x][y].graphic = tile_config["map_island"]
elseif adjacentWalls == 1 then
self.tiles[x][y].graphic = tile_config["map_nub"]
elseif adjacentWalls == 2 then
self.tiles[x][y].graphic = tile_config["map_corner"] -- need to detect whether its a corner or a corridor
elseif adjacentWalls == 3 then
self.tiles[x][y].graphic = tile_config["map_wall"]
if math.random(3) == 2 then
self.tiles[x][y].graphic.x = 0
else
self.tiles[x][y].graphic.x = 2
end
end
else
self.tiles[x][y].graphic = tile_config["map_floor"]
end
end
end
end
end
Code: Select all
if math.random(3) == 2 then
self.tiles[x][y].graphic.x = 0
else
self.tiles[x][y].graphic.x = 2
end
For a simple illustration, run the program a few times and you'll see the walls will either ALL display or NONE of them will display. Completely randomly (like the function is set up to do - just it should be doing it tile by tile)
I've attached the LOVE file