I am new to this forum.
I am also a love2d/game programming newb, so I want to ask the community for a little help.
I decided to try my hand at a basic platforming game, so I wrote some the following code:
player.lua
Code: Select all
function module.create()
return {x=750,y=590,velocity=200,velocity2=300,isjumping=false}
end
function module.moveleft(x,dt,movespeed)
return x - 600*dt
end
function module.moveright(x,dt,movespeed)
return x + 600*dt
end
function module.jump(y,velocity,velocity2,isjumping,dt)
if isjumping == true then
y = y - velocity
velocity = velocity - dt*600
end
if velocity == 0 and y < 590 then
y = y + velocity2
isjumping = false
end
if y >= 590 then
velocity = 20
isjumping = false
end
end
function module.draw(x,y)
love.graphics.rectangle("fill",x,y,10,10)
end
return module
main.lua
Code: Select all
local playerfunc=require 'player'
function love.load()
player={x=750,y=590,velocity=200,velocity2=300,isjumping=false}
end
function love.update(dt)
--movement left and right
if love.keyboard.isDown("left") then
player.x = playerfunc.moveleft(player.x,dt,speed)
end
if love.keyboard.isDown("right") then
player.x = playerfunc.moveright(player.x,dt,speed)
end
playerfunc.jump(player.y,player.velocity,player.velocity2,player.isjumping,dt)
function love.keypressed(key)
--if space was pressed start jumping
if key == " " then
player.isjumping = true
print("it's true")
print(isjumping)
end
end
function love.draw()
--our hero
--love.graphics.rectangle("fill",player.x,player.y,10,10)
playerfunc.draw(player.x,player.y)
end
thanks if you help
thanks if you don't help
thanks if you insult me saying "noob"
i'm soory for swamping you guys in code