Page 1 of 1

[SOLVED]ASCII Map Generation Problem

Posted: Mon Jun 16, 2014 8:22 pm
by ponger3d
Hello, I'm new to LOVE and have been messing around with it to learn the loops. Recently I have tried making a simple map in ASCII. The code runs but the map is not turning out How I want it to be.

Image


The red clump in the top left hand corner is suppose to be a 20x20 map, with "." and "#". I was expecting for there to be spaces between then characters instead of having this one large heap. I have attempted to solve it but am at a stump now.

I use this code to draw the map:

Code: Select all

function draw_map()
	for y=1, map_h do
		for x=1, map_w do
			if map[y][x] == 0 then
				love.graphics.print(".", x + map_offset_x, y + map_offset_y)
				
			else
				love.graphics.print("#", x + map_offset_x, y + map_offset_y)
				
			end
		end
	end
end
And this is the actual code for the map:

Code: Select all

--map variables
map_w = 20
map_h = 20
map_x = 0
map_y = 0
map_offset_x = 30
map_offset_y = 30

map = {
	{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
	{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
	{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
	{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
	{ 0, 0, 0, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
	{ 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
	{ 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
	{ 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
	{ 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
	{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
	{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
	{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 0, 0},
	{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0},
	{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0},
	{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 1, 0, 0},
	{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 0},
	{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 0},
	{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0},
	{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
	{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
}
I have attached the .love file below. Any help will be much appreciated! I'm sure it is something simple, I'm just not smart enough to figure it out! Thanks again for the help!

Re: ASCII Map Generation Problem

Posted: Mon Jun 16, 2014 8:52 pm
by lachlaan

Code: Select all

    function draw_map()
       for y=1, map_h do
          for x=1, map_w do
             if map[y][x] == 0 then
                love.graphics.print(".", x + map_offset_x, y + map_offset_y)  <---                 
             else
                love.graphics.print("#", x + map_offset_x, y + map_offset_y)
                
             end
          end
       end
    end
Multiply the index values by the desired width of one element / the desired distance between the start of one character and the start of the next.

Code: Select all

                 love.graphics.print(".", x*10+ map_offset_x, y*16 + map_offset_y)

Re: ASCII Map Generation Problem

Posted: Mon Jun 16, 2014 9:33 pm
by ponger3d
Thank You so much!