#============================================================================== # ** Input #------------------------------------------------------------------------------ # Added methods for correctly detecting directional input #============================================================================== module Input #-------------------------------------------------------------------------- # * Class Variables #-------------------------------------------------------------------------- @@_direction = nil @@_direction_v = nil @@_direction_h = nil @@_last_up = nil @@_last_down = nil @@_last_left = nil @@_last_right = nil #-------------------------------------------------------------------------- # * Check if direction is the latest #-------------------------------------------------------------------------- def self.direction?(direction) # Set direction to up if pressed (and wasn't before) if self.press?(UP) and !@@_last_up @@_direction = UP end @@_last_up = self.press?(UP) if self.press?(DOWN) and !@@_last_down @@_direction = DOWN end @@_last_down = self.press?(DOWN) if self.press?(LEFT) and !@@_last_left @@_direction = LEFT end @@_last_left = self.press?(LEFT) if self.press?(RIGHT) and !@@_last_right @@_direction = RIGHT end @@_last_right = self.press?(RIGHT) # True if direction is the latest and pressed return (direction == @@_direction and self.press?(direction)) end #-------------------------------------------------------------------------- # * Check if direction is the latest (U/D only) #-------------------------------------------------------------------------- def self.direction_v?(direction) if self.press?(UP) and !@@_last_up @@_direction_v = UP end @@_last_up = self.press?(UP) if self.press?(DOWN) and !@@_last_down @@_direction_v = DOWN end @@_last_down = self.press?(DOWN) return (direction == @@_direction_v and self.press?(direction)) end #-------------------------------------------------------------------------- # * Check if direction is the latest (L/R only) #-------------------------------------------------------------------------- def self.direction_h?(direction) if self.press?(LEFT) and !@@_last_left @@_direction_h = LEFT end @@_last_left = self.press?(LEFT) if self.press?(RIGHT) and !@@_last_right @@_direction_h = RIGHT end @@_last_right = self.press?(RIGHT) return (direction == @@_direction_h and self.press?(direction)) end end