Code: Select all
jump = true
function love.keypressed(key)
--jump
if key == " " then
if jump == true then
jump = false
player.y = player.y - 190
else
jump = true
end
end
end
Code: Select all
jump = true
function love.keypressed(key)
--jump
if key == " " then
if jump == true then
jump = false
player.y = player.y - 190
else
jump = true
end
end
end
Code: Select all
function love.load()
player = {}
player.x = 10
player.y = 300 -- or whatever fits your game
player.dy = 0
end
function love.update(dt)
player.y = player.y + player.dy*dt
player.dy = math.max(0, player.dy - 100*dt)
end
function love.keypressed(k)
if k=="up" then
player.dy = -100
end
Code: Select all
require "external"
block = {}
player = {}
local collision = false
jump = true
moveleft = true
moveright = true
--load the images
background_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})
table.insert(block, {x = 150, y = 200})
for i=1,3 do
table.insert(block, {x = 150+i*50, y = 200})
end
end
function love.draw()
x, y = love.mouse.getPosition()
--draw the background
love.graphics.setColor(255, 130, 130, 255)
love.graphics.draw(background_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
hitboxes:update(dt)
--move left
if moveleft == true then
if love.keyboard.isDown("left") then
player.x = player.x - 190*dt
end
end
--move right
if moveright == true then
if love.keyboard.isDown("right") then
player.x = player.x + 190*dt
end
end
end
function love.keypressed(key)
--jump
if key == " " then
if jump == true then
jump = false
player.y = player.y - 190
else
jump = true
end
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
Code: Select all
hitboxes = {}
function hitboxes:update(dt)
--Gravity!
local collision = false --Right there
for i= 1, #block do
if collision then break end
collision = CheckCollision(player.x, player.y, 50, 50, block[i].x, block[i].y, 50, 50)
end
if collision == false then
player.y = player.y + 190*dt
end
end
Code: Select all
require "external"
block = {}
player = {}
local collision = false
jump = true
moveleft = true
moveright = true
--load the images
background_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
player.xspeed = 0
player.yspeed = 0
table.insert(block, {x = 0, y = 50})
table.insert(block, {x = 50, y = 50})
table.insert(block, {x = 150, y = 200})
for i=1,3 do
table.insert(block, {x = 150+i*50, y = 200})
end
end
function love.draw()
x, y = love.mouse.getPosition()
--draw the background
love.graphics.setColor(255, 130, 130, 255)
love.graphics.draw(background_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
hitboxes:update(dt)
--move left
if moveleft == true then
if love.keyboard.isDown("left") then
player.xspeed = -190
else
player.xspeed = 0
end
end
--move right
if moveright == true then
if love.keyboard.isDown("right") then
player.xspeed =190
else
player.xspeed = 0
end
end
player.x = player.x + player.xspeed * dt
player.y = player.y + player.yspeed * dt
end
function love.keypressed(key)
--jump
if key == " " then
if jump == true then
jump = false
player.yspeed = player.yspeed - 380
else
jump = true
end
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
Code: Select all
hitboxes = {}
function hitboxes:update(dt)
--Gravity!
local collision = false --Right there
for i= 1, #block do
if collision then break end
collision = CheckCollision(player.x, player.y, 50, 50, block[i].x, block[i].y, 50, 50)
end
if collision == false then
player.y = player.y + 190*dt
end
end
Users browsing this forum: No registered users and 6 guests