Code: Select all
block = {}
player = {}
--load the images
backgroung_img = love.graphics.newImage("textures/photo.png")
block_img = love.graphics.newImage("textures/block.png")
player_img = love.graphics.newImage("textures/player.png")
function love.load()
player.x = 0
player.y = 0
table.insert(block, {x = 0, y = 50})
table.insert(block, {x = 50, y = 50})
end
function love.draw()
x, y = love.mouse.getPosition()
--draw the background
love.graphics.setColor(255, 130, 130, 255)
love.graphics.draw(backgroung_img, 0, 0)
--draw the blocks
love.graphics.setColor(255, 255, 255, 255)
love.graphics.draw(block_img, x, y)
for i, v in pairs(block) do
love.graphics.draw(block_img, block[i].x, block[i].y)
end
--draw the player
love.graphics.setColor(255, 130, 130, 255)
love.graphics.draw(player_img, player.x, player.y)
end
function love.update(dt)
x, y = love.mouse.getPosition()
if love.mouse.isDown("l") then
table.insert(block, {x = x, y = y})
end
--Gravity!
for i, v in pairs(block) do
if CheckCollision(player.x, player.y, 50, 50, block[i].x, block[i].y, 50, 50) then
else
player.y = player.y + 10*dt
end
end
--move left
if love.keyboard.isDown("left") then
player.x = player.x - 190*dt
end
--move right
if love.keyboard.isDown("right") then
player.x = player.x + 190*dt
end
end
function CheckCollision(x1,y1,w1,h1, x2,y2,w2,h2)
return x1 < x2+w2 and
x2 < x1+w1 and
y1 < y2+h2 and
y2 < y1+h1
end