rubygame 2.3.0-x86-linux
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CREDITS +60 -0
- data/LICENSE +504 -0
- data/NEWS +252 -0
- data/README +123 -0
- data/ROADMAP +109 -0
- data/Rakefile +438 -0
- data/doc/extended_readme.rdoc +49 -0
- data/doc/getting_started.rdoc +47 -0
- data/doc/macosx_install.rdoc +70 -0
- data/doc/windows_install.rdoc +123 -0
- data/ext/rubygame/rubygame_core.so +0 -0
- data/ext/rubygame/rubygame_event.c +644 -0
- data/ext/rubygame/rubygame_event.h +48 -0
- data/ext/rubygame/rubygame_event.o +0 -0
- data/ext/rubygame/rubygame_gfx.c +942 -0
- data/ext/rubygame/rubygame_gfx.h +101 -0
- data/ext/rubygame/rubygame_gfx.o +0 -0
- data/ext/rubygame/rubygame_gfx.so +0 -0
- data/ext/rubygame/rubygame_gl.c +154 -0
- data/ext/rubygame/rubygame_gl.h +32 -0
- data/ext/rubygame/rubygame_gl.o +0 -0
- data/ext/rubygame/rubygame_image.c +252 -0
- data/ext/rubygame/rubygame_image.h +41 -0
- data/ext/rubygame/rubygame_image.o +0 -0
- data/ext/rubygame/rubygame_image.so +0 -0
- data/ext/rubygame/rubygame_joystick.c +247 -0
- data/ext/rubygame/rubygame_joystick.h +41 -0
- data/ext/rubygame/rubygame_joystick.o +0 -0
- data/ext/rubygame/rubygame_main.c +155 -0
- data/ext/rubygame/rubygame_main.h +36 -0
- data/ext/rubygame/rubygame_main.o +0 -0
- data/ext/rubygame/rubygame_mixer.c +1024 -0
- data/ext/rubygame/rubygame_mixer.h +36 -0
- data/ext/rubygame/rubygame_mixer.o +0 -0
- data/ext/rubygame/rubygame_mixer.so +0 -0
- data/ext/rubygame/rubygame_music.c +1017 -0
- data/ext/rubygame/rubygame_music.h +29 -0
- data/ext/rubygame/rubygame_music.o +0 -0
- data/ext/rubygame/rubygame_screen.c +448 -0
- data/ext/rubygame/rubygame_screen.h +43 -0
- data/ext/rubygame/rubygame_screen.o +0 -0
- data/ext/rubygame/rubygame_shared.c +272 -0
- data/ext/rubygame/rubygame_shared.h +68 -0
- data/ext/rubygame/rubygame_shared.o +0 -0
- data/ext/rubygame/rubygame_sound.c +863 -0
- data/ext/rubygame/rubygame_sound.h +29 -0
- data/ext/rubygame/rubygame_sound.o +0 -0
- data/ext/rubygame/rubygame_surface.c +1151 -0
- data/ext/rubygame/rubygame_surface.h +62 -0
- data/ext/rubygame/rubygame_surface.o +0 -0
- data/ext/rubygame/rubygame_time.c +183 -0
- data/ext/rubygame/rubygame_time.h +32 -0
- data/ext/rubygame/rubygame_time.o +0 -0
- data/ext/rubygame/rubygame_ttf.c +599 -0
- data/ext/rubygame/rubygame_ttf.h +69 -0
- data/ext/rubygame/rubygame_ttf.o +0 -0
- data/ext/rubygame/rubygame_ttf.so +0 -0
- data/lib/rubygame.rb +41 -0
- data/lib/rubygame/clock.rb +128 -0
- data/lib/rubygame/color.rb +79 -0
- data/lib/rubygame/color/models/base.rb +111 -0
- data/lib/rubygame/color/models/hsl.rb +153 -0
- data/lib/rubygame/color/models/hsv.rb +149 -0
- data/lib/rubygame/color/models/rgb.rb +78 -0
- data/lib/rubygame/color/palettes/css.rb +49 -0
- data/lib/rubygame/color/palettes/palette.rb +100 -0
- data/lib/rubygame/color/palettes/x11.rb +177 -0
- data/lib/rubygame/constants.rb +238 -0
- data/lib/rubygame/event.rb +313 -0
- data/lib/rubygame/ftor.rb +370 -0
- data/lib/rubygame/hotspot.rb +265 -0
- data/lib/rubygame/keyconstants.rb +237 -0
- data/lib/rubygame/mediabag.rb +94 -0
- data/lib/rubygame/named_resource.rb +254 -0
- data/lib/rubygame/queue.rb +288 -0
- data/lib/rubygame/rect.rb +612 -0
- data/lib/rubygame/sfont.rb +223 -0
- data/lib/rubygame/sprite.rb +511 -0
- data/samples/FreeSans.ttf +0 -0
- data/samples/GPL.txt +340 -0
- data/samples/README +40 -0
- data/samples/chimp.bmp +0 -0
- data/samples/chimp.rb +302 -0
- data/samples/demo_gl.rb +151 -0
- data/samples/demo_gl_tex.rb +197 -0
- data/samples/demo_music.rb +77 -0
- data/samples/demo_rubygame.rb +296 -0
- data/samples/demo_sfont.rb +52 -0
- data/samples/demo_ttf.rb +193 -0
- data/samples/demo_utf8.rb +53 -0
- data/samples/fist.bmp +0 -0
- data/samples/load_and_blit.rb +22 -0
- data/samples/panda.png +0 -0
- data/samples/punch.wav +0 -0
- data/samples/ruby.png +0 -0
- data/samples/song.ogg +0 -0
- data/samples/term16.png +0 -0
- data/samples/whiff.wav +0 -0
- data/test/audio_spec.rb +236 -0
- data/test/color_spec.rb +544 -0
- data/test/image.png +0 -0
- data/test/music_spec.rb +727 -0
- data/test/named_resource_spec.rb +211 -0
- data/test/short.ogg +0 -0
- data/test/sound_spec.rb +564 -0
- data/test/surface_spec.rb +219 -0
- data/test/test_crop.rb +45 -0
- data/test/test_rect.rb +841 -0
- metadata +174 -0
@@ -0,0 +1,211 @@
|
|
1
|
+
require 'rubygame/named_resource'
|
2
|
+
|
3
|
+
include Rubygame
|
4
|
+
|
5
|
+
|
6
|
+
TEST_DIR = File.dirname(__FILE__)
|
7
|
+
|
8
|
+
|
9
|
+
|
10
|
+
describe NamedResource do
|
11
|
+
|
12
|
+
|
13
|
+
describe "instance names" do
|
14
|
+
before :each do
|
15
|
+
@class = Class.new {
|
16
|
+
include NamedResource
|
17
|
+
|
18
|
+
def initialize( name=nil )
|
19
|
+
self.name = name
|
20
|
+
end
|
21
|
+
|
22
|
+
def to_s
|
23
|
+
"#<InstanceNameExample #{name}>"
|
24
|
+
end
|
25
|
+
alias :inspect :to_s
|
26
|
+
}
|
27
|
+
|
28
|
+
@resource = @class.new( "my_name" )
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should have a name" do
|
32
|
+
@resource.name.should == "my_name"
|
33
|
+
end
|
34
|
+
|
35
|
+
it "name string should be frozen" do
|
36
|
+
@resource.name.should be_frozen
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should be able to set name" do
|
40
|
+
@resource.name = "new_name"
|
41
|
+
@resource.name.should == "new_name"
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should reject non-string names" do
|
45
|
+
lambda { @resource.name = ["foo"] }.should raise_error(TypeError)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
|
50
|
+
describe "resource table" do
|
51
|
+
|
52
|
+
describe "general" do
|
53
|
+
before :each do
|
54
|
+
@class = Class.new {
|
55
|
+
include NamedResource
|
56
|
+
|
57
|
+
class << self
|
58
|
+
attr_accessor :resources
|
59
|
+
end
|
60
|
+
|
61
|
+
def to_s
|
62
|
+
"#<ResourceTableExample>"
|
63
|
+
end
|
64
|
+
alias :inspect :to_s
|
65
|
+
}
|
66
|
+
|
67
|
+
@instance = @class.new
|
68
|
+
@class.resources["foo"] = @instance
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should be able to get basename a name from a filename" do
|
72
|
+
@class.basename("/foo/bar/baz.ext").should == "baz.ext"
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should return object with registered name" do
|
76
|
+
@class["foo"].should == @instance
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should be able to register an object by name" do
|
80
|
+
@class["bar"] = @instance
|
81
|
+
@class["bar"].should == @instance
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should only allow registering instances of that class" do
|
85
|
+
lambda { @class["bar"] = 3 }.should raise_error(TypeError)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
|
90
|
+
describe "without autoload" do
|
91
|
+
before :each do
|
92
|
+
@class = Class.new {
|
93
|
+
include NamedResource
|
94
|
+
|
95
|
+
class << self
|
96
|
+
attr_accessor :resources
|
97
|
+
end
|
98
|
+
|
99
|
+
def to_s
|
100
|
+
"#<ResourceTableExample>"
|
101
|
+
end
|
102
|
+
alias :inspect :to_s
|
103
|
+
}
|
104
|
+
end
|
105
|
+
|
106
|
+
it "should return nil for unregistered names" do
|
107
|
+
@class["unassigned"].should be_nil
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
|
112
|
+
describe "with autoload" do
|
113
|
+
before :each do
|
114
|
+
@class = Class.new {
|
115
|
+
include NamedResource
|
116
|
+
|
117
|
+
class << self
|
118
|
+
attr_accessor :resources
|
119
|
+
|
120
|
+
def autoload( name )
|
121
|
+
instance = self.new
|
122
|
+
return instance
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
attr_accessor :name
|
127
|
+
|
128
|
+
def to_s
|
129
|
+
"#<ResourceTableExample>"
|
130
|
+
end
|
131
|
+
alias :inspect :to_s
|
132
|
+
}
|
133
|
+
end
|
134
|
+
|
135
|
+
it "should autoload unregistered names" do
|
136
|
+
instance = @class["bar"]
|
137
|
+
instance.name.should == "bar"
|
138
|
+
instance.should be_instance_of(@class)
|
139
|
+
end
|
140
|
+
|
141
|
+
it "should save autoloaded instances" do
|
142
|
+
@class.resources["bar"].should be_nil
|
143
|
+
instance = @class["bar"]
|
144
|
+
@class.resources["bar"].should == instance
|
145
|
+
end
|
146
|
+
|
147
|
+
it "should set the name of autoloaded instances" do
|
148
|
+
@class["bar"].name.should == "bar"
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
|
153
|
+
describe "autoload paths" do
|
154
|
+
before :each do
|
155
|
+
@class = Class.new {
|
156
|
+
include NamedResource
|
157
|
+
|
158
|
+
class << self
|
159
|
+
attr_accessor :resources
|
160
|
+
|
161
|
+
def autoload( name )
|
162
|
+
path = find_file( name )
|
163
|
+
if path
|
164
|
+
instance = self.new
|
165
|
+
instance.path = path
|
166
|
+
return instance
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
# Fake check to see if file exists
|
171
|
+
def exist?( path )
|
172
|
+
if( path == File.join("foo","bar") or
|
173
|
+
path == File.join("moo","bar") )
|
174
|
+
true
|
175
|
+
else
|
176
|
+
false
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
attr_accessor :name, :path
|
182
|
+
|
183
|
+
def to_s
|
184
|
+
"#<ResourceTableExample>"
|
185
|
+
end
|
186
|
+
alias :inspect :to_s
|
187
|
+
}
|
188
|
+
|
189
|
+
@some_dirs = [ "hoo", "woo", "foo", "moo" ]
|
190
|
+
end
|
191
|
+
|
192
|
+
it "should have an accessor for @autoload_paths" do
|
193
|
+
@class.autoload_dirs.should == []
|
194
|
+
@class.autoload_dirs.push("foo")
|
195
|
+
@class.autoload_dirs.should == ["foo"]
|
196
|
+
end
|
197
|
+
|
198
|
+
it "should use the first path which succeeds" do
|
199
|
+
@class.autoload_dirs = @some_dirs
|
200
|
+
@class["bar"].path.should == File.join("foo","bar")
|
201
|
+
end
|
202
|
+
|
203
|
+
it "should return nil if no path succeeds" do
|
204
|
+
@class.autoload_dirs = @some_dirs
|
205
|
+
@class["nothing"].should be_nil
|
206
|
+
end
|
207
|
+
|
208
|
+
end
|
209
|
+
|
210
|
+
end
|
211
|
+
end
|
data/test/short.ogg
ADDED
Binary file
|
data/test/sound_spec.rb
ADDED
@@ -0,0 +1,564 @@
|
|
1
|
+
require 'rubygame'
|
2
|
+
include Rubygame
|
3
|
+
|
4
|
+
samples_dir = File.join( File.dirname(__FILE__), "..", "samples", "")
|
5
|
+
test_dir = File.dirname(__FILE__)
|
6
|
+
|
7
|
+
song = samples_dir + "song.ogg"
|
8
|
+
short = File.join( File.dirname(__FILE__), "short.ogg")
|
9
|
+
dne = samples_dir + "does_not_exist.ogg"
|
10
|
+
panda = samples_dir + "panda.png"
|
11
|
+
|
12
|
+
|
13
|
+
|
14
|
+
#########################
|
15
|
+
## ##
|
16
|
+
## INITIALIAZING ##
|
17
|
+
## ##
|
18
|
+
#########################
|
19
|
+
|
20
|
+
|
21
|
+
describe Sound, "new" do
|
22
|
+
it "should raise NotImplementedError" do
|
23
|
+
lambda{ Sound.new }.should raise_error(NotImplementedError)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
|
28
|
+
describe Sound, "load" do
|
29
|
+
|
30
|
+
before :each do
|
31
|
+
Rubygame.open_audio
|
32
|
+
@sound = Sound.load(song)
|
33
|
+
end
|
34
|
+
|
35
|
+
after :each do
|
36
|
+
Rubygame.close_audio
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should have a volume of 1.0" do
|
40
|
+
@sound.volume.should == 1.0
|
41
|
+
end
|
42
|
+
|
43
|
+
it { @sound.should_not be_playing }
|
44
|
+
it { @sound.should_not be_paused }
|
45
|
+
it { @sound.should be_stopped }
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
describe Sound, "load without open audio" do
|
52
|
+
|
53
|
+
before :each do
|
54
|
+
@sound = Sound.load(song)
|
55
|
+
end
|
56
|
+
|
57
|
+
after :each do
|
58
|
+
Rubygame.close_audio
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should open audio" do
|
62
|
+
Rubygame.open_audio.should be_false
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should have a volume of 1.0" do
|
66
|
+
@sound.volume.should == 1.0
|
67
|
+
end
|
68
|
+
|
69
|
+
it { @sound.should_not be_playing }
|
70
|
+
it { @sound.should_not be_paused }
|
71
|
+
it { @sound.should be_stopped }
|
72
|
+
|
73
|
+
end
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
describe "loading Sound from nonexistent file" do
|
78
|
+
|
79
|
+
before :each do
|
80
|
+
Rubygame.open_audio
|
81
|
+
end
|
82
|
+
|
83
|
+
after :each do
|
84
|
+
Rubygame.close_audio
|
85
|
+
end
|
86
|
+
|
87
|
+
it "should raise SDLError" do
|
88
|
+
lambda { @sound = Sound.load(dne) }.should raise_error(SDLError)
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
describe "loading Sound from non-sound file" do
|
96
|
+
|
97
|
+
before :each do
|
98
|
+
Rubygame.open_audio
|
99
|
+
end
|
100
|
+
|
101
|
+
after :each do
|
102
|
+
Rubygame.close_audio
|
103
|
+
end
|
104
|
+
|
105
|
+
it "should raise SDLError" do
|
106
|
+
lambda { @sound = Sound.load(panda) }.should raise_error(SDLError)
|
107
|
+
end
|
108
|
+
|
109
|
+
end
|
110
|
+
|
111
|
+
|
112
|
+
describe Sound, "(named resource)" do
|
113
|
+
before :each do
|
114
|
+
Sound.autoload_dirs = [samples_dir]
|
115
|
+
end
|
116
|
+
|
117
|
+
after :each do
|
118
|
+
Sound.autoload_dirs = []
|
119
|
+
Sound.instance_eval { @resources = {} }
|
120
|
+
end
|
121
|
+
|
122
|
+
it "should include NamedResource" do
|
123
|
+
Sound.included_modules.should include(NamedResource)
|
124
|
+
end
|
125
|
+
|
126
|
+
it "should respond to :[]" do
|
127
|
+
Sound.should respond_to(:[])
|
128
|
+
end
|
129
|
+
|
130
|
+
it "should respond to :[]=" do
|
131
|
+
Sound.should respond_to(:[]=)
|
132
|
+
end
|
133
|
+
|
134
|
+
it "should allow setting resources" do
|
135
|
+
s = Sound.load(short)
|
136
|
+
Sound["short"] = s
|
137
|
+
Sound["short"].should == s
|
138
|
+
end
|
139
|
+
|
140
|
+
it "should reject non-Sound resources" do
|
141
|
+
lambda { Sound["foo"] = "bar" }.should raise_error(TypeError)
|
142
|
+
end
|
143
|
+
|
144
|
+
it "should autoload images as Sound instances" do
|
145
|
+
unless( Rubygame::VERSIONS[:sdl_mixer] )
|
146
|
+
raise "Can't test sound loading, no SDL_mixer installed."
|
147
|
+
end
|
148
|
+
|
149
|
+
Sound["whiff.wav"].should be_instance_of(Sound)
|
150
|
+
end
|
151
|
+
|
152
|
+
it "should return nil for nonexisting files" do
|
153
|
+
unless( Rubygame::VERSIONS[:sdl_mixer] )
|
154
|
+
raise "Can't test sound loading, no SDL_mixer installed."
|
155
|
+
end
|
156
|
+
|
157
|
+
Sound["foobar.wav"].should be_nil
|
158
|
+
end
|
159
|
+
|
160
|
+
it "should set names of autoload Sounds" do
|
161
|
+
unless( Rubygame::VERSIONS[:sdl_mixer] )
|
162
|
+
raise "Can't test sound loading, no SDL_mixer installed."
|
163
|
+
end
|
164
|
+
|
165
|
+
Sound["whiff.wav"].name.should == "whiff.wav"
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
|
170
|
+
#########################
|
171
|
+
## ##
|
172
|
+
## BASIC ##
|
173
|
+
## ##
|
174
|
+
#########################
|
175
|
+
|
176
|
+
|
177
|
+
describe "Sound that is playing" do
|
178
|
+
|
179
|
+
before :each do
|
180
|
+
Rubygame.open_audio
|
181
|
+
@sound = Sound.load(song)
|
182
|
+
@sound.play
|
183
|
+
end
|
184
|
+
|
185
|
+
after :each do
|
186
|
+
Rubygame.close_audio
|
187
|
+
end
|
188
|
+
|
189
|
+
it { @sound.should be_playing }
|
190
|
+
it { @sound.should_not be_paused }
|
191
|
+
it { @sound.should_not be_stopped }
|
192
|
+
|
193
|
+
it "should be playing after being played again" do
|
194
|
+
@sound.play
|
195
|
+
@sound.should be_playing
|
196
|
+
end
|
197
|
+
|
198
|
+
it "should be paused after being paused" do
|
199
|
+
@sound.pause
|
200
|
+
@sound.should be_paused
|
201
|
+
end
|
202
|
+
|
203
|
+
it "should be stopped after being stopped" do
|
204
|
+
@sound.stop
|
205
|
+
@sound.should be_stopped
|
206
|
+
end
|
207
|
+
|
208
|
+
it "should be able to change volume" do
|
209
|
+
@sound.volume = 0.5
|
210
|
+
@sound.volume.should == 0.5
|
211
|
+
end
|
212
|
+
|
213
|
+
end
|
214
|
+
|
215
|
+
|
216
|
+
describe Sound, "played without open audio" do
|
217
|
+
|
218
|
+
before :each do
|
219
|
+
@sound = Sound.load(song)
|
220
|
+
Rubygame.close_audio
|
221
|
+
@sound.play
|
222
|
+
end
|
223
|
+
|
224
|
+
after :each do
|
225
|
+
Rubygame.close_audio
|
226
|
+
end
|
227
|
+
|
228
|
+
it "should open audio" do
|
229
|
+
Rubygame.open_audio.should be_false
|
230
|
+
end
|
231
|
+
|
232
|
+
it "should be playing" do
|
233
|
+
@sound.should be_playing
|
234
|
+
end
|
235
|
+
|
236
|
+
end
|
237
|
+
|
238
|
+
|
239
|
+
describe "Sound that is paused" do
|
240
|
+
|
241
|
+
before :each do
|
242
|
+
Rubygame.open_audio
|
243
|
+
@sound = Sound.load(song)
|
244
|
+
@sound.play
|
245
|
+
@sound.pause
|
246
|
+
end
|
247
|
+
|
248
|
+
after :each do
|
249
|
+
Rubygame.close_audio
|
250
|
+
end
|
251
|
+
|
252
|
+
it { @sound.should_not be_playing }
|
253
|
+
it { @sound.should be_paused }
|
254
|
+
it { @sound.should_not be_stopped }
|
255
|
+
|
256
|
+
it "should be playing after being played" do
|
257
|
+
@sound.play
|
258
|
+
@sound.should be_playing
|
259
|
+
end
|
260
|
+
|
261
|
+
it "should be playing after being unpaused" do
|
262
|
+
@sound.unpause
|
263
|
+
@sound.should be_playing
|
264
|
+
end
|
265
|
+
|
266
|
+
it "should still be paused after being paused again" do
|
267
|
+
@sound.pause
|
268
|
+
@sound.should be_paused
|
269
|
+
end
|
270
|
+
|
271
|
+
it "should be stopped after being stopped" do
|
272
|
+
@sound.stop
|
273
|
+
@sound.should be_stopped
|
274
|
+
end
|
275
|
+
|
276
|
+
it "should be able to change volume" do
|
277
|
+
@sound.volume = 0.5
|
278
|
+
@sound.volume.should == 0.5
|
279
|
+
end
|
280
|
+
|
281
|
+
end
|
282
|
+
|
283
|
+
|
284
|
+
|
285
|
+
describe "Sound that is stopped" do
|
286
|
+
|
287
|
+
before :each do
|
288
|
+
Rubygame.open_audio
|
289
|
+
@sound = Sound.load(song)
|
290
|
+
@sound.play
|
291
|
+
@sound.stop
|
292
|
+
end
|
293
|
+
|
294
|
+
after :each do
|
295
|
+
Rubygame.close_audio
|
296
|
+
end
|
297
|
+
|
298
|
+
it { @sound.should_not be_playing }
|
299
|
+
it { @sound.should_not be_paused }
|
300
|
+
it { @sound.should be_stopped }
|
301
|
+
|
302
|
+
it "should not be paused after being paused" do
|
303
|
+
@sound.pause
|
304
|
+
@sound.should_not be_paused
|
305
|
+
end
|
306
|
+
|
307
|
+
it "should be stopped after being stopped" do
|
308
|
+
@sound.stop
|
309
|
+
@sound.should be_stopped
|
310
|
+
end
|
311
|
+
|
312
|
+
it "should be playing after being played" do
|
313
|
+
@sound.play
|
314
|
+
@sound.should be_playing
|
315
|
+
end
|
316
|
+
|
317
|
+
it "should be able to change volume" do
|
318
|
+
@sound.volume = 0.5
|
319
|
+
@sound.volume.should == 0.5
|
320
|
+
end
|
321
|
+
|
322
|
+
end
|
323
|
+
|
324
|
+
|
325
|
+
|
326
|
+
#########################
|
327
|
+
## ##
|
328
|
+
## AUTO-STOPPING ##
|
329
|
+
## ##
|
330
|
+
#########################
|
331
|
+
|
332
|
+
|
333
|
+
describe "Sound set to stop after 0.2 seconds" do
|
334
|
+
|
335
|
+
before :each do
|
336
|
+
Rubygame.open_audio
|
337
|
+
@sound = Sound.load(song)
|
338
|
+
@sound.volume = 0.01 # for programmer sanity
|
339
|
+
@sound.play( :stop_after => 0.2 )
|
340
|
+
end
|
341
|
+
|
342
|
+
after :each do
|
343
|
+
Rubygame.close_audio
|
344
|
+
end
|
345
|
+
|
346
|
+
it "should still be playing at 0.15 seconds" do
|
347
|
+
sleep 0.15
|
348
|
+
@sound.should be_playing
|
349
|
+
end
|
350
|
+
|
351
|
+
it "should be stopped at 0.25 seconds" do
|
352
|
+
sleep 0.25
|
353
|
+
@sound.should be_stopped
|
354
|
+
end
|
355
|
+
|
356
|
+
end
|
357
|
+
|
358
|
+
|
359
|
+
|
360
|
+
describe "Sound that is short" do
|
361
|
+
|
362
|
+
before :each do
|
363
|
+
Rubygame.open_audio
|
364
|
+
@sound = Sound.load(short)
|
365
|
+
@sound.volume = 0.01 # for programmer sanity
|
366
|
+
@sound.play
|
367
|
+
end
|
368
|
+
|
369
|
+
after :each do
|
370
|
+
Rubygame.close_audio
|
371
|
+
end
|
372
|
+
|
373
|
+
it "should be stopped after it has expired" do
|
374
|
+
sleep 0.15
|
375
|
+
@sound.should be_stopped
|
376
|
+
end
|
377
|
+
|
378
|
+
end
|
379
|
+
|
380
|
+
|
381
|
+
|
382
|
+
describe "Sound that repeats forever but stops after 0.3 seconds" do
|
383
|
+
|
384
|
+
before :each do
|
385
|
+
Rubygame.open_audio
|
386
|
+
@sound = Sound.load(short)
|
387
|
+
@sound.volume = 0.01 # for programmer sanity
|
388
|
+
@sound.play( :repeats => -1, :stop_after => 0.3 )
|
389
|
+
end
|
390
|
+
|
391
|
+
after :each do
|
392
|
+
Rubygame.close_audio
|
393
|
+
end
|
394
|
+
|
395
|
+
it "should still be playing at 0.25 second" do
|
396
|
+
sleep 0.25
|
397
|
+
@sound.should be_playing
|
398
|
+
end
|
399
|
+
|
400
|
+
it "should be stopped at 0.35 second" do
|
401
|
+
sleep 0.35
|
402
|
+
@sound.should be_stopped
|
403
|
+
end
|
404
|
+
|
405
|
+
end
|
406
|
+
|
407
|
+
|
408
|
+
|
409
|
+
#########################
|
410
|
+
## ##
|
411
|
+
## REPEATING ##
|
412
|
+
## ##
|
413
|
+
#########################
|
414
|
+
|
415
|
+
|
416
|
+
describe "Sound that repeats forever" do
|
417
|
+
|
418
|
+
before :each do
|
419
|
+
Rubygame.open_audio
|
420
|
+
@sound = Sound.load(short)
|
421
|
+
@sound.volume = 0.01 # for programmer sanity
|
422
|
+
@sound.play( :repeats => -1 )
|
423
|
+
end
|
424
|
+
|
425
|
+
after :each do
|
426
|
+
Rubygame.close_audio
|
427
|
+
end
|
428
|
+
|
429
|
+
it "should still be playing at 0.3 seconds" do
|
430
|
+
sleep 0.3
|
431
|
+
@sound.should be_playing
|
432
|
+
end
|
433
|
+
|
434
|
+
end
|
435
|
+
|
436
|
+
|
437
|
+
|
438
|
+
describe "Sound that repeats 3 times" do
|
439
|
+
|
440
|
+
before :each do
|
441
|
+
Rubygame.open_audio
|
442
|
+
@sound = Sound.load(short)
|
443
|
+
@sound.volume = 0.01 # for programmer sanity
|
444
|
+
@sound.play( :repeats => 3 )
|
445
|
+
end
|
446
|
+
|
447
|
+
after :each do
|
448
|
+
Rubygame.close_audio
|
449
|
+
end
|
450
|
+
|
451
|
+
it "should still be playing after 3 plays" do
|
452
|
+
sleep 0.1*3
|
453
|
+
@sound.should be_playing
|
454
|
+
end
|
455
|
+
|
456
|
+
it "should be stopped after 4 plays" do
|
457
|
+
sleep 0.1*4 + 0.05
|
458
|
+
@sound.should be_stopped
|
459
|
+
end
|
460
|
+
|
461
|
+
end
|
462
|
+
|
463
|
+
|
464
|
+
|
465
|
+
#########################
|
466
|
+
## ##
|
467
|
+
## FADING ##
|
468
|
+
## ##
|
469
|
+
#########################
|
470
|
+
|
471
|
+
|
472
|
+
describe "Sound that fades in for 0.2 seconds" do
|
473
|
+
|
474
|
+
before :each do
|
475
|
+
Rubygame.open_audio
|
476
|
+
@sound = Sound.load(short)
|
477
|
+
@sound.volume = 0.01 # for programmer sanity
|
478
|
+
@sound.play( :repeats => -1, :fade_in => 0.2 )
|
479
|
+
end
|
480
|
+
|
481
|
+
after :each do
|
482
|
+
Rubygame.close_audio
|
483
|
+
end
|
484
|
+
|
485
|
+
it "should be playing right away" do
|
486
|
+
@sound.should be_playing
|
487
|
+
end
|
488
|
+
|
489
|
+
it "should be fading in right away" do
|
490
|
+
@sound.should be_fading
|
491
|
+
@sound.fading?(:in).should be_true
|
492
|
+
end
|
493
|
+
|
494
|
+
it "should still be fading in after 0.15 seconds" do
|
495
|
+
sleep 0.15
|
496
|
+
@sound.should be_fading
|
497
|
+
@sound.fading?(:in).should be_true
|
498
|
+
end
|
499
|
+
|
500
|
+
it "should not be fading in after 0.25 seconds" do
|
501
|
+
sleep 0.25
|
502
|
+
@sound.should_not be_fading
|
503
|
+
@sound.fading?(:in).should be_false
|
504
|
+
end
|
505
|
+
|
506
|
+
it "should still be playing after it has faded in" do
|
507
|
+
sleep 0.25
|
508
|
+
@sound.should be_playing
|
509
|
+
end
|
510
|
+
|
511
|
+
it "should not allow changing volume" do
|
512
|
+
lambda { @sound.volume = 0.5 }.should raise_error(SDLError)
|
513
|
+
@sound.volume.should_not == 0.5
|
514
|
+
end
|
515
|
+
|
516
|
+
end
|
517
|
+
|
518
|
+
|
519
|
+
describe "Sound that fades out for 0.2 seconds" do
|
520
|
+
|
521
|
+
before :each do
|
522
|
+
Rubygame.open_audio
|
523
|
+
@sound = Sound.load(short)
|
524
|
+
@sound.volume = 0.01 # for programmer sanity
|
525
|
+
@sound.play( :repeats => -1 )
|
526
|
+
@sound.fade_out( 0.2 )
|
527
|
+
end
|
528
|
+
|
529
|
+
after :each do
|
530
|
+
Rubygame.close_audio
|
531
|
+
end
|
532
|
+
|
533
|
+
it "should be playing right away" do
|
534
|
+
@sound.should be_playing
|
535
|
+
end
|
536
|
+
|
537
|
+
it "should be fading out right away" do
|
538
|
+
@sound.should be_fading
|
539
|
+
@sound.fading?(:out).should be_true
|
540
|
+
end
|
541
|
+
|
542
|
+
it "should still be fading out after 0.25 seconds" do
|
543
|
+
sleep 0.15
|
544
|
+
@sound.should be_fading
|
545
|
+
@sound.fading?(:out).should be_true
|
546
|
+
end
|
547
|
+
|
548
|
+
it "should not be fading out after 0.35 seconds" do
|
549
|
+
sleep 0.25
|
550
|
+
@sound.should_not be_fading
|
551
|
+
@sound.fading?(:out).should be_false
|
552
|
+
end
|
553
|
+
|
554
|
+
it "should be stopped after it has faded out" do
|
555
|
+
sleep 0.25
|
556
|
+
@sound.should be_stopped
|
557
|
+
end
|
558
|
+
|
559
|
+
it "should not allow changing volume" do
|
560
|
+
lambda { @sound.volume = 0.5 }.should raise_error(SDLError)
|
561
|
+
@sound.volume.should_not == 0.5
|
562
|
+
end
|
563
|
+
|
564
|
+
end
|