Code: Select all
collision = "Null"
fallingtrue = 0
fallspeed = 100
falling = {}
function love.load()
player_x = 0
player_y = 360
fuel = 0
counter = 0
player = love.graphics.newImage("babyduck.png")
background = love.graphics.newImage("rain_background.png")
end
function love.update(dt)
counter = counter +(math.ceil(dt) )
if fallingtrue > 1 then
for i = 0,13 do
enemy = {}
enemy.width = 20
enemy.height = 20
enemy.x = i * (enemy.width + 100) + (math.random(-100, 100))
enemy.y = 0
table.insert(falling, enemy)
end
fallingtrue = 0
end
if counter == 500 then
fallingtrue = 5
end
if fuel > 0 then
fuel = fuel - .5
end
if player_x > 1200 then
player_x = -20
end
if player_x < -40 then
player_x = 1200
end
if player_y < 10 then
player_y = 10
end
if love.keyboard.isDown("right") then
player_x = player_x + 2
end
if love.keyboard.isDown("left") then
player_x = player_x - 2
end
if love.keyboard.isDown("escape") then
love.event.push("quit")
end
if love.keyboard.isDown("up") and fuel < 600 then
player_y = player_y - 2.3
fuel = fuel + 2
end
if player_y < 360 then
player_y = player_y + 1
end
for i,v in ipairs(falling) do
if player_x > (v.x + v.height) or player_x + 40 < v.x then
collision = "Miss"
else
collision = "HIT"
end
v.y = v.y + (dt * fallspeed)
if v.y > 450 then
table.remove(falling, i)
fallingtrue = fallingtrue + .1
if fallspeed < 700 then
fallspeed = fallspeed + 5
end
end
end
end
function love.draw()
love.graphics.draw(background, 0, 0)
love.graphics.draw(player, player_x, player_y)
love.graphics.setColor(255,255,255,255)
love.graphics.print(fuel, 10, 10)
love.graphics.print(counter, 10, 40)
love.graphics.print(collision, 10, 70)
love.graphics.setColor(255,0,255,255)
for i,v in ipairs(falling) do
love.graphics.rectangle("fill", v.x, v.y, v.width, v.height)
end
end