Monday, July 29, 2013

flea circus

Copperbox revision 2991.

Slaps forehead, Homer Simpson style...

The problem with the flea player not picking up simultaneous jump and left / right arrow key presses was entirely self-inflicted and not due to a slow computer.

The old code merged all key press detection into one multiway if statement:
if the.keys:pressed("left") then
    self:walkLeft()
elseif the.keys:pressed("right") then
    self:walkRight()
elseif the.keys:pressed(" ") then
    playSound('jump.ogg')
    self:jumpAction()
end
The solution is to group exclusive key presses together (left | right) but use separate if statements for independent actions (jump):
if the.keys:pressed("left") then
    self:walkLeft()
elseif the.keys:pressed("right") then
    self:walkRight()
end

-- We can detect more then one key press per frame if we
-- don't nest them within the same if-elseif ... statement
if the.keys:pressed(" ") then
    playSound('jump.ogg')
    self:jumpAction()
end
Annoyingly I was aware of this idiom as the player control has had it before, but it got removed in a frustrated bout of hacking. This obviates the need for yesterdays Pachinko inspired player control.

Blog Archive

About Me

My photo
Disambiguating biog as there are a few Stephen Tetley's in the world. I'm neither a cage fighter or yachtsman. I studied Fine Art in the nineties (foundation Bradford 1992, degree Cheltenham 1992 - 95) then Computing part-time at Leeds Met graduating in 2003. I'm the Stephen Tetley on Haskell Cafe and Stackoverflow.