Code: Select all
function love.load()
map_display_h = 15
map_display_w = 15
tile_w = 16
tile_h = 16
--NOTE: X comes before Y in the creation part so the array becomes map[X][Y] and not map[Y][X]
map = {}
for x=1, map_display_w do
map[x] = {}
for y=1, map_display_h do
map[x][y] = {
hit = math.random(0,1)
}
end
end
Then the second part of the code does the loop part. It'll use the variables storing the grid size in the loop process, the first for will loop 16 times the second for that'll also loop 16 times that code that says "hit = math.random(0,1)" although I don't know what it mean and does. Also why the second loop has "[x][y]" other than just "[y]" on it?
Code: Select all
function love.draw()
for y=1, map_display_h do -- this y=1 means that we're setting the variable y with 1 and using it on map[x][y] like x=1 in the second for?
for x=1, map_display_w do --
if map[x][y] == 1 then
love.graphics.setColor(0,0,0)
else
love.graphics.setColor(255,255,255)
end
love.graphics.rectangle("fill", x + map_offset_x, y + map_offset_y)
end
end
end
What I didn't understand about "hit = math.random(0,1) is that:
Wont it generate numbers over 16?
Does it have a chance to generate the same numbers more than once?
Why (0,1) not (0,0)?
Other than that, thanks for this help. It clarifies thinks a LOT for me now. Really.