rubygame 2.5.3 → 2.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CREDITS +6 -4
- data/NEWS +79 -0
- data/README +55 -72
- data/ROADMAP +20 -13
- data/doc/custom_sdl_load_paths.rdoc +79 -0
- data/doc/getting_started.rdoc +65 -36
- data/doc/keyboard_symbols.rdoc +243 -0
- data/doc/macosx_install.rdoc +49 -35
- data/doc/windows_install.rdoc +36 -108
- data/lib/rubygame.rb +62 -24
- data/lib/rubygame/audio.rb +147 -0
- data/lib/rubygame/clock.rb +164 -1
- data/lib/rubygame/color.rb +40 -7
- data/lib/rubygame/color/models/hsl.rb +1 -1
- data/lib/rubygame/color/models/hsv.rb +1 -1
- data/lib/rubygame/color/models/rgb.rb +1 -1
- data/lib/rubygame/color/palettes/css.rb +1 -3
- data/lib/rubygame/color/palettes/x11.rb +1 -2
- data/lib/rubygame/constants.rb +297 -0
- data/lib/rubygame/deprecated_mixer.rb +555 -0
- data/lib/rubygame/event.rb +122 -6
- data/lib/rubygame/event_handler.rb +3 -1
- data/lib/rubygame/event_hook.rb +6 -2
- data/lib/rubygame/event_triggers.rb +1 -1
- data/lib/rubygame/events.rb +416 -1
- data/lib/rubygame/ftor.rb +1 -7
- data/lib/rubygame/gfx.rb +583 -0
- data/lib/rubygame/gl.rb +107 -0
- data/lib/rubygame/image.rb +140 -0
- data/lib/rubygame/joystick.rb +184 -0
- data/lib/rubygame/main.rb +82 -0
- data/lib/rubygame/mediabag.rb +1 -1
- data/lib/rubygame/mixer.rb +30 -0
- data/lib/rubygame/music.rb +493 -0
- data/lib/rubygame/queue.rb +3 -1
- data/lib/rubygame/rect.rb +9 -9
- data/lib/rubygame/screen.rb +357 -0
- data/lib/rubygame/shared.rb +40 -4
- data/lib/rubygame/sound.rb +428 -0
- data/lib/rubygame/surface.rb +626 -0
- data/lib/rubygame/ttf.rb +311 -0
- data/samples/FreeSans.ttf +0 -0
- data/samples/README +6 -5
- data/samples/demo_draw.rb +1 -1
- data/samples/demo_gl.rb +3 -1
- data/samples/demo_gl_tex.rb +4 -2
- data/samples/demo_rubygame.rb +114 -105
- data/samples/demo_sfont.rb +1 -1
- data/samples/demo_ttf.rb +3 -1
- data/samples/demo_utf8.rb +1 -1
- data/samples/image_viewer.rb +118 -0
- data/samples/load_and_blit.rb +1 -1
- data/samples/rubygame.png +0 -0
- metadata +34 -40
- data/Rakefile +0 -537
- data/doc/extended_readme.rdoc +0 -49
- data/ext/body/rubygame_body.so +0 -0
- data/ext/rubygame/rubygame_clock.c +0 -301
- data/ext/rubygame/rubygame_clock.h +0 -32
- data/ext/rubygame/rubygame_event.c +0 -760
- data/ext/rubygame/rubygame_event.h +0 -48
- data/ext/rubygame/rubygame_event2.c +0 -661
- data/ext/rubygame/rubygame_event2.h +0 -29
- data/ext/rubygame/rubygame_gfx.c +0 -942
- data/ext/rubygame/rubygame_gfx.h +0 -101
- data/ext/rubygame/rubygame_gl.c +0 -154
- data/ext/rubygame/rubygame_gl.h +0 -32
- data/ext/rubygame/rubygame_image.c +0 -252
- data/ext/rubygame/rubygame_image.h +0 -41
- data/ext/rubygame/rubygame_joystick.c +0 -336
- data/ext/rubygame/rubygame_joystick.h +0 -41
- data/ext/rubygame/rubygame_main.c +0 -158
- data/ext/rubygame/rubygame_main.h +0 -36
- data/ext/rubygame/rubygame_mixer.c +0 -1024
- data/ext/rubygame/rubygame_mixer.h +0 -36
- data/ext/rubygame/rubygame_music.c +0 -1017
- data/ext/rubygame/rubygame_music.h +0 -29
- data/ext/rubygame/rubygame_screen.c +0 -572
- data/ext/rubygame/rubygame_screen.h +0 -45
- data/ext/rubygame/rubygame_shared.c +0 -269
- data/ext/rubygame/rubygame_shared.h +0 -69
- data/ext/rubygame/rubygame_sound.c +0 -863
- data/ext/rubygame/rubygame_sound.h +0 -29
- data/ext/rubygame/rubygame_surface.c +0 -1153
- data/ext/rubygame/rubygame_surface.h +0 -62
- data/ext/rubygame/rubygame_ttf.c +0 -599
- data/ext/rubygame/rubygame_ttf.h +0 -69
- data/samples/keys.rb +0 -52
data/lib/rubygame/color.rb
CHANGED
@@ -17,14 +17,17 @@
|
|
17
17
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
18
18
|
#++
|
19
19
|
|
20
|
-
require 'rubygame/color/models/base'
|
21
|
-
require 'rubygame/color/models/rgb'
|
22
|
-
require 'rubygame/color/models/hsv'
|
23
|
-
require 'rubygame/color/models/hsl'
|
24
20
|
|
25
|
-
|
26
|
-
|
27
|
-
require
|
21
|
+
|
22
|
+
%w{ base rgb hsv hsl }.each do |f|
|
23
|
+
require( File.join( File.dirname(__FILE__), "color", "models", f ) )
|
24
|
+
end
|
25
|
+
|
26
|
+
%w{ palette x11 css }.each do |f|
|
27
|
+
require( File.join( File.dirname(__FILE__), "color", "palettes", f ) )
|
28
|
+
end
|
29
|
+
|
30
|
+
|
28
31
|
|
29
32
|
module Rubygame
|
30
33
|
|
@@ -74,6 +77,36 @@ module Rubygame
|
|
74
77
|
GLOBAL[name] = color
|
75
78
|
end
|
76
79
|
|
80
|
+
|
81
|
+
# For use by Rubygame methods only:
|
82
|
+
|
83
|
+
# Convert a color name (string or symbol), Color instance, or Array
|
84
|
+
# to a color array.
|
85
|
+
def self.convert_color( color ) # :nodoc:
|
86
|
+
color =
|
87
|
+
if color.kind_of?(Symbol) or color.kind_of?(String)
|
88
|
+
Rubygame::Color[color].to_sdl_rgba_ary
|
89
|
+
elsif color.respond_to? :to_sdl_rgba_ary
|
90
|
+
color.to_sdl_rgba_ary
|
91
|
+
elsif color.respond_to? :to_ary
|
92
|
+
color.to_ary
|
93
|
+
else
|
94
|
+
raise TypeError, "unsupported type #{color.class} for color"
|
95
|
+
end
|
96
|
+
|
97
|
+
unless color.size.between?(3,4) and color.all?{|n| n.kind_of? Numeric}
|
98
|
+
raise TypeError, "invalid color: #{color.inspect}"
|
99
|
+
end
|
100
|
+
|
101
|
+
return color
|
102
|
+
end
|
103
|
+
|
104
|
+
def self.make_sdl_rgba( color ) # :nodoc:
|
105
|
+
r,g,b,a = convert_color(color).collect!{ |c| c.to_i }[0,4]
|
106
|
+
a = 255 if a.nil?
|
107
|
+
[r,g,b,a]
|
108
|
+
end
|
109
|
+
|
77
110
|
end
|
78
111
|
end
|
79
112
|
|
data/lib/rubygame/constants.rb
CHANGED
@@ -19,6 +19,303 @@
|
|
19
19
|
|
20
20
|
module Rubygame
|
21
21
|
|
22
|
+
|
23
|
+
# Event constants
|
24
|
+
NOEVENT = SDL::NOEVENT
|
25
|
+
ACTIVEEVENT = SDL::ACTIVEEVENT
|
26
|
+
KEYDOWN = SDL::KEYDOWN
|
27
|
+
KEYUP = SDL::KEYUP
|
28
|
+
MOUSEMOTION = SDL::MOUSEMOTION
|
29
|
+
MOUSEBUTTONDOWN = SDL::MOUSEBUTTONDOWN
|
30
|
+
MOUSEBUTTONUP = SDL::MOUSEBUTTONUP
|
31
|
+
JOYAXISMOTION = SDL::JOYAXISMOTION
|
32
|
+
JOYBALLMOTION = SDL::JOYBALLMOTION
|
33
|
+
JOYHATMOTION = SDL::JOYHATMOTION
|
34
|
+
JOYBUTTONDOWN = SDL::JOYBUTTONDOWN
|
35
|
+
JOYBUTTONUP = SDL::JOYBUTTONUP
|
36
|
+
QUIT = SDL::QUIT
|
37
|
+
SYSWMEVENT = SDL::SYSWMEVENT
|
38
|
+
VIDEORESIZE = SDL::VIDEORESIZE
|
39
|
+
VIDEOEXPOSE = SDL::VIDEOEXPOSE
|
40
|
+
USEREVENT = SDL::USEREVENT
|
41
|
+
|
42
|
+
|
43
|
+
# Joystick constants
|
44
|
+
HAT_CENTERED = SDL::HAT_CENTERED
|
45
|
+
HAT_UP = SDL::HAT_UP
|
46
|
+
HAT_RIGHT = SDL::HAT_RIGHT
|
47
|
+
HAT_DOWN = SDL::HAT_DOWN
|
48
|
+
HAT_LEFT = SDL::HAT_LEFT
|
49
|
+
HAT_RIGHTUP = SDL::HAT_RIGHTUP
|
50
|
+
HAT_RIGHTDOWN = SDL::HAT_RIGHTDOWN
|
51
|
+
HAT_LEFTUP = SDL::HAT_LEFTUP
|
52
|
+
HAT_LEFTDOWN = SDL::HAT_LEFTDOWN
|
53
|
+
|
54
|
+
|
55
|
+
# Mouse constants
|
56
|
+
MOUSE_LEFT = SDL::BUTTON_LEFT
|
57
|
+
MOUSE_MIDDLE = SDL::BUTTON_MIDDLE
|
58
|
+
MOUSE_RIGHT = SDL::BUTTON_RIGHT
|
59
|
+
MOUSE_LMASK = SDL::BUTTON_LMASK
|
60
|
+
MOUSE_MMASK = SDL::BUTTON_MMASK
|
61
|
+
MOUSE_RMASK = SDL::BUTTON_RMASK
|
62
|
+
|
63
|
+
|
64
|
+
# ASCII key symbols
|
65
|
+
K_UNKNOWN = SDL::K_UNKNOWN
|
66
|
+
K_FIRST = SDL::K_FIRST
|
67
|
+
K_BACKSPACE = SDL::K_BACKSPACE
|
68
|
+
K_TAB = SDL::K_TAB
|
69
|
+
K_CLEAR = SDL::K_CLEAR
|
70
|
+
K_RETURN = SDL::K_RETURN
|
71
|
+
K_PAUSE = SDL::K_PAUSE
|
72
|
+
K_ESCAPE = SDL::K_ESCAPE
|
73
|
+
K_SPACE = SDL::K_SPACE
|
74
|
+
K_EXCLAIM = SDL::K_EXCLAIM
|
75
|
+
K_QUOTEDBL = SDL::K_QUOTEDBL
|
76
|
+
K_HASH = SDL::K_HASH
|
77
|
+
K_DOLLAR = SDL::K_DOLLAR
|
78
|
+
K_AMPERSAND = SDL::K_AMPERSAND
|
79
|
+
K_QUOTE = SDL::K_QUOTE
|
80
|
+
K_LEFTPAREN = SDL::K_LEFTPAREN
|
81
|
+
K_RIGHTPAREN = SDL::K_RIGHTPAREN
|
82
|
+
K_ASTERISK = SDL::K_ASTERISK
|
83
|
+
K_PLUS = SDL::K_PLUS
|
84
|
+
K_COMMA = SDL::K_COMMA
|
85
|
+
K_MINUS = SDL::K_MINUS
|
86
|
+
K_PERIOD = SDL::K_PERIOD
|
87
|
+
K_SLASH = SDL::K_SLASH
|
88
|
+
K_0 = SDL::K_0
|
89
|
+
K_1 = SDL::K_1
|
90
|
+
K_2 = SDL::K_2
|
91
|
+
K_3 = SDL::K_3
|
92
|
+
K_4 = SDL::K_4
|
93
|
+
K_5 = SDL::K_5
|
94
|
+
K_6 = SDL::K_6
|
95
|
+
K_7 = SDL::K_7
|
96
|
+
K_8 = SDL::K_8
|
97
|
+
K_9 = SDL::K_9
|
98
|
+
K_COLON = SDL::K_COLON
|
99
|
+
K_SEMICOLON = SDL::K_SEMICOLON
|
100
|
+
K_LESS = SDL::K_LESS
|
101
|
+
K_EQUALS = SDL::K_EQUALS
|
102
|
+
K_GREATER = SDL::K_GREATER
|
103
|
+
K_QUESTION = SDL::K_QUESTION
|
104
|
+
K_AT = SDL::K_AT
|
105
|
+
K_LEFTBRACKET = SDL::K_LEFTBRACKET
|
106
|
+
K_BACKSLASH = SDL::K_BACKSLASH
|
107
|
+
K_RIGHTBRACKET = SDL::K_RIGHTBRACKET
|
108
|
+
K_CARET = SDL::K_CARET
|
109
|
+
K_UNDERSCORE = SDL::K_UNDERSCORE
|
110
|
+
K_BACKQUOTE = SDL::K_BACKQUOTE
|
111
|
+
K_A = SDL::K_a
|
112
|
+
K_B = SDL::K_b
|
113
|
+
K_C = SDL::K_c
|
114
|
+
K_D = SDL::K_d
|
115
|
+
K_E = SDL::K_e
|
116
|
+
K_F = SDL::K_f
|
117
|
+
K_G = SDL::K_g
|
118
|
+
K_H = SDL::K_h
|
119
|
+
K_I = SDL::K_i
|
120
|
+
K_J = SDL::K_j
|
121
|
+
K_K = SDL::K_k
|
122
|
+
K_L = SDL::K_l
|
123
|
+
K_M = SDL::K_m
|
124
|
+
K_N = SDL::K_n
|
125
|
+
K_O = SDL::K_o
|
126
|
+
K_P = SDL::K_p
|
127
|
+
K_Q = SDL::K_q
|
128
|
+
K_R = SDL::K_r
|
129
|
+
K_S = SDL::K_s
|
130
|
+
K_T = SDL::K_t
|
131
|
+
K_U = SDL::K_u
|
132
|
+
K_V = SDL::K_v
|
133
|
+
K_W = SDL::K_w
|
134
|
+
K_X = SDL::K_x
|
135
|
+
K_Y = SDL::K_y
|
136
|
+
K_Z = SDL::K_z
|
137
|
+
K_DELETE = SDL::K_DELETE
|
138
|
+
|
139
|
+
|
140
|
+
# International keyboard symbols
|
141
|
+
K_WORLD_0 = SDL::K_WORLD_0
|
142
|
+
K_WORLD_1 = SDL::K_WORLD_1
|
143
|
+
K_WORLD_2 = SDL::K_WORLD_2
|
144
|
+
K_WORLD_3 = SDL::K_WORLD_3
|
145
|
+
K_WORLD_4 = SDL::K_WORLD_4
|
146
|
+
K_WORLD_5 = SDL::K_WORLD_5
|
147
|
+
K_WORLD_6 = SDL::K_WORLD_6
|
148
|
+
K_WORLD_7 = SDL::K_WORLD_7
|
149
|
+
K_WORLD_8 = SDL::K_WORLD_8
|
150
|
+
K_WORLD_9 = SDL::K_WORLD_9
|
151
|
+
K_WORLD_10 = SDL::K_WORLD_10
|
152
|
+
K_WORLD_11 = SDL::K_WORLD_11
|
153
|
+
K_WORLD_12 = SDL::K_WORLD_12
|
154
|
+
K_WORLD_13 = SDL::K_WORLD_13
|
155
|
+
K_WORLD_14 = SDL::K_WORLD_14
|
156
|
+
K_WORLD_15 = SDL::K_WORLD_15
|
157
|
+
K_WORLD_16 = SDL::K_WORLD_16
|
158
|
+
K_WORLD_17 = SDL::K_WORLD_17
|
159
|
+
K_WORLD_18 = SDL::K_WORLD_18
|
160
|
+
K_WORLD_19 = SDL::K_WORLD_19
|
161
|
+
K_WORLD_20 = SDL::K_WORLD_20
|
162
|
+
K_WORLD_21 = SDL::K_WORLD_21
|
163
|
+
K_WORLD_22 = SDL::K_WORLD_22
|
164
|
+
K_WORLD_23 = SDL::K_WORLD_23
|
165
|
+
K_WORLD_24 = SDL::K_WORLD_24
|
166
|
+
K_WORLD_25 = SDL::K_WORLD_25
|
167
|
+
K_WORLD_26 = SDL::K_WORLD_26
|
168
|
+
K_WORLD_27 = SDL::K_WORLD_27
|
169
|
+
K_WORLD_28 = SDL::K_WORLD_28
|
170
|
+
K_WORLD_29 = SDL::K_WORLD_29
|
171
|
+
K_WORLD_30 = SDL::K_WORLD_30
|
172
|
+
K_WORLD_31 = SDL::K_WORLD_31
|
173
|
+
K_WORLD_32 = SDL::K_WORLD_32
|
174
|
+
K_WORLD_33 = SDL::K_WORLD_33
|
175
|
+
K_WORLD_34 = SDL::K_WORLD_34
|
176
|
+
K_WORLD_35 = SDL::K_WORLD_35
|
177
|
+
K_WORLD_36 = SDL::K_WORLD_36
|
178
|
+
K_WORLD_37 = SDL::K_WORLD_37
|
179
|
+
K_WORLD_38 = SDL::K_WORLD_38
|
180
|
+
K_WORLD_39 = SDL::K_WORLD_39
|
181
|
+
K_WORLD_40 = SDL::K_WORLD_40
|
182
|
+
K_WORLD_41 = SDL::K_WORLD_41
|
183
|
+
K_WORLD_42 = SDL::K_WORLD_42
|
184
|
+
K_WORLD_43 = SDL::K_WORLD_43
|
185
|
+
K_WORLD_44 = SDL::K_WORLD_44
|
186
|
+
K_WORLD_45 = SDL::K_WORLD_45
|
187
|
+
K_WORLD_46 = SDL::K_WORLD_46
|
188
|
+
K_WORLD_47 = SDL::K_WORLD_47
|
189
|
+
K_WORLD_48 = SDL::K_WORLD_48
|
190
|
+
K_WORLD_49 = SDL::K_WORLD_49
|
191
|
+
K_WORLD_50 = SDL::K_WORLD_50
|
192
|
+
K_WORLD_51 = SDL::K_WORLD_51
|
193
|
+
K_WORLD_52 = SDL::K_WORLD_52
|
194
|
+
K_WORLD_53 = SDL::K_WORLD_53
|
195
|
+
K_WORLD_54 = SDL::K_WORLD_54
|
196
|
+
K_WORLD_55 = SDL::K_WORLD_55
|
197
|
+
K_WORLD_56 = SDL::K_WORLD_56
|
198
|
+
K_WORLD_57 = SDL::K_WORLD_57
|
199
|
+
K_WORLD_58 = SDL::K_WORLD_58
|
200
|
+
K_WORLD_59 = SDL::K_WORLD_59
|
201
|
+
K_WORLD_60 = SDL::K_WORLD_60
|
202
|
+
K_WORLD_61 = SDL::K_WORLD_61
|
203
|
+
K_WORLD_62 = SDL::K_WORLD_62
|
204
|
+
K_WORLD_63 = SDL::K_WORLD_63
|
205
|
+
K_WORLD_64 = SDL::K_WORLD_64
|
206
|
+
K_WORLD_65 = SDL::K_WORLD_65
|
207
|
+
K_WORLD_66 = SDL::K_WORLD_66
|
208
|
+
K_WORLD_67 = SDL::K_WORLD_67
|
209
|
+
K_WORLD_68 = SDL::K_WORLD_68
|
210
|
+
K_WORLD_69 = SDL::K_WORLD_69
|
211
|
+
K_WORLD_70 = SDL::K_WORLD_70
|
212
|
+
K_WORLD_71 = SDL::K_WORLD_71
|
213
|
+
K_WORLD_72 = SDL::K_WORLD_72
|
214
|
+
K_WORLD_73 = SDL::K_WORLD_73
|
215
|
+
K_WORLD_74 = SDL::K_WORLD_74
|
216
|
+
K_WORLD_75 = SDL::K_WORLD_75
|
217
|
+
K_WORLD_76 = SDL::K_WORLD_76
|
218
|
+
K_WORLD_77 = SDL::K_WORLD_77
|
219
|
+
K_WORLD_78 = SDL::K_WORLD_78
|
220
|
+
K_WORLD_79 = SDL::K_WORLD_79
|
221
|
+
K_WORLD_80 = SDL::K_WORLD_80
|
222
|
+
K_WORLD_81 = SDL::K_WORLD_81
|
223
|
+
K_WORLD_82 = SDL::K_WORLD_82
|
224
|
+
K_WORLD_83 = SDL::K_WORLD_83
|
225
|
+
K_WORLD_84 = SDL::K_WORLD_84
|
226
|
+
K_WORLD_85 = SDL::K_WORLD_85
|
227
|
+
K_WORLD_86 = SDL::K_WORLD_86
|
228
|
+
K_WORLD_87 = SDL::K_WORLD_87
|
229
|
+
K_WORLD_88 = SDL::K_WORLD_88
|
230
|
+
K_WORLD_89 = SDL::K_WORLD_89
|
231
|
+
K_WORLD_90 = SDL::K_WORLD_90
|
232
|
+
K_WORLD_91 = SDL::K_WORLD_91
|
233
|
+
K_WORLD_92 = SDL::K_WORLD_92
|
234
|
+
K_WORLD_93 = SDL::K_WORLD_93
|
235
|
+
K_WORLD_94 = SDL::K_WORLD_94
|
236
|
+
K_WORLD_95 = SDL::K_WORLD_95
|
237
|
+
|
238
|
+
|
239
|
+
# Numeric keypad symbols
|
240
|
+
K_KP0 = SDL::K_KP0
|
241
|
+
K_KP1 = SDL::K_KP1
|
242
|
+
K_KP2 = SDL::K_KP2
|
243
|
+
K_KP3 = SDL::K_KP3
|
244
|
+
K_KP4 = SDL::K_KP4
|
245
|
+
K_KP5 = SDL::K_KP5
|
246
|
+
K_KP6 = SDL::K_KP6
|
247
|
+
K_KP7 = SDL::K_KP7
|
248
|
+
K_KP8 = SDL::K_KP8
|
249
|
+
K_KP9 = SDL::K_KP9
|
250
|
+
K_KP_PERIOD = SDL::K_KP_PERIOD
|
251
|
+
K_KP_DIVIDE = SDL::K_KP_DIVIDE
|
252
|
+
K_KP_MULTIPLY = SDL::K_KP_MULTIPLY
|
253
|
+
K_KP_MINUS = SDL::K_KP_MINUS
|
254
|
+
K_KP_PLUS = SDL::K_KP_PLUS
|
255
|
+
K_KP_ENTER = SDL::K_KP_ENTER
|
256
|
+
K_KP_EQUALS = SDL::K_KP_EQUALS
|
257
|
+
|
258
|
+
|
259
|
+
# Arrows + Home/End pad
|
260
|
+
K_UP = SDL::K_UP
|
261
|
+
K_DOWN = SDL::K_DOWN
|
262
|
+
K_RIGHT = SDL::K_RIGHT
|
263
|
+
K_LEFT = SDL::K_LEFT
|
264
|
+
K_INSERT = SDL::K_INSERT
|
265
|
+
K_HOME = SDL::K_HOME
|
266
|
+
K_END = SDL::K_END
|
267
|
+
K_PAGEUP = SDL::K_PAGEUP
|
268
|
+
K_PAGEDOWN = SDL::K_PAGEDOWN
|
269
|
+
|
270
|
+
|
271
|
+
# Function keys
|
272
|
+
K_F1 = SDL::K_F1
|
273
|
+
K_F2 = SDL::K_F2
|
274
|
+
K_F3 = SDL::K_F3
|
275
|
+
K_F4 = SDL::K_F4
|
276
|
+
K_F5 = SDL::K_F5
|
277
|
+
K_F6 = SDL::K_F6
|
278
|
+
K_F7 = SDL::K_F7
|
279
|
+
K_F8 = SDL::K_F8
|
280
|
+
K_F9 = SDL::K_F9
|
281
|
+
K_F10 = SDL::K_F10
|
282
|
+
K_F11 = SDL::K_F11
|
283
|
+
K_F12 = SDL::K_F12
|
284
|
+
K_F13 = SDL::K_F13
|
285
|
+
K_F14 = SDL::K_F14
|
286
|
+
K_F15 = SDL::K_F15
|
287
|
+
|
288
|
+
|
289
|
+
# Key state modifier keys
|
290
|
+
K_NUMLOCK = SDL::K_NUMLOCK
|
291
|
+
K_CAPSLOCK = SDL::K_CAPSLOCK
|
292
|
+
K_SCROLLOCK = SDL::K_SCROLLOCK
|
293
|
+
K_RSHIFT = SDL::K_RSHIFT
|
294
|
+
K_LSHIFT = SDL::K_LSHIFT
|
295
|
+
K_RCTRL = SDL::K_RCTRL
|
296
|
+
K_LCTRL = SDL::K_LCTRL
|
297
|
+
K_RALT = SDL::K_RALT
|
298
|
+
K_LALT = SDL::K_LALT
|
299
|
+
K_RMETA = SDL::K_RMETA
|
300
|
+
K_LMETA = SDL::K_LMETA
|
301
|
+
K_LSUPER = SDL::K_LSUPER
|
302
|
+
K_RSUPER = SDL::K_RSUPER
|
303
|
+
K_MODE = SDL::K_MODE
|
304
|
+
|
305
|
+
|
306
|
+
# Miscellaneous keys
|
307
|
+
K_HELP = SDL::K_HELP
|
308
|
+
K_PRINT = SDL::K_PRINT
|
309
|
+
K_SYSREQ = SDL::K_SYSREQ
|
310
|
+
K_BREAK = SDL::K_BREAK
|
311
|
+
K_MENU = SDL::K_MENU
|
312
|
+
K_POWER = SDL::K_POWER
|
313
|
+
K_EURO = SDL::K_EURO
|
314
|
+
K_LAST = SDL::K_LAST
|
315
|
+
|
316
|
+
|
317
|
+
|
318
|
+
|
22
319
|
module Mouse
|
23
320
|
# Hash to translate mouse button sym to string
|
24
321
|
MOUSE2STR = {
|
@@ -0,0 +1,555 @@
|
|
1
|
+
#--
|
2
|
+
# Rubygame -- Ruby code and bindings to SDL to facilitate game creation
|
3
|
+
# Copyright (C) 2004-2009 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
|
+
# **NOTE:** This module is DEPRECATED and will be removed in Rubygame 3.0.
|
22
|
+
# Please use Rubygame.open_audio, Rubygame.close_audio, Rubygame::Sound,
|
23
|
+
# and Rubygame::Music instead.
|
24
|
+
#
|
25
|
+
# The Mixer module provides access to the SDL_mixer library for audio
|
26
|
+
# playback and mixing. This module is still very basic, but it is
|
27
|
+
# good enough to load and play WAV files on multiple mix channels.
|
28
|
+
#
|
29
|
+
# See the Sample class for loading audio files.
|
30
|
+
# See the Music class for streaming music from a file.
|
31
|
+
#
|
32
|
+
module Rubygame::Mixer
|
33
|
+
|
34
|
+
AUDIO_U8 = SDL::AUDIO_U8
|
35
|
+
AUDIO_S8 = SDL::AUDIO_S8
|
36
|
+
AUDIO_U16SYS = SDL::AUDIO_U16SYS
|
37
|
+
AUDIO_S16SYS = SDL::AUDIO_S16SYS
|
38
|
+
|
39
|
+
|
40
|
+
# **NOTE:** This method is DEPRECATED and will be removed in
|
41
|
+
# Rubygame 3.0. Please use the Rubygame.open_audio instead.
|
42
|
+
#
|
43
|
+
# Initializes the audio device. You must call this before using the other
|
44
|
+
# mixer functions. See also #close_audio().
|
45
|
+
#
|
46
|
+
# Returns nil. May raise an SDLError if initialization fails.
|
47
|
+
#
|
48
|
+
# This method takes these arguments:
|
49
|
+
#
|
50
|
+
# frequency:: output sample rate in audio samples per second (Hz).
|
51
|
+
# Affects the quality of the sound output, at the
|
52
|
+
# expense of CPU usage. If nil, the default (22050) is
|
53
|
+
# used. 22050 is recommended for most games. For
|
54
|
+
# reference, 44100 is CD quality.
|
55
|
+
#
|
56
|
+
# The larger the value, the more processing required.
|
57
|
+
#
|
58
|
+
# format:: output sample format. If nil, the default recommended
|
59
|
+
# system format is used. It's _highly_ recommended you
|
60
|
+
# leave this nil!
|
61
|
+
#
|
62
|
+
# But if you're feeling reckless, you can use one of these
|
63
|
+
# constants located in the Rubygame::Mixer module:
|
64
|
+
#
|
65
|
+
# AUDIO_U16SYS:: unsigned 16-bit samples.
|
66
|
+
# AUDIO_S16SYS:: signed 16-bit samples.
|
67
|
+
# AUDIO_U8:: unsigned 8-bit samples.
|
68
|
+
# AUDIO_S8:: signed 8-bit samples.
|
69
|
+
#
|
70
|
+
# channels:: output sound channels. Use 2 for stereo, 1 for mono.
|
71
|
+
# If nil, the default (2) is used.
|
72
|
+
# This option is not related to mixing channels.
|
73
|
+
#
|
74
|
+
# buffer:: size of the sound buffer, in bytes. If nil, the default
|
75
|
+
# (1024) is used. Larger values have more delay before
|
76
|
+
# playing a sound, but require less CPU usage (and
|
77
|
+
# have less skipping on slow systems).
|
78
|
+
#
|
79
|
+
#
|
80
|
+
def self.open_audio( frequency=nil, format=nil, channels=nil, buffer=nil )
|
81
|
+
|
82
|
+
Rubygame.deprecated( "Rubygame::Mixer", "3.0" )
|
83
|
+
|
84
|
+
frequency = (frequency or 22050)
|
85
|
+
format = (format or AUDIO_U16SYS)
|
86
|
+
channels = (channels or 2)
|
87
|
+
buffer = (buffer or 1024)
|
88
|
+
|
89
|
+
result = SDL::Mixer.OpenAudio(frequency, format, channels, buffer)
|
90
|
+
|
91
|
+
if( result < 0 )
|
92
|
+
raise( Rubygame::SDLError,
|
93
|
+
"Error initializing SDL_mixer: #{SDL.GetError()}" )
|
94
|
+
end
|
95
|
+
|
96
|
+
return nil
|
97
|
+
end
|
98
|
+
|
99
|
+
|
100
|
+
# **NOTE:** This method is DEPRECATED and will be removed in
|
101
|
+
# Rubygame 3.0. Please use the Rubygame.close_audio instead.
|
102
|
+
#
|
103
|
+
# Close the audio device being used by the mixer. You should not use any
|
104
|
+
# mixer functions after this function, unless you use #open_audio() to
|
105
|
+
# re-open the audio device. See also #open_audio().
|
106
|
+
#
|
107
|
+
# Returns nil.
|
108
|
+
#
|
109
|
+
def self.close_audio()
|
110
|
+
Rubygame.deprecated( "Rubygame::Mixer", "3.0" )
|
111
|
+
SDL::Mixer.CloseAudio()
|
112
|
+
return nil
|
113
|
+
end
|
114
|
+
|
115
|
+
|
116
|
+
# **NOTE:** This method is DEPRECATED and will be removed in
|
117
|
+
# Rubygame 3.0. Please use the Rubygame::Sound class instead.
|
118
|
+
#
|
119
|
+
# Returns the number of mixing channels currently allocated.
|
120
|
+
# See also #mix_channels=
|
121
|
+
#
|
122
|
+
def self.mix_channels
|
123
|
+
Rubygame.deprecated( "Rubygame::Mixer", "3.0" )
|
124
|
+
return SDL::Mixer.AllocateChannels(-1)
|
125
|
+
end
|
126
|
+
|
127
|
+
|
128
|
+
# **NOTE:** This method is DEPRECATED and will be removed in
|
129
|
+
# Rubygame 3.0. Please use the Rubygame::Sound class instead.
|
130
|
+
#
|
131
|
+
# Set the number of mixer channels, allocating or deallocating channels as
|
132
|
+
# needed. This can be called many times, even during audio playback. If this
|
133
|
+
# call reduces the number of channels allocated, the excess channels will
|
134
|
+
# be stopped automatically. See also #mix_channels
|
135
|
+
#
|
136
|
+
# Returns the number of mixing channels allocated.
|
137
|
+
#
|
138
|
+
# Note that 8 mixing channels are allocated when #open_audio is called.
|
139
|
+
# This method only needs to be called if you want a different number (either
|
140
|
+
# greater or fewer) of mixing channels.
|
141
|
+
#
|
142
|
+
# This method takes this argument:
|
143
|
+
# num_channels:: desired number of mixing channels, an integer.
|
144
|
+
# Negative values will cause this method to behave as
|
145
|
+
# #mix_channels, returning the number of channels
|
146
|
+
# currently allocated, without changing it.
|
147
|
+
#
|
148
|
+
def self.mix_channels=( num_channels )
|
149
|
+
Rubygame.deprecated( "Rubygame::Mixer", "3.0" )
|
150
|
+
return SDL::Mixer.AllocateChannels( num_channels )
|
151
|
+
end
|
152
|
+
|
153
|
+
|
154
|
+
# **NOTE:** This method is DEPRECATED and will be removed in
|
155
|
+
# Rubygame 3.0. Please use the Rubygame.audio_driver instead.
|
156
|
+
#
|
157
|
+
# Returns the name of the audio driver that SDL is using.
|
158
|
+
#
|
159
|
+
# May raise SDLError if initialization fails.
|
160
|
+
#
|
161
|
+
def self.driver_name
|
162
|
+
Rubygame.deprecated( "Rubygame::Mixer", "3.0" )
|
163
|
+
|
164
|
+
driver = SDL.AudioDriverName()
|
165
|
+
|
166
|
+
if driver.nil?
|
167
|
+
raise( Rubygame::SDLError,
|
168
|
+
"Error fetching audio driver name: #{SDL.GetError()}" )
|
169
|
+
end
|
170
|
+
|
171
|
+
return driver
|
172
|
+
end
|
173
|
+
|
174
|
+
|
175
|
+
# **NOTE:** This method is DEPRECATED and will be removed in
|
176
|
+
# Rubygame 3.0. Please use the Rubygame::Sound class instead.
|
177
|
+
#
|
178
|
+
# Play an audio Sample on a mixing channel, repeating a certain number
|
179
|
+
# of extra times. Returns the number of the channel that the sample
|
180
|
+
# is being played on.
|
181
|
+
#
|
182
|
+
# Raises SDLError if something goes wrong.
|
183
|
+
#
|
184
|
+
# This method takes these arguments:
|
185
|
+
# sample:: what Sample to play
|
186
|
+
# channel_num:: which mixing channel to play the sample on.
|
187
|
+
# Use -1 to play on the first unreserved channel.
|
188
|
+
# repeats:: how many extra times to repeat the sample.
|
189
|
+
# Can be -1 to repeat forever until it is stopped.
|
190
|
+
#
|
191
|
+
def self.play( sample, channel_num, repeats )
|
192
|
+
Rubygame.deprecated( "Rubygame::Mixer", "3.0" )
|
193
|
+
|
194
|
+
result = SDL::Mixer.PlayChannel( channel_num, sample.struct, repeats )
|
195
|
+
|
196
|
+
if( result < 0 )
|
197
|
+
raise( Rubygame::SDLError,
|
198
|
+
"Error playing sample on channel %d: %s"%
|
199
|
+
[channel, SDL.GetError()] )
|
200
|
+
end
|
201
|
+
|
202
|
+
return result
|
203
|
+
end
|
204
|
+
|
205
|
+
|
206
|
+
# Stop playback of a playing or paused mixing channel.
|
207
|
+
# Unlike #pause, playback cannot be resumed from the current point.
|
208
|
+
# See also #play.
|
209
|
+
#
|
210
|
+
def self.stop( channel_num )
|
211
|
+
Rubygame.deprecated( "Rubygame::Mixer", "3.0" )
|
212
|
+
SDL::Mixer.HaltChannel( channel_num )
|
213
|
+
return nil
|
214
|
+
end
|
215
|
+
|
216
|
+
|
217
|
+
# Pause playback of a currently-playing mixing channel.
|
218
|
+
# Playback can be resumed from the current point with #resume.
|
219
|
+
# See also #stop.
|
220
|
+
#
|
221
|
+
def self.pause( channel_num )
|
222
|
+
Rubygame.deprecated( "Rubygame::Mixer", "3.0" )
|
223
|
+
SDL::Mixer.Pause( channel_num )
|
224
|
+
return nil
|
225
|
+
end
|
226
|
+
|
227
|
+
|
228
|
+
# Resume playback of a paused mixing channel. The channel must have
|
229
|
+
# been paused (via the #pause method) for this to have any effect.
|
230
|
+
# Playback will resume from the point where the channel was paused.
|
231
|
+
#
|
232
|
+
def self.resume( channel_num )
|
233
|
+
Rubygame.deprecated( "Rubygame::Mixer", "3.0" )
|
234
|
+
SDL::Mixer.Resume( channel_num )
|
235
|
+
return nil
|
236
|
+
end
|
237
|
+
|
238
|
+
end
|
239
|
+
|
240
|
+
|
241
|
+
|
242
|
+
# **NOTE:** This class is DEPRECATED and will be removed in Rubygame 3.0.
|
243
|
+
# Please use the Rubygame::Sound class instead.
|
244
|
+
#
|
245
|
+
# Stores audio data to play with Rubygame::Mixer.play
|
246
|
+
#
|
247
|
+
class Rubygame::Mixer::Sample
|
248
|
+
|
249
|
+
# **NOTE:** Rubygame::Mixer::Sample is DEPRECATED and will be removed in
|
250
|
+
# Rubygame 3.0. Please use the Rubygame::Sound class instead.
|
251
|
+
#
|
252
|
+
# Load an audio sample (a "chunk", to use SDL_mixer's term) from a file.
|
253
|
+
# Only WAV files are supported at this time.
|
254
|
+
#
|
255
|
+
# Raises SDLError if the sample could not be loaded.
|
256
|
+
#
|
257
|
+
def self.load_audio( filename )
|
258
|
+
Rubygame.deprecated( "Rubygame::Mixer::Sample", "3.0" )
|
259
|
+
|
260
|
+
chunk = SDL::Mixer.LoadWAV( filename )
|
261
|
+
|
262
|
+
if( chunk.pointer.null? )
|
263
|
+
raise( Rubygame::SDLError,
|
264
|
+
"Error loading audio Sample from file `%s': %s"%
|
265
|
+
[filename, SDL.GetError()] )
|
266
|
+
end
|
267
|
+
|
268
|
+
return new( chunk )
|
269
|
+
end
|
270
|
+
|
271
|
+
|
272
|
+
attr_reader :struct # :nodoc:
|
273
|
+
protected :struct
|
274
|
+
|
275
|
+
|
276
|
+
# call-seq: new
|
277
|
+
def initialize( struct=nil )
|
278
|
+
@struct = struct
|
279
|
+
end
|
280
|
+
|
281
|
+
end
|
282
|
+
|
283
|
+
|
284
|
+
|
285
|
+
# **NOTE:** This class is DEPRECATED and will be removed in Rubygame 3.0.
|
286
|
+
# Please use the Rubygame::Music class instead.
|
287
|
+
#
|
288
|
+
# The Music class is used for playing music from a file. It supports
|
289
|
+
# WAVE, MOD, MIDI, OGG, and MP3 files. There are two important differences
|
290
|
+
# between Music and Sample:
|
291
|
+
#
|
292
|
+
# 1. Music streams the music from disk, which means it can start faster and
|
293
|
+
# uses less memory than Sample, which loads the entire file into memory.
|
294
|
+
# This is especially important for music files, which are often several
|
295
|
+
# minutes long.
|
296
|
+
# 2. There can only be one Music instance playing at once, while there can
|
297
|
+
# be many Samples playing at once. If you play a second Music while one
|
298
|
+
# is already playing, the first one will be stopped. See #play.
|
299
|
+
#
|
300
|
+
class Rubygame::Mixer::Music
|
301
|
+
|
302
|
+
# # Sets the external command used to play music.
|
303
|
+
# #
|
304
|
+
# # Raises SDLError if something goes wrong.
|
305
|
+
# #
|
306
|
+
# # This method takes these arguments:
|
307
|
+
# # command:: what command to use to play the music.
|
308
|
+
# #
|
309
|
+
# def set_command( command )
|
310
|
+
# Rubygame.deprecated( "Rubygame::Mixer::Music", "3.0" )
|
311
|
+
#
|
312
|
+
# result = SDL::Mixer.SetMusicCMD( command )
|
313
|
+
#
|
314
|
+
# if( result < 0 )
|
315
|
+
# raise( Rubygame::SDLError,
|
316
|
+
# "Error setting music player command to `%s': %s"%
|
317
|
+
# [command, SDL.GetError()] )
|
318
|
+
# end
|
319
|
+
#
|
320
|
+
# return result
|
321
|
+
# end
|
322
|
+
|
323
|
+
|
324
|
+
# **NOTE:** Rubygame::Mixer::Music is DEPRECATED and will be removed
|
325
|
+
# in Rubygame 3.0. Please use the Rubygame::Music class instead.
|
326
|
+
#
|
327
|
+
# Load music from a file. Supports WAV, MOD, MIDI, OGG, and MP3 formats.
|
328
|
+
#
|
329
|
+
# Raises SDLError if the music could not be loaded.
|
330
|
+
#
|
331
|
+
def self.load_audio
|
332
|
+
Rubygame.deprecated( "Rubygame::Mixer::Music", "3.0" )
|
333
|
+
|
334
|
+
music = SDL::Mixer.LoadMUS( filename )
|
335
|
+
|
336
|
+
if( music.pointer.null? )
|
337
|
+
raise( Rubygame::SDLError,
|
338
|
+
"Error loading audio music from file `%s': %s"%
|
339
|
+
[filename, SDL.GetError()] )
|
340
|
+
end
|
341
|
+
|
342
|
+
return new( music )
|
343
|
+
end
|
344
|
+
|
345
|
+
|
346
|
+
attr_reader :struct # :nodoc:
|
347
|
+
protected :struct
|
348
|
+
|
349
|
+
|
350
|
+
# call-seq: new
|
351
|
+
def initialize( struct=nil )
|
352
|
+
@struct = struct
|
353
|
+
end
|
354
|
+
|
355
|
+
|
356
|
+
# Play music, repeating a certain number of extra times. If
|
357
|
+
# any music was already playing, that music will be stopped
|
358
|
+
# first, and this music will start.
|
359
|
+
#
|
360
|
+
# Raises SDLError if something goes wrong.
|
361
|
+
#
|
362
|
+
# This method takes these arguments:
|
363
|
+
# repeats:: how many extra times to play the music.
|
364
|
+
# Can be -1 to repeat forever until it is stopped.
|
365
|
+
#
|
366
|
+
def play( repeats=0 )
|
367
|
+
# Adjust so repeats means the same as it does for Samples
|
368
|
+
repeats += 1 if repeats > -1
|
369
|
+
|
370
|
+
result = SDL::Mixer.PlayMusic( @struct, repeats )
|
371
|
+
|
372
|
+
if( result < 0 )
|
373
|
+
raise Rubygame::SDLError, "Error playing music: #{SDL.GetError()}"
|
374
|
+
end
|
375
|
+
|
376
|
+
return self
|
377
|
+
end
|
378
|
+
|
379
|
+
|
380
|
+
# Stop playback of music.
|
381
|
+
# See also #play
|
382
|
+
#
|
383
|
+
def stop
|
384
|
+
SDL::Mixer::HaltMusic()
|
385
|
+
return self
|
386
|
+
end
|
387
|
+
|
388
|
+
|
389
|
+
# Pause playback of the playing music. You can later #resume
|
390
|
+
# playback from the point where you paused.
|
391
|
+
# Safe to use on already-paused music.
|
392
|
+
# See also #play_music.
|
393
|
+
#
|
394
|
+
def pause
|
395
|
+
SDL::Mixer::PauseMusic()
|
396
|
+
return self
|
397
|
+
end
|
398
|
+
|
399
|
+
|
400
|
+
# Resume playback of paused music from the point it was paused.
|
401
|
+
# Safe to use on already-playing music.
|
402
|
+
# See also #play.
|
403
|
+
#
|
404
|
+
def resume
|
405
|
+
SDL::Mixer::ResumeMusic()
|
406
|
+
return self
|
407
|
+
end
|
408
|
+
|
409
|
+
|
410
|
+
# Rewind the music to the start. This is safe to use on stopped,
|
411
|
+
# paused, and playing music. Only works for MOD, OGG, MP3, and
|
412
|
+
# MIDI (but not WAV).
|
413
|
+
#
|
414
|
+
def rewind
|
415
|
+
SDL::Mixer::RewindMusic()
|
416
|
+
return self
|
417
|
+
end
|
418
|
+
|
419
|
+
|
420
|
+
# Jump to a certain time in the music.
|
421
|
+
# Only works when music is playing or paused (but not stopped).
|
422
|
+
# Only works for OGG and MP3 files.
|
423
|
+
#
|
424
|
+
# Raises SDLError if something goes wrong, or if the music type does not
|
425
|
+
# support setting the position.
|
426
|
+
#
|
427
|
+
# time:: Time to jump to, in seconds from the beginning.
|
428
|
+
#
|
429
|
+
def jump( time )
|
430
|
+
case SDL::Mixer.GetMusicType(nil)
|
431
|
+
when SDL::Mixer::MUS_OGG, SDL::Mixer::MUS_MP3
|
432
|
+
|
433
|
+
SDL::Mixer::RewindMusic() # Needed for MP3, and OK with OGG
|
434
|
+
|
435
|
+
result = SDL::Mixer.SetmusicPosition( time )
|
436
|
+
|
437
|
+
if( result < 0 )
|
438
|
+
raise( Rubygame::SDLError,
|
439
|
+
"Error jumping to time in music: #{SDL.GetError()}" )
|
440
|
+
end
|
441
|
+
|
442
|
+
when SDL::Mixer::MUS_NONE
|
443
|
+
raise Rubygame::SDLError, "Cannot jump when no music is playing."
|
444
|
+
else
|
445
|
+
raise Rubygame::SDLError, "Music type does not support jumping."
|
446
|
+
end
|
447
|
+
end
|
448
|
+
|
449
|
+
|
450
|
+
# Returns true if the music is currently playing.
|
451
|
+
#
|
452
|
+
def playing?
|
453
|
+
return SDL::Mixer::PlayingMusic()
|
454
|
+
end
|
455
|
+
|
456
|
+
|
457
|
+
# Returns true if the music is currently paused.
|
458
|
+
#
|
459
|
+
def paused?
|
460
|
+
return SDL::Mixer::PausedMusic()
|
461
|
+
end
|
462
|
+
|
463
|
+
|
464
|
+
# Returns the current volume level of the music.
|
465
|
+
# 0.0 is total silence, 1.0 is maximum volume.
|
466
|
+
#
|
467
|
+
def volume
|
468
|
+
return (SDL::Mixer::VolumeMusic(-1).to_f / SDL::Mixer::MAX_VOLUME)
|
469
|
+
end
|
470
|
+
|
471
|
+
|
472
|
+
# Sets the volume level of the music.
|
473
|
+
# 0.0 is total silence, 1.0 is maximum volume.
|
474
|
+
#
|
475
|
+
def volume=( new_volume )
|
476
|
+
SDL::Mixer.VolumeMusic( (volume * SDL::Mixer::MAX_VOLUME).to_i )
|
477
|
+
return new_volume
|
478
|
+
end
|
479
|
+
|
480
|
+
|
481
|
+
# Play the music, fading in and repeating a certain number of times.
|
482
|
+
# See also #play.
|
483
|
+
#
|
484
|
+
# Raises SDLError if something goes wrong.
|
485
|
+
#
|
486
|
+
# fade_time:: Time in seconds for the fade-in effect to complete.
|
487
|
+
# repeats:: Number of extra times to play through the music.
|
488
|
+
# -1 plays the music forever until it is stopped.
|
489
|
+
# Defaults to 0, play only once (no repeats).
|
490
|
+
# start:: Time to start from, in seconds since the beginning.
|
491
|
+
# Defaults to 0, the beginning of the song.
|
492
|
+
# Non-zero values only work for OGG and MP3; other
|
493
|
+
# music types will raise SDLError.
|
494
|
+
#
|
495
|
+
def fade_in( fade_time, repeats=0, start=0 )
|
496
|
+
fade_time *= 1000 # convert to milliseconds
|
497
|
+
repeats = (repeats or 0)
|
498
|
+
start = (start or 0)
|
499
|
+
|
500
|
+
# Adjust so repeats means the same as it does for Samples
|
501
|
+
repeats += 1 if repeats > -1
|
502
|
+
|
503
|
+
result =
|
504
|
+
if( start == 0 )
|
505
|
+
SDL::Mixer.FadeInMusic( @struct, repeats, fade_time )
|
506
|
+
else
|
507
|
+
SDL::Mixer.FadeInMusicPos( @struct, repeats, fade_time, start )
|
508
|
+
end
|
509
|
+
|
510
|
+
if( result < 0 )
|
511
|
+
raise Rubygame::SDLError, "Error fading in music: #{SDL.GetError()}"
|
512
|
+
end
|
513
|
+
|
514
|
+
return self
|
515
|
+
end
|
516
|
+
|
517
|
+
|
518
|
+
# Gradually fade the music to silence over +fade_length+ seconds.
|
519
|
+
# After the fade is complete, the music will be automatically stopped.
|
520
|
+
#
|
521
|
+
# Raises SDLError if something goes wrong.
|
522
|
+
#
|
523
|
+
# fade_time:: Time until the music is totally silent, in seconds.
|
524
|
+
#
|
525
|
+
def fade_out( fade_time )
|
526
|
+
fade_time *= 1000 # convert to milliseconds
|
527
|
+
|
528
|
+
result = SDL::Mixer.FadeOutMusic( fade_time )
|
529
|
+
|
530
|
+
if( result < 0 )
|
531
|
+
raise Rubygame::SDLError, "Error fading out music: #{SDL.GetError()}"
|
532
|
+
end
|
533
|
+
end
|
534
|
+
|
535
|
+
|
536
|
+
# True if the music is fading in or out (or either). You can
|
537
|
+
# specify +direction+ as :in/:out to check only fading in/out;
|
538
|
+
# otherwise, it will return true if it's fading either way.
|
539
|
+
#
|
540
|
+
# direction:: :in, :out, or nil if you don't care which.
|
541
|
+
# Returns:: true if the music is fading in the given direction.
|
542
|
+
#
|
543
|
+
def fading?( direction=nil )
|
544
|
+
case direction
|
545
|
+
when :in
|
546
|
+
return (SDL::Mixer.FadingMusic() == SDL::Mixer::FADING_IN)
|
547
|
+
when :out
|
548
|
+
return (SDL::Mixer.FadingMusic() == SDL::Mixer::FADING_OUT)
|
549
|
+
else
|
550
|
+
return (SDL::Mixer.FadingMusic() != SDL::Mixer::NO_FADING)
|
551
|
+
end
|
552
|
+
end
|
553
|
+
end
|
554
|
+
|
555
|
+
|