LARGURA_TELA = 320
ALTURA_TELA = 480
MAX_METEOROS = 12
aviao_14bis = {
src = "14bis.png",
largura = 64,
altura = 64,
x = LARGURA_TELA / 2 - 64 / 2,
y = ALTURA_TELA - 64/2
}
meteoros = {}
function removeMeteoros()
for i = #meteoros, 1, -1 do
if meteoros[i].y > ALTURA_TELA then
table.remove(meteoros, i)
end
end
end
function criaMeteoro()
meteoro = {
x = math.random(LARGURA_TELA),
y = 0
}
table.insert(meteoros, meteoro)
end
function moveMeteoros()
for k, v in pairs(meteoros) do
meteoro.y = meteoro.y + 1
end
end
function move14bis()
if love.keyboard.isDown('w') then
aviao_14bis.y = aviao_14bis.y - 1
end
if love.keyboard.isDown('s') then
aviao_14bis.y = aviao_14bis.y + 1
end
if love.keyboard.isDown('a') then
aviao_14bis.x = aviao_14bis.x - 1
end
if love.keyboard.isDown('d') then
aviao_14bis.x = aviao_14bis.x + 1
end
end
function love.load()
love.window.setMode(LARGURA_TELA, ALTURA_TELA, {resizable = false})
love.window.setTitle("14bis vs Meteoros")
background = love.graphics.newImage("background.png")
aviao_14bis.imagem = love.graphics.newImage(aviao_14bis.src)
meteoro_img = love.graphics.newImage("meteoro.png")
end
function love.update(dt)
if love.keyboard.isDown('w', 'a', 's', 'd') then
move14bis()
end
if #meteoros < MAX_METEOROS then
criaMeteoro()
end
moveMeteoros()
end
function love.draw()
love.graphics.draw(background, 0, 0)
love.graphics.draw(aviao_14bis.imagem, aviao_14bis.x, aviao_14bis.y)
for k,meteoro in pairs(meteoros) do
love.graphics.draw(meteoro_img, meteoro.x, meteoro.y)
end
end
Obs: esta caindo apenas um meteoro