strange behavior w/ graphics

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
zd
Prole
Posts: 5
Joined: Thu Mar 08, 2012 2:27 am

strange behavior w/ graphics

Post by zd » 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:

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
Attachments
orzia.love
(1014.46 KiB) Downloaded 36 times

User avatar
pch
Prole
Posts: 32
Joined: Sun Mar 04, 2012 5:17 pm
Location: poland

Re: strange behavior w/ graphics

Post by pch » Sat Mar 10, 2012 11:30 am

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.

coffee
Party member
Posts: 1206
Joined: Wed Nov 02, 2011 9:07 pm

Re: strange behavior w/ graphics

Post by coffee » Sat Mar 10, 2012 11:49 am

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!

zd
Prole
Posts: 5
Joined: Thu Mar 08, 2012 2:27 am

Re: strange behavior w/ graphics

Post by zd » Sat Mar 10, 2012 3:29 pm

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!

coffee
Party member
Posts: 1206
Joined: Wed Nov 02, 2011 9:07 pm

Re: strange behavior w/ graphics

Post by coffee » Sat Mar 10, 2012 4:47 pm

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. :)

User avatar
Nixola
Inner party member
Posts: 1941
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: strange behavior w/ graphics

Post by Nixola » Sun Mar 11, 2012 12:28 pm

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
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics

Post Reply

Who is online

Users browsing this forum: No registered users and 40 guests