I received a report on the
Full Input Keyboard script written by cidiomar which allows you to use the entire keyboard for your game instead of the default buttons.
The problem was related to direction keys.
Here are some examples of the problem:
Case 1
1. Create a new project
2. Move down
3. While holding the down button, press left or right
The expected behavior is you would move down, but when you press left or right, you would move left or right immediately in response to the keys
Now, install the full input keyboard script, and repeat the same experiment.
However, this time, you'll notice you can't move left or right WHILE moving down.
BUT, if you were to move left or right WHILE moving up, it does work as expected.
Case 2
Here's another behavior. Starting without any scripts,
1. Move down
2. While moving down, press the up button
The expected behavior is the character will stop.
However, with full input keyboard, this does not work.
Problem
There is a problem with the way dir4 (and consequently, dir8) have been implemented.
def self.dir4
return 2 if self.press?(DOWN)
return 4 if self.press?(LEFT)
return 6 if self.press?(RIGHT)
return 8 if self.press?(UP)
return 0
end
This means that if you're pressing down, the code will always return there.
This means if you were pressing down AND left, the code will still return 2, and therefore the game would say you're only moving down.
Now, if you were pressing UP, you could press left or right, and the code will return left or right as needed because they are checked before checking for the UP key.
So there are two issues here
1. Ace's default input direction updating takes into consideration changed buttons
2. If you were to press opposite directions at the same time, it's as if they don't move
A set of mutually exclusive conditional branches here doesn't seem enough.
How can this be improved to allow for the player to change directions while holding any direction button?
Can the solution be generalized to 8 directions?