Skip to content

Commit

Permalink
multiple keydownevents when key is pressed fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
apoh committed Dec 31, 2011
1 parent 9699c6f commit 80c9b47
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions sokoban/main.lua
Expand Up @@ -7,6 +7,10 @@ require "framework"
env = {
}

-- this value is used for blocing new keyentrys
block_keyevents = false



-- helpervalues
-- local __maxbound = 1.5
Expand Down Expand Up @@ -34,7 +38,8 @@ function Player:update()
local old_pos = {x = self.pos.x, y = self.pos.y}
local dir = {x = 0, y = 0}
for cursor_dir, oc in pairs({left="-x", right="+x", up="-y", down="+y" }) do
if wall.input[1][cursor_dir] then
if wall.input[1][cursor_dir] and not block_keyevents then
block_keyevents = true
local o, c = oc:sub(1,1), oc:sub(2)
if c == 'x' then
if o == '-' then
Expand Down Expand Up @@ -213,10 +218,14 @@ function love.keypressed(key)
end
end

function love.keyreleased(key)
block_keyevents = false
end

function love.update(dt)
-- constant 30 FPS
local t = love.timer.getTime() * 1000
time = time + 1000 / 13
time = time + 1000 / 30
love.timer.sleep(time - t)

update()
Expand Down

0 comments on commit 80c9b47

Please sign in to comment.