Attempt to make it so that keys track their own key down and key up event so you can hold down one key and do something with another at the same time.

This commit is contained in:
Storm dragon 2015-12-30 13:34:23 -05:00
parent 3a1f834777
commit 21466a5e2d

View File

@ -113,15 +113,15 @@ while running do
for e in SDL.pollEvent() do for e in SDL.pollEvent() do
if e.type == SDL.event.KeyUp then --chrys just recognice the keyup and free the loop if e.type == SDL.event.KeyUp then --chrys just recognice the keyup and free the loop
keyName = SDL.getKeyName(e.keysym.sym) keyName = SDL.getKeyName(e.keysym.sym)
holdKey.keyName = false holdKey[keyName] = false
direction = "" direction = ""
-- speak(playerPosition) -- speak(playerPosition)
end end
if e.type == SDL.event.Quit then if e.type == SDL.event.Quit then
running = false running = false
elseif e.type == SDL.event.KeyDown and not holdKey.keyName then -- chrysif not already down ( see below) elseif e.type == SDL.event.KeyDown and not holdKey[keyName] then -- chrysif not already down ( see below)
keyName = SDL.getKeyName(e.keysym.sym) keyName = SDL.getKeyName(e.keysym.sym)
holdKey.keyName = true --chrys mark the remember the keydown holdKey[keyName] = true --chrys mark the remember the keydown
if keyName == "Q" then if keyName == "Q" then
running = exit_game(SDL, mixer) running = exit_game(SDL, mixer)
elseif keyName == "Left Shift" or keyName == "Right Shift" then elseif keyName == "Left Shift" or keyName == "Right Shift" then