-
Notifications
You must be signed in to change notification settings - Fork 0
Controls
code found in 'controls.py'
A neat improvement we made to pygame's already existing key system can be observed in our code. Each button in their library is associated with a specific integer, an index in the keys list.
We used a concept called edge detection
. It's a very useful tool for finding change in digital output. Graphing the output gave by a digital device (like a button) in time, gives us something like this:
Source: sparkfun
Notice the sudden change in inputs? Always analising two consecutive values, we have 4 possible configurations:
-
0 & 0
---> the line stayslow
; -
0 & 1
---> the line 'climbed', meaning the detector isrising
; -
1 & 0
---> the line 'fell' back down, meaning the detector isfalling
; -
1 & 1
---> the line stayshigh
;
Implementing an abstract class in the 'edgeDetectorEx.py' file doing just that, we create a list of detectors for all keyboard and controller buttons, and update their values each loop. This allows us to change values only when the button is pressed, not everytime is pressed like we would do using the raw input.
An inner class created for a more abstract joystick use is the last important implementation we did here. It recognizes the type of joystick connected and sets the buttons accordingly.