Level Generation
Posted: Thu Apr 04, 2013 4:04 pm
Hey, I have developed a game and now I am wanting to use sprites to replace the LÖVE geometry with sprites. So I have started dabbling and messing with Sprite batches and quads (I have never used these before) and I have tried to make a simple level generator:
The problem is the only thing that shows up is a few random sprites down the left side of the screen and across the top, not across the whole screen.
Please help :S (I am such a newbie) thanks in advance, Kyle.
Code: Select all
function love.load()
level = {}
for i=1, 25 do
table.insert(level, {})
for i2 = 1, 33 do
table.insert(level[i], math.random(1, 5))
end
end
love.graphics.setDefaultImageFilter("nearest", "nearest")
tileset = love.graphics.newImage("tileset.png")
tickbox_q = love.graphics.newQuad(0, 24, 24, 24, 384, 202)
r_star_q = love.graphics.newQuad(24, 0, 24, 24, 384, 202)
g_star_q = love.graphics.newQuad(72, 0, 24, 24, 384, 202)
explos_q = love.graphics.newQuad(96, 24, 24, 24, 384, 202)
invdot_q = love.graphics.newQuad(48, 48, 24, 24, 384, 202)
spriteBatch = love.graphics.newSpriteBatch(tileset, 25)
for i = 1, #level do
for i2 = 1, #level[i] do
if level[i][i2] == 1 then
spriteBatch:addq(tickbox_q, (i - 1)*24, (i2 - 1)*24)
elseif level[i][i2] == 2 then
spriteBatch:addq(r_star_q, (i - 1)*24, (i2 - 1)*24)
elseif level[i][i2] == 3 then
spriteBatch:addq(g_star_q, (i - 1)*24, (i2 - 1)*24)
elseif level[i][i2] == 4 then
spriteBatch:addq(explos_q, (i2 - 1)*24, (i - 1)*24)
elseif level[i][i2] == 5 then
spriteBatch:addq(invdot_q, (i2 - 1)*24, (i - 1)*24)
end
end
end
end
function love.draw()
love.graphics.draw(spriteBatch, 0, 0)
end
Please help :S (I am such a newbie) thanks in advance, Kyle.