this is the line:
inputTimer.r = inputTimer.r + dt
and the entire code:
Code: Select all
debug = true
function love.load()
ground = {}
ground.y = 550
ground.w = love.graphics.getWidth()
ground.h = love.graphics.getHeight() - ground.y
player = {}
player.y = 500
player.x = 100
player.w = 50
player.h = 50
player.b = player.y + player.h
player.r = player.x + player.w
player.y_vel_base = -(ground.y + player.h)
player.y_vel = player.y_vel_base
player.x_vel = 200
player.x_vel2 = player.x_vel*3
player.state = {
jumping = false,
facing = "right",
running = false,
}
gravity = 1000
releasekey = "none"
inputTimer = {
l = 0,
r = 0,
}
combo = {
l = "false",
r = "false",
}
end
function love.update(dt)
if love.keyboard.isDown("up") and player.state == "idle" then
player.state.jumping = true
end
if player.state.jumping then
player.y = player.y + player.y_vel * dt
player.y_vel = player.y_vel + gravity * dt
if player.y + player.h > ground.y then
player.y = ground.y - player.h
player.y_vel = player.y_vel_base
player.state = "idle"
end
end
if releasekey == "right" then
inputTimer.r = inputTimer.r + dt
if inputTimer.r < 0.3 then
combo.r = "true"
else
inputTimer = 0
releasekey = "none"
combo.r = "false"
end
end
if love.keyboard.isDown("right") then
player.x = player.x + player.x_vel * dt
if combo.r == "true" and love.keyboard.isDown("right") then
player.x = player.x + player.x_vel2 * dt
else
inputTimer = 0
end
end
if releasekey == "left" then
inputTimer.l = inputTimer.l + dt
if inputTimer.l < 0.3 then
combo.l = "true"
else
inputTimer.l = 0
releasekey = "none"
combo.l = "false"
end
end
if love.keyboard.isDown("left") then
player.x = player.x - player.x_vel * dt
if combo.l == "true" and love.keyboard.isDown("left") then
player.x = player.x - player.x_vel2 * dt
else
inputTimer.l = 0
end
end
end
function love.draw()
love.graphics.rectangle("fill",player.x,player.y,player.w,player.h)
love.graphics.rectangle("fill",0,ground.y,ground.w,ground.h)
if debug then
--love.graphics.print("player state: " ..player.state,50,50,0,1,1)
love.graphics.print("y: " ..player.y,200,50,0,1,1)
love.graphics.print("x: " ..player.x,200,65,0,1,1)
love.graphics.print("last key release: " ..releasekey,50,65,0,1,1)
love.graphics.print("combo (r): " ..combo.r, 50,80,0,1,1)
love.graphics.print("combo (l): " ..combo.l, 50,90,0,1,1)
end
end
function love.keypressed(key)
end
function love.keyreleased(key)
if key == "tab" then
debug = not debug
end
if key == "right" then
releasekey = "right"
end
if key == "left" then
releasekey = "left"
end
end