rubygame 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. data/CREDITS +50 -0
  2. data/Changelog +162 -0
  3. data/LICENSE +504 -0
  4. data/README +122 -0
  5. data/Rakefile +380 -0
  6. data/TODO +45 -0
  7. data/doc/extended_readme.rdoc +49 -0
  8. data/doc/getting_started.rdoc +47 -0
  9. data/doc/macosx_install.rdoc +74 -0
  10. data/doc/windows_install.rdoc +124 -0
  11. data/ext/rubygame/MANIFEST +25 -0
  12. data/ext/rubygame/rubygame_event.c +644 -0
  13. data/ext/rubygame/rubygame_event.h +48 -0
  14. data/ext/rubygame/rubygame_gfx.c +951 -0
  15. data/ext/rubygame/rubygame_gfx.h +102 -0
  16. data/ext/rubygame/rubygame_gl.c +154 -0
  17. data/ext/rubygame/rubygame_gl.h +32 -0
  18. data/ext/rubygame/rubygame_image.c +108 -0
  19. data/ext/rubygame/rubygame_image.h +41 -0
  20. data/ext/rubygame/rubygame_joystick.c +247 -0
  21. data/ext/rubygame/rubygame_joystick.h +41 -0
  22. data/ext/rubygame/rubygame_main.c +155 -0
  23. data/ext/rubygame/rubygame_main.h +33 -0
  24. data/ext/rubygame/rubygame_mixer.c +764 -0
  25. data/ext/rubygame/rubygame_mixer.h +62 -0
  26. data/ext/rubygame/rubygame_screen.c +420 -0
  27. data/ext/rubygame/rubygame_screen.h +41 -0
  28. data/ext/rubygame/rubygame_shared.c +152 -0
  29. data/ext/rubygame/rubygame_shared.h +54 -0
  30. data/ext/rubygame/rubygame_surface.c +1107 -0
  31. data/ext/rubygame/rubygame_surface.h +62 -0
  32. data/ext/rubygame/rubygame_time.c +183 -0
  33. data/ext/rubygame/rubygame_time.h +32 -0
  34. data/ext/rubygame/rubygame_ttf.c +600 -0
  35. data/ext/rubygame/rubygame_ttf.h +69 -0
  36. data/lib/rubygame.rb +40 -0
  37. data/lib/rubygame/MANIFEST +12 -0
  38. data/lib/rubygame/clock.rb +128 -0
  39. data/lib/rubygame/constants.rb +238 -0
  40. data/lib/rubygame/event.rb +313 -0
  41. data/lib/rubygame/ftor.rb +370 -0
  42. data/lib/rubygame/hotspot.rb +265 -0
  43. data/lib/rubygame/keyconstants.rb +237 -0
  44. data/lib/rubygame/mediabag.rb +94 -0
  45. data/lib/rubygame/queue.rb +288 -0
  46. data/lib/rubygame/rect.rb +614 -0
  47. data/lib/rubygame/sfont.rb +223 -0
  48. data/lib/rubygame/sprite.rb +477 -0
  49. data/samples/FreeSans.ttf +0 -0
  50. data/samples/GPL.txt +340 -0
  51. data/samples/README +40 -0
  52. data/samples/chimp.bmp +0 -0
  53. data/samples/chimp.rb +313 -0
  54. data/samples/demo_gl.rb +151 -0
  55. data/samples/demo_gl_tex.rb +197 -0
  56. data/samples/demo_music.rb +75 -0
  57. data/samples/demo_rubygame.rb +279 -0
  58. data/samples/demo_sfont.rb +52 -0
  59. data/samples/demo_ttf.rb +193 -0
  60. data/samples/demo_utf8.rb +53 -0
  61. data/samples/fist.bmp +0 -0
  62. data/samples/load_and_blit.rb +22 -0
  63. data/samples/panda.png +0 -0
  64. data/samples/punch.wav +0 -0
  65. data/samples/ruby.png +0 -0
  66. data/samples/term16.png +0 -0
  67. data/samples/whiff.wav +0 -0
  68. metadata +123 -0
@@ -0,0 +1,69 @@
1
+ /*
2
+ * Rubygame -- Ruby code and bindings to SDL to facilitate game creation
3
+ * Copyright (C) 2004-2007 John Croisant
4
+ *
5
+ * This library is free software; you can redistribute it and/or
6
+ * modify it under the terms of the GNU Lesser General Public
7
+ * License as published by the Free Software Foundation; either
8
+ * version 2.1 of the License, or (at your option) any later version.
9
+ *
10
+ * This library is distributed in the hope that it will be useful,
11
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
+ * Lesser General Public License for more details.
14
+ *
15
+ * You should have received a copy of the GNU Lesser General Public
16
+ * License along with this library; if not, write to the Free Software
17
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
+ *
19
+ */
20
+
21
+ #ifndef _RUBYGAME_TTF_H
22
+ #define _RUBYGAME_TTF_H
23
+
24
+ #include "SDL_ttf.h"
25
+
26
+ #ifndef SDL_TTF_MAJOR_VERSION
27
+ #define SDL_TTF_MAJOR_VERSION 0
28
+ #endif
29
+
30
+ #ifndef SDL_TTF_MINOR_VERSION
31
+ #define SDL_TTF_MINOR_VERSION 0
32
+ #endif
33
+
34
+ #ifndef SDL_TTF_PATCHLEVEL
35
+ #define SDL_TTF_PATCHLEVEL 0
36
+ #endif
37
+
38
+ extern void Init_rubygame_ttf();
39
+
40
+ extern VALUE cTTF;
41
+
42
+ extern VALUE rbgm_ttf_setup(VALUE);
43
+ extern VALUE rbgm_ttf_quit(VALUE);
44
+ extern VALUE rbgm_ttf_new(VALUE, VALUE, VALUE);
45
+ extern VALUE rbgm_ttf_initialize(int, VALUE*, VALUE);
46
+
47
+ extern VALUE rbgm_ttf_getbold(VALUE);
48
+ extern VALUE rbgm_ttf_setbold(VALUE, VALUE);
49
+
50
+ extern VALUE rbgm_ttf_getitalic(VALUE);
51
+ extern VALUE rbgm_ttf_setitalic(VALUE, VALUE);
52
+
53
+ extern VALUE rbgm_ttf_getunderline(VALUE);
54
+ extern VALUE rbgm_ttf_setunderline(VALUE, VALUE);
55
+
56
+ extern VALUE rbgm_ttf_height(VALUE);
57
+ extern VALUE rbgm_ttf_ascent(VALUE);
58
+ extern VALUE rbgm_ttf_descent(VALUE);
59
+ extern VALUE rbgm_ttf_lineskip(VALUE);
60
+
61
+ extern VALUE rbgm_ttf_sizetext(VALUE, VALUE);
62
+ extern VALUE rbgm_ttf_size_utf8(VALUE, VALUE);
63
+ extern VALUE rbgm_ttf_size_unicode(VALUE, VALUE);
64
+
65
+ extern VALUE rbgm_ttf_render(int, VALUE*, VALUE);
66
+ extern VALUE rbgm_ttf_render_utf8(int , VALUE*, VALUE);
67
+ extern VALUE rbgm_ttf_render_unicode(int , VALUE*, VALUE);
68
+
69
+ #endif
data/lib/rubygame.rb ADDED
@@ -0,0 +1,40 @@
1
+ #--
2
+ # Rubygame -- Ruby code and bindings to SDL to facilitate game creation
3
+ # Copyright (C) 2004-2007 John Croisant
4
+ #
5
+ # This library is free software; you can redistribute it and/or
6
+ # modify it under the terms of the GNU Lesser General Public
7
+ # License as published by the Free Software Foundation; either
8
+ # version 2.1 of the License, or (at your option) any later version.
9
+ #
10
+ # This library is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
+ # Lesser General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Lesser General Public
16
+ # License along with this library; if not, write to the Free Software
17
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
+ #++
19
+
20
+ # This is the file that should be imported, it in turn imports rubygame.so
21
+ # (which has all of the C code for rubygame) and all the other rubygame modules
22
+
23
+ require "rbconfig"
24
+
25
+ require "rubygame_core"
26
+
27
+ %W{ rubygame_gfx rubygame_image rubygame_ttf rubygame_mixer }.each do |mod|
28
+ begin
29
+ require mod
30
+ rescue LoadError
31
+ warn( "Warning: Unable to require optional module: #{mod}.") if $VERBOSE
32
+ end
33
+ end
34
+
35
+ require "rubygame/constants"
36
+ require "rubygame/event"
37
+ require "rubygame/queue"
38
+ require "rubygame/rect"
39
+ require "rubygame/sprite"
40
+ require "rubygame/clock"
@@ -0,0 +1,12 @@
1
+ clock.rb
2
+ constants.rb
3
+ event.rb
4
+ ftor.rb
5
+ hotspot.rb
6
+ keyconstants.rb
7
+ MANIFEST
8
+ mediabag.rb
9
+ queue.rb
10
+ rect.rb
11
+ sfont.rb
12
+ sprite.rb
@@ -0,0 +1,128 @@
1
+ #--
2
+ # Rubygame -- Ruby code and bindings to SDL to facilitate game creation
3
+ # Copyright (C) 2004-2007 John Croisant
4
+ #
5
+ # This library is free software; you can redistribute it and/or
6
+ # modify it under the terms of the GNU Lesser General Public
7
+ # License as published by the Free Software Foundation; either
8
+ # version 2.1 of the License, or (at your option) any later version.
9
+ #
10
+ # This library is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
+ # Lesser General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Lesser General Public
16
+ # License along with this library; if not, write to the Free Software
17
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
+ #++
19
+
20
+ module Rubygame
21
+ # Clock provides class methods for tracking running time and delaying
22
+ # execution of the program for specified time periods. This is used to
23
+ # provide a consistent framerate, prevent the program from using
24
+ # all the processor time, etc.
25
+ #
26
+ # Clock also provides instance methods to make it convenient to
27
+ # monitor and limit application framerate. See #tick.
28
+ class Clock
29
+ # The runtime when the Clock was initialized.
30
+ attr_reader :start
31
+ # The number of times #tick has been called.
32
+ attr_reader :ticks
33
+
34
+ # Create a new Clock instance.
35
+ def initialize()
36
+ @start = Clock.runtime()
37
+ @last_tick = @start
38
+ @ticks = 0
39
+ @target_frametime = nil
40
+ yield self if block_given?
41
+ end
42
+
43
+ # The target frametime (milliseconds/frame). See #tick
44
+ attr_accessor :target_frametime
45
+
46
+ # Returns the current target framerate (frames/second).
47
+ # This is an alternate way to access @target_frametime.
48
+ # Same as: 1000.0 / #target_frametime
49
+ def target_framerate
50
+ if @target_frametime
51
+ 1000.0 / @target_frametime
52
+ else
53
+ nil
54
+ end
55
+ rescue ZeroDivisionError
56
+ return nil
57
+ end
58
+
59
+ # Sets the target number of frames per second to +framerate+.
60
+ # This is an alternate way to access @target_frametime.
61
+ # Same as: #target_frametime = 1000.0 / framerate
62
+ def target_framerate=( framerate )
63
+ if framerate
64
+ @target_frametime = 1000.0 / framerate
65
+ else
66
+ @target_frametime = nil
67
+ end
68
+ rescue ZeroDivisionError
69
+ @target_frametime = nil
70
+ end
71
+
72
+ # call-seq: lifetime() -> Numeric
73
+ #
74
+ # Returns time in milliseconds since this Clock instance was created.
75
+ def lifetime
76
+ Clock.runtime() - @start
77
+ end
78
+
79
+ # call-seq: framerate() -> Numeric
80
+ #
81
+ # Return the actual framerate (frames per second) recorded by the Clock.
82
+ # See #tick.
83
+ #
84
+ # TODO: sample only a few seconds in the past, instead of the
85
+ # entire lifetime of the Clock.
86
+ def framerate
87
+ # below is same as: return @ticks / (lifetime / 1000.0)
88
+ return 1000.0 * @ticks / lifetime()
89
+ rescue ZeroDivisionError
90
+ return 0
91
+ end
92
+
93
+ # Returns the number of milliseconds since you last called this method.
94
+ #
95
+ # You must call this method once per frame (i.e. per iteration of
96
+ # your main loop) if you want to use the framerate monitoring and/or
97
+ # framerate limiting features.
98
+ #
99
+ # Framerate monitoring allows you to check the framerate (frames per
100
+ # second) with the #framerate method.
101
+ #
102
+ # Framerate limiting allows you to prevent the application from running
103
+ # too fast (and using 100% of processor time) by pausing the program
104
+ # very briefly each frame. The pause duration is calculated each frame
105
+ # to maintain a constant framerate.
106
+ #
107
+ # Framerate limiting is only enabled if you have set the
108
+ # #target_framerate= or #target_frametime=.
109
+ # If you have done that, this method will automatically perform the
110
+ # delay each time you call it.
111
+ #
112
+ # (Please note that no effort is made to correct a framerate
113
+ # which is *slower* than the target framerate. Clock can't
114
+ # make your code run faster, only slow it down if it is
115
+ # running too fast.)
116
+ def tick()
117
+ passed = Clock.runtime() - @last_tick # how long since the last tick?
118
+ if @target_frametime
119
+ return Clock.delay(@target_frametime - passed) + passed
120
+ end
121
+ return passed
122
+ ensure
123
+ @last_tick = Clock.runtime()
124
+ @ticks += 1
125
+ end
126
+
127
+ end # class Clock
128
+ end #module Rubygame
@@ -0,0 +1,238 @@
1
+ #--
2
+ # Rubygame -- Ruby code and bindings to SDL to facilitate game creation
3
+ # Copyright (C) 2004-2007 John Croisant
4
+ #
5
+ # This library is free software; you can redistribute it and/or
6
+ # modify it under the terms of the GNU Lesser General Public
7
+ # License as published by the Free Software Foundation; either
8
+ # version 2.1 of the License, or (at your option) any later version.
9
+ #
10
+ # This library is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
+ # Lesser General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Lesser General Public
16
+ # License along with this library; if not, write to the Free Software
17
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
+ #++
19
+
20
+ module Rubygame
21
+
22
+ module Mouse
23
+ # Hash to translate mouse button sym to string
24
+ MOUSE2STR = {
25
+ MOUSE_LEFT => "left",
26
+ MOUSE_MIDDLE => "middle",
27
+ MOUSE_RIGHT => "right"
28
+ }
29
+ # And to translate the other way...
30
+ STR2MOUSE = MOUSE2STR.invert()
31
+ # And allow numbers too (1 = left, so on)...
32
+ STR2MOUSE[1] = MOUSE_LEFT
33
+ STR2MOUSE[2] = MOUSE_MIDDLE
34
+ STR2MOUSE[3] = MOUSE_RIGHT
35
+ end # module Mouse
36
+
37
+ module Key
38
+ # All the keys which have ASCII print values
39
+ # It is 87 lines from here to the closing }, if you want to skip it...
40
+ KEY2ASCII = {
41
+ K_BACKSPACE => "\b",
42
+ K_TAB => "\t",
43
+ K_RETURN => "\n", #SDL docs: "\r". Win vs *nix? What about Mac?
44
+ K_ESCAPE => "^[",
45
+ K_SPACE => " ",
46
+ K_EXCLAIM => "!",
47
+ K_QUOTEDBL => "\"",
48
+ K_HASH => "#",
49
+ K_DOLLAR => "$",
50
+ K_AMPERSAND => "&",
51
+ K_QUOTE => "\'",
52
+ K_LEFTPAREN => "(",
53
+ K_RIGHTPAREN => ")",
54
+ K_ASTERISK => "*",
55
+ K_PLUS => "+",
56
+ K_COMMA => ",",
57
+ K_MINUS => "-",
58
+ K_PERIOD => ".",
59
+ K_SLASH => "/",
60
+ K_0 => "0",
61
+ K_1 => "1",
62
+ K_2 => "2",
63
+ K_3 => "3",
64
+ K_4 => "4",
65
+ K_5 => "5",
66
+ K_6 => "6",
67
+ K_7 => "7",
68
+ K_8 => "8",
69
+ K_9 => "9",
70
+ K_COLON => ":",
71
+ K_SEMICOLON => ";",
72
+ K_LESS => "<",
73
+ K_EQUALS => "=",
74
+ K_GREATER => ">",
75
+ K_QUESTION => "?",
76
+ K_AT => "@",
77
+ K_LEFTBRACKET => "[",
78
+ K_BACKSLASH => "\\",
79
+ K_RIGHTBRACKET => "]",
80
+ K_CARET => "^",
81
+ K_UNDERSCORE => "_",
82
+ K_BACKQUOTE => "`",
83
+ K_A => "a",
84
+ K_B => "b",
85
+ K_C => "c",
86
+ K_D => "d",
87
+ K_E => "e",
88
+ K_F => "f",
89
+ K_G => "g",
90
+ K_H => "h",
91
+ K_I => "i",
92
+ K_J => "j",
93
+ K_K => "k",
94
+ K_L => "l",
95
+ K_M => "m",
96
+ K_N => "n",
97
+ K_O => "o",
98
+ K_P => "p",
99
+ K_Q => "q",
100
+ K_R => "r",
101
+ K_S => "s",
102
+ K_T => "t",
103
+ K_U => "u",
104
+ K_V => "v",
105
+ K_W => "w",
106
+ K_X => "x",
107
+ K_Y => "y",
108
+ K_Z => "z",
109
+ K_KP0 => "0",
110
+ K_KP1 => "1",
111
+ K_KP2 => "2",
112
+ K_KP3 => "3",
113
+ K_KP4 => "4",
114
+ K_KP5 => "5",
115
+ K_KP6 => "6",
116
+ K_KP7 => "7",
117
+ K_KP8 => "8",
118
+ K_KP9 => "9",
119
+ K_KP_PERIOD => ".",
120
+ K_KP_DIVIDE => "/",
121
+ K_KP_MULTIPLY => "*",
122
+ K_KP_MINUS => "-",
123
+ K_KP_PLUS => "+",
124
+ K_KP_ENTER => "\n", #again, SDL docs say "\r"
125
+ K_KP_EQUALS => "=",
126
+ }
127
+
128
+ # And to translate the other way...
129
+ ASCII2KEY = KEY2ASCII.invert()
130
+ # accept uppercase letters too, return same as lowercase version:
131
+ ("a".."z").each{ |letter| ASCII2KEY[letter.upcase] = ASCII2KEY[letter] }
132
+
133
+ # All the keys that are affected by the Shift key, in lower case
134
+ # 49 lines from here to the end of the hash
135
+ KEY2LOWER = {
136
+ K_QUOTE => "\'",
137
+ K_COMMA => ",",
138
+ K_MINUS => "-",
139
+ K_PERIOD => ".",
140
+ K_SLASH => "/",
141
+ K_0 => "0",
142
+ K_1 => "1",
143
+ K_2 => "2",
144
+ K_3 => "3",
145
+ K_4 => "4",
146
+ K_5 => "5",
147
+ K_6 => "6",
148
+ K_7 => "7",
149
+ K_8 => "8",
150
+ K_9 => "9",
151
+ K_SEMICOLON => ";",
152
+ K_EQUALS => "=",
153
+ K_LEFTBRACKET => "[",
154
+ K_BACKSLASH => "\\",
155
+ K_RIGHTBRACKET => "]",
156
+ K_BACKQUOTE => "`",
157
+ K_A => "a",
158
+ K_B => "b",
159
+ K_C => "c",
160
+ K_D => "d",
161
+ K_E => "e",
162
+ K_F => "f",
163
+ K_G => "g",
164
+ K_H => "h",
165
+ K_I => "i",
166
+ K_J => "j",
167
+ K_K => "k",
168
+ K_L => "l",
169
+ K_M => "m",
170
+ K_N => "n",
171
+ K_O => "o",
172
+ K_P => "p",
173
+ K_Q => "q",
174
+ K_R => "r",
175
+ K_S => "s",
176
+ K_T => "t",
177
+ K_U => "u",
178
+ K_V => "v",
179
+ K_W => "w",
180
+ K_X => "x",
181
+ K_Y => "y",
182
+ K_Z => "z",
183
+ }
184
+
185
+ # All the keys that are affected by the Shift key, in UPPER case
186
+ # 49 lines from here to the end of the hash
187
+ KEY2UPPER = {
188
+ K_QUOTE => "\"",
189
+ K_COMMA => "<",
190
+ K_MINUS => "_",
191
+ K_PERIOD => ">",
192
+ K_SLASH => "?",
193
+ K_0 => ")",
194
+ K_1 => "!",
195
+ K_2 => "@",
196
+ K_3 => "#",
197
+ K_4 => "$",
198
+ K_5 => "%",
199
+ K_6 => "^",
200
+ K_7 => "&",
201
+ K_8 => "*",
202
+ K_9 => "(",
203
+ K_SEMICOLON => ":",
204
+ K_EQUALS => "+",
205
+ K_LEFTBRACKET => "{",
206
+ K_BACKSLASH => "|",
207
+ K_RIGHTBRACKET => "}",
208
+ K_BACKQUOTE => "~",
209
+ K_A => "A",
210
+ K_B => "B",
211
+ K_C => "C",
212
+ K_D => "D",
213
+ K_E => "E",
214
+ K_F => "F",
215
+ K_G => "G",
216
+ K_H => "H",
217
+ K_I => "I",
218
+ K_J => "J",
219
+ K_K => "K",
220
+ K_L => "L",
221
+ K_M => "M",
222
+ K_N => "N",
223
+ K_O => "O",
224
+ K_P => "P",
225
+ K_Q => "Q",
226
+ K_R => "R",
227
+ K_S => "S",
228
+ K_T => "T",
229
+ K_U => "U",
230
+ K_V => "V",
231
+ K_W => "W",
232
+ K_X => "X",
233
+ K_Y => "Y",
234
+ K_Z => "Z",
235
+ }
236
+ end #module Key
237
+
238
+ end # module Rubygame