[SOLVED]ASCII Map Generation Problem

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
ponger3d
Prole
Posts: 6
Joined: Mon Jun 16, 2014 8:00 pm

[SOLVED]ASCII Map Generation Problem

Post 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!
Attachments
simple_map.love
(1.59 KiB) Downloaded 94 times
Last edited by ponger3d on Mon Jun 16, 2014 11:42 pm, edited 1 time in total.
lachlaan
Prole
Posts: 30
Joined: Sun Jun 30, 2013 7:23 pm

Re: ASCII Map Generation Problem

Post 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)
ponger3d
Prole
Posts: 6
Joined: Mon Jun 16, 2014 8:00 pm

Re: ASCII Map Generation Problem

Post by ponger3d »

Thank You so much!
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 9 guests