Page 1 of 1

strange behavior w/ graphics

Posted: Sat Mar 10, 2012 7:35 am
by zd
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:

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
Specifically,

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
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

Re: strange behavior w/ graphics

Posted: Sat Mar 10, 2012 11:30 am
by pch
1. open orzia_map.lua
2. go to:

Code: Select all

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
and change:
self.tiles[x][y].graphic = tile_config["map_wall"]
with
self.tiles[x][y].graphic.y = 0

3. start the game - now it works.

Re: strange behavior w/ graphics

Posted: Sat Mar 10, 2012 11:49 am
by coffee
It's nice and I'm glad to see other tile engines suitable for roguelikes and similar games. Do have future plans or just testing? Anyway good work zd!

Re: strange behavior w/ graphics

Posted: Sat Mar 10, 2012 3:29 pm
by zd
coffee wrote:It's nice and I'm glad to see other tile engines suitable for roguelikes and similar games. Do have future plans or just testing? Anyway good work zd!
I don't have any specific future plans but I don't think I'm going to make a roguelike with it (although it was originally a port of a python+libtcod project I started and I do want to preserve some roguelike elements, such as procedural generation)

I was thinking more of a randomly generated dungeon crawler with a party-based combat system. My main inspirations for this project are Lufia II's ancient cave and Atlantic Online's battle system. Whether or not that system (not exact system, but similar) will translate into a single player game remains to be seen. I'd like to do 7-8 tilesets and a few towns. My current "roadmap" looks like

- Finish map display (make tiles rotate based on position, so corners actually show up in corners, walls are facing the correct direction, etc)
- Another layer of sprites on top of the map that adds some flavor to each tileset (small graphical doodads like cracks in the floor, flowers, puddles)
- Animation of sprite movement (so the player's character actually "runs")

If I actually get the tile engine to an "acceptable" place (I'm somewhat of a perfectionist and this is the third language I've ported this project to) I'll probably start searching for an artist.
pch wrote:1. open orzia_map.lua
2. go to:

Code: Select all

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
and change:
self.tiles[x][y].graphic = tile_config["map_wall"]
with
self.tiles[x][y].graphic.y = 0

3. start the game - now it works.
I had a feeling that this was the problem. Is there a way for me to do that assignment (set the graphic to the location specified in the configuration) without linking the two objects in one line?

Code: Select all

self.tiles[x][y].graphic.x = tile_config["map_wall"].x
self.tiles[x][y].graphic.y = tile_config["map_wall"].y
obviously works, but I hate having to do the assignment in two lines

Thanks for the help!

Re: strange behavior w/ graphics

Posted: Sat Mar 10, 2012 4:47 pm
by coffee
zd wrote:
I don't have any specific future plans but I don't think I'm going to make a roguelike with it (although it was originally a port of a python+libtcod project I started and I do want to preserve some roguelike elements, such as procedural generation)

I was thinking more of a randomly generated dungeon crawler with a party-based combat system. My main inspirations for this project are Lufia II's ancient cave and Atlantic Online's battle system. Whether or not that system (not exact system, but similar) will translate into a single player game remains to be seen.
That's a pretty good variation to flat rogues! That also remembered me somewhat Mysterious Castle (random gen map + party style). If you don't know it yet you could like try it http://www.mysteriouscastle.com/. Have fun finding your style and keep posting some news. :)

Re: strange behavior w/ graphics

Posted: Sun Mar 11, 2012 12:28 pm
by Nixola

Code: Select all

self.tiles[x][y].graphic.x, self.tiles[x][y].graphic.y = tile_config["map_wall"].x, tile_config["map_wall"].y