Permalink
Browse files

Moved Rubygame.get_key_state from main.rb to events.rb.

Also cleaned up credits/copyright info.
  • Loading branch information...
1 parent 79866cf commit 6c011527bf2ced2c92940b74d50723ed4970a0df @jacius jacius committed Feb 19, 2011
Showing with 26 additions and 19 deletions.
  1. +1 −1 CREDITS.rdoc
  2. +22 −0 lib/rubygame/events.rb
  3. +3 −18 lib/rubygame/main.rb
View
@@ -68,5 +68,5 @@
- <b>Tyler Church</b>
Email:: tylertrain at yahoo.com
- Contribution:: Added a get_key_state method
+ Contribution:: Patch to add Rubygame.get_key_state
Date:: 2010-09-06
View
@@ -17,6 +17,11 @@
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+#
+# Changes:
+# * Tyler Church, 2010-09-06: Added Rubygame.get_key_state
+#
#++
@@ -83,6 +88,23 @@ def self.disable_key_repeat
end
+ # Returns a hash of all the keys, if a key's value in the hash
+ # is true, the key is currently pressed down, otherwise it's
+ # value is false.
+ #
+ # Usage: Rubygame.get_key_state[:a]
+ #
+ def self.get_key_state
+ hash = {}
+ key_state = SDL.GetKeyState
+ key_state.length.times do |i|
+ state = (key_state[i] != 0)
+ hash[Rubygame::Events._convert_key_symbol(i)] = state
+ end
+ hash.delete :unknown_key
+ return hash
+ end
+
# The Events module contains classes representing various
# hardware events (e.g. keyboard presses, mouse clicks)
View
@@ -1,6 +1,6 @@
#--
# Rubygame -- Ruby code and bindings to SDL to facilitate game creation
-# Copyright (C) 2004-2010 John Croisant, Tyler Church
+# Copyright (C) 2004-2010 John Croisant
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
@@ -50,23 +50,8 @@ def self.init
def self.quit
SDL.Quit
end
-
- # Returns a hash of all the keys, if a key's value in the hash
- # is true, the key is currently pressed down, otherwise it's
- # value is false.
- #
- # Usage: Rubygame.get_key_state[:a]
- #
- def self.get_key_state
- hash = {}
- key_state = SDL.GetKeyState
- key_state.length.times do |i|
- state = (key_state[i] != 0)
- hash[Rubygame::Events._convert_key_symbol(i)] = state
- end
- hash.delete :unknown_key
- return hash
- end
+
+
# Indicates that an SDL function failed.
class SDLError < RuntimeError

0 comments on commit 6c01152

Please sign in to comment.