dxruby_sdl 0.0.4 → 0.0.5

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.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZjEyN2ViYzcxYTFiMGVjNTJhOTU2MDg3M2Q1YjMxNDExOWE1NGQ5Yw==
4
+ Mzg1MmJhMGFhODU4MmYzZmY5M2QyOTdjYWJiMGJmNWI0ZTA3MmZmMg==
5
5
  data.tar.gz: !binary |-
6
- YTg5ZGE1YTUxYWUzNzFlOGVkYTk5MTFkN2MwNTVhMDZkZGQ2ZmI1ZQ==
6
+ ZmUwNmU2ZjgwZWY1NTIyMmRjMzBhNDg2MzY0OGU5NDBiNDhkZjhlZA==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- NDExY2Q5MzA3YWUyZGY4Y2U0YmJjZTBiNTE1ZGZjNGE2ZGY1NDE2ZTFkNDM3
10
- Yjg5ZDRhZGMxMDQ2YTRlYTVjYzM0NDY3NTVkMzJjYWFjYzZjNWI2NmU5OWQ0
11
- YzRiYjg1NmM3YjhjNDVjMmQ1M2FhYmViZGZmOGVmMjI2M2E4ZWI=
9
+ YzFhNGIyM2E0Y2MxMmE3N2RhYTE0NmY4MzhkYzg2NTAzOTY1MTg5Yzc3NmNl
10
+ MDAyMzJkOGI3ZTFhNjgwNzVmZWUzNDI4NTU5Y2VkNjYwNTgyOWU0NDNmYzE2
11
+ NTliNWY0NDhmY2MxMDE0MTQzNjI0MTA2OGQ4YWJiNWRlNGJmOWM=
12
12
  data.tar.gz: !binary |-
13
- OTc1ZGZhZWJmY2QzZTkxMzkzZmFmZWY1MGU4YmRmMGI0MTAxOGI3YmM5ODZk
14
- NWNjNTY3MWFjNWMxNDE0ODU1NzQ4ZWEzYTVkZmEyNTI3ZGVhMTVhMzUyZTI5
15
- ZTAxNDJkYmQyZjUxNmY2MGUwYWVlMzI1ODVkZjg0NDFiYWIwY2U=
13
+ OTllMjA5YzFjZGM3M2JiZGZjYjA5Y2JjNGUzMjY3NzY4OGE2ZDVjNTVlMmEz
14
+ YWMyMDI5ZDU3MDRiYTM5NDFhZWM2N2MxNzg1ZGJiMzY5M2U3NjQ0YzI5YTQ0
15
+ YWMxNDVjYmIxMDgwODZmMTJhMGY0NTVlNWMzN2UwYjM1ZjZlNzI=
data/.rubocop.yml CHANGED
@@ -1,3 +1,7 @@
1
+ AllCops:
2
+ Excludes:
3
+ - tmp/**
4
+
1
5
  MethodLength:
2
6
  Enabled: false
3
7
 
@@ -22,3 +26,8 @@ RedundantReturn:
22
26
  AsciiComments:
23
27
  Enabled: false
24
28
 
29
+ CaseEquality:
30
+ Enabled: false
31
+
32
+ SymbolName:
33
+ Enabled: false
data/.travis.yml CHANGED
@@ -8,4 +8,5 @@ env:
8
8
 
9
9
  before_install:
10
10
  - sudo apt-get update -qq
11
- - sudo apt-get install -qq libsdl1.2-dev libsdl-mixer1.2-dev timidity libsdl-ttf2.0-dev libsdl-sge-dev otf-ipafont-gothic
11
+ - sudo apt-get install -qq libsdl1.2-dev libsdl-image1.2-dev libsdl-mixer1.2-dev timidity libsdl-ttf2.0-dev libsdl-sge-dev fonts-horai-umefont fonts-ipafont
12
+
data/Guardfile CHANGED
@@ -10,7 +10,7 @@ if /darwin/ =~ RUBY_PLATFORM
10
10
  end
11
11
  guard :rspec, rspec_option do
12
12
  watch(%r{^spec/.+_spec\.rb$})
13
- watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
13
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
14
14
  watch('spec/spec_helper.rb') { "spec" }
15
15
  watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
16
16
  end
data/README.md CHANGED
@@ -1,5 +1,6 @@
1
1
  # dxruby_sdl
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/dxruby_sdl.png)](http://badge.fury.io/rb/dxruby_sdl)
3
4
  [![Build Status](https://travis-ci.org/takaokouji/dxruby_sdl.png?branch=master)](https://travis-ci.org/takaokouji/dxruby_sdl)
4
5
  [![Coverage Status](https://coveralls.io/repos/takaokouji/dxruby_sdl/badge.png?branch=master)](https://coveralls.io/r/takaokouji/dxruby_sdl?branch=master)
5
6
  [![Dependency Status](https://gemnasium.com/takaokouji/dxruby_sdl.png)](https://gemnasium.com/takaokouji/dxruby_sdl)
@@ -8,41 +9,64 @@
8
9
  `dxruby_sdl` is a ruby library for 2D graphics and game. It has same
9
10
  DXRuby API. It use SDL/Ruby.
10
11
 
12
+ Current API compatibility status: http://dxruby-apis.herokuapp.com/en/
13
+
11
14
  ## Installation
12
15
 
13
- ### SDL & SGE
16
+ ### SDL, SGE, etc...
17
+
18
+ #### Mac OS X
19
+
20
+ (1) SDL
21
+
22
+ ```
23
+ (if you use MacPorts.)
24
+ $ sudo port install libsdl libsdl_image libsdl_mixer libsdl_sound libsdl_ttf
25
+ ```
26
+
27
+ (2) SGE
14
28
 
15
- #### Mac OS X with MacPorts
29
+ ```
30
+ $ curl -O http://www.digitalfanatics.org/cal/sge/files/sge030809.tar.gz
31
+ $ tar xvzf sge030809.tar.gz
32
+ $ cd sge030809
33
+ $ curl https://gist.github.com/steved555/963525/raw/7b638e4100f9dd1a9d00560b98ea2ddd4375b2b0/sge_030809_freetype.patch | patch
34
+ $ curl https://gist.github.com/steved555/963524/raw/c03396e1fb8bb87e9f4ba92597d087f730c6c48b/sge_030809_cmap.patch | patch
35
+ $ curl https://gist.github.com/steved555/963522/raw/5b277a0a6b08a1c077fbe2c96eead4ef1d761856/sge-030809-build.patch | patch
36
+ $ sed -i -e 's/-soname/-install_name/g' Makefile
37
+ $ make
38
+ $ sudo make install
39
+ ```
16
40
 
17
- SDL
41
+ (3) MS PGohic (DXRuby's default font)
18
42
 
19
- sudo port install libsdl libsdl_image libsdl_mixer libsdl_sound libsdl_ttf
43
+ Install Microsoft Office:mac from http://www.microsoft.com/japan/mac.
20
44
 
21
- SGE
45
+ #### Linux
22
46
 
23
- curl -O http://www.digitalfanatics.org/cal/sge/files/sge030809.tar.gz
24
- tar xvzf sge030809.tar.gz
25
- cd sge030809
26
- curl https://gist.github.com/steved555/963525/raw/7b638e4100f9dd1a9d00560b98ea2ddd4375b2b0/sge_030809_freetype.patch | patch
27
- curl https://gist.github.com/steved555/963524/raw/c03396e1fb8bb87e9f4ba92597d087f730c6c48b/sge_030809_cmap.patch | patch
28
- curl https://gist.github.com/steved555/963522/raw/5b277a0a6b08a1c077fbe2c96eead4ef1d761856/sge-030809-build.patch | patch
29
- sed -i -e 's/-soname/-install_name/g' Makefile
30
- make
31
- sudo make install
47
+ ```
48
+ $ sudo apt-get install libsdl1.2-dev libsdl-image1.2-dev libsdl-mixer1.2-dev timidity libsdl-ttf2.0-dev libsdl-sge-dev fonts-horai-umefont fonts-ipafont
49
+ ```
32
50
 
33
51
  ### dxruby_sdl
34
52
 
35
53
  Add this line to your application's Gemfile:
36
54
 
37
- gem 'dxruby_sdl'
55
+ ```
56
+ gem 'dxruby_sdl'
57
+ ```
38
58
 
39
59
  And then execute:
40
60
 
41
- $ bundle
61
+ ```
62
+ $ bundle
63
+ ```
42
64
 
43
65
  Or install it yourself as:
44
66
 
45
- $ gem install dxruby_sdl
67
+ ```
68
+ $ gem install dxruby_sdl
69
+ ```
46
70
 
47
71
  ## Usage
48
72
 
@@ -8,7 +8,7 @@ module DXRubySDL
8
8
  if color.length == 4
9
9
  return color[0..2]
10
10
  else
11
- color
11
+ return color
12
12
  end
13
13
  end
14
14
 
@@ -16,7 +16,7 @@ module DXRubySDL
16
16
  if color.length == 4
17
17
  return color[3]
18
18
  else
19
- return 255
19
+ return nil
20
20
  end
21
21
  end
22
22
  end
@@ -5,33 +5,154 @@ module DXRubySDL
5
5
  attr_reader :size
6
6
  attr_reader :_ttf
7
7
 
8
+ @font_cache = {}
9
+
8
10
  def initialize(size, fontname = '', hash = {})
9
11
  @size = size
10
12
 
11
13
  if !SDL::TTF.init?
12
14
  SDL::TTF.init
13
15
  end
14
- if !(path = FONTS[fontname.downcase])
16
+ if !(path = (FONTS[fontname] || FONT_ALIASES[fontname]))
15
17
  path = FONTS.first.last
16
18
  end
17
- @_ttf = SDL::TTF.open(path, size)
19
+ font_cache = Font.instance_variable_get('@font_cache')
20
+ args = [path, size]
21
+ if font_cache.key?(args)
22
+ @_ttf = font_cache[args]
23
+ else
24
+ @_ttf = font_cache[args] = SDL::TTF.open(*args)
25
+ end
18
26
  end
19
27
 
28
+ def get_width(string)
29
+ return @_ttf.text_size(string).first
30
+ end
31
+
32
+ alias_method :getWidth, :get_width
33
+
20
34
  private
21
35
 
36
+ FONTS = {}
37
+ private_constant :FONTS
38
+
39
+ FONT_ALIASES = {}
40
+ private_constant :FONT_ALIASES
41
+
22
42
  # :nocov:
23
43
  if /darwin/ =~ RUBY_PLATFORM
24
- FONTS = {
25
- 'osaka' => '/Library/Fonts/osaka.ttf',
26
- 'IPA ゴシック' => '/Library/Fonts/ipag.ttf',
27
- 'IPA Pゴシック' => '/Library/Fonts/ipagp.ttf',
28
- }
44
+ font_info =
45
+ [
46
+ %w[
47
+ MS\ Pゴシック
48
+ /Library/Fonts/Microsoft/MS\ PGothic.ttf
49
+ MS\ Pゴシック
50
+ MS\ PGothic
51
+ ],
52
+ %w[
53
+ MS\ ゴシック
54
+ /Library/Fonts/Microsoft/MS\ Gothic.ttf
55
+ MS\ ゴシック
56
+ MS\ Gothic
57
+ ],
58
+ %w[
59
+ MS\ P明朝
60
+ /Library/Fonts/Microsoft/MS\ PMincho.ttf
61
+ MS\ P明朝
62
+ MS\ PMincho
63
+ ],
64
+ %w[
65
+ MS\ 明朝
66
+ /Library/Fonts/Microsoft/MS\ Mincho.ttf
67
+ MS\ 明朝
68
+ MS\ Mincho
69
+ ],
70
+ %w[
71
+ osaka
72
+ /Library/Fonts/osaka.ttf
73
+ ],
74
+ %w[
75
+ IPA\ Pゴシック
76
+ /Library/Fonts/ipagp.ttf
77
+ IPA\ PGothic
78
+ ipagp
79
+ ],
80
+ %w[
81
+ IPA\ ゴシック
82
+ /Library/Fonts/ipag.ttf
83
+ IPA\ Gothic
84
+ ipag
85
+ ],
86
+ ]
29
87
  elsif /linux/ =~ RUBY_PLATFORM
30
- FONTS = {
31
- 'IPA ゴシック' => '/usr/share/fonts/opentype/ipafont-gothic/ipag.ttf',
32
- 'IPA Pゴシック' => '/usr/share/fonts/opentype/ipafont-gothic/ipagp.ttf',
33
- }
88
+ font_info =
89
+ [
90
+ %w[
91
+ 梅Pゴシック
92
+ /usr/share/fonts/truetype/horai-umefont/ume-pgo4.ttf
93
+ ume-pgo4
94
+ MS\ Pゴシック
95
+ MS\ Pゴシック
96
+ MS\ PGothic
97
+ ],
98
+ %w[
99
+ 梅ゴシック
100
+ /usr/share/fonts/truetype/horai-umefont/ume-tgo4.ttf
101
+ ume-tgo4
102
+ MS\ ゴシック
103
+ MS\ ゴシック
104
+ MS\ Gothic
105
+ ],
106
+ %w[
107
+ 梅P明朝
108
+ /usr/share/fonts/truetype/horai-umefont/ume-pmo3.ttf
109
+ ume-pmo3
110
+ MS\ P明朝
111
+ MS\ P明朝
112
+ MS\ PMincho
113
+ ],
114
+ %w[
115
+ 梅明朝
116
+ /usr/share/fonts/truetype/horai-umefont/ume-tmo3.ttf
117
+ ume-tmo3
118
+ MS\ 明朝
119
+ MS\ 明朝
120
+ MS\ Mincho
121
+ ],
122
+ %w[
123
+ IPA\ Pゴシック
124
+ /usr/share/fonts/opentype/ipafont-gothic/ipagp.ttf
125
+ IPA\ PGothic
126
+ ipagp
127
+ ],
128
+ %w[
129
+ IPA\ ゴシック
130
+ /usr/share/fonts/opentype/ipafont-gothic/ipag.ttf
131
+ IPA\ Gothic
132
+ ipag
133
+ ],
134
+ %w[
135
+ IPA\ P明朝
136
+ /usr/share/fonts/opentype/ipafont-mincho/ipamp.ttf
137
+ IPA\ PMincho
138
+ ipamp
139
+ ],
140
+ %w[
141
+ IPA\ 明朝
142
+ /usr/share/fonts/opentype/ipafont-mincho/ipam.ttf
143
+ IPA\ Mincho
144
+ ipam
145
+ ],
146
+ ]
34
147
  end
35
148
  # :nocov:
149
+ font_info.each do |name, path, *aliases|
150
+ if File.exist?(path)
151
+ FONTS[name] = path
152
+ aliases.each do |a|
153
+ FONT_ALIASES[a] = path
154
+ end
155
+ end
156
+ end
36
157
  end
37
158
  end
@@ -31,6 +31,7 @@ module DXRubySDL
31
31
 
32
32
  def initialize(width, height, color = [0, 0, 0, 0])
33
33
  @color = color
34
+ @_surface_is_dirty = false
34
35
 
35
36
  if width == 0 && height == 0
36
37
  return
@@ -39,6 +40,14 @@ module DXRubySDL
39
40
  @_surface =
40
41
  SDL::Surface.new(SDL::SWSURFACE, width, height, Window.send(:screen))
41
42
  @_surface.fill_rect(0, 0, width, height, @color)
43
+ @_surface_is_dirty = true
44
+ end
45
+
46
+ def _surface_display_format_alpha
47
+ if @_surface_is_dirty
48
+ @_surface = @_surface.display_format_alpha
49
+ @_surface_is_dirty = false
50
+ end
42
51
  end
43
52
 
44
53
  def width
@@ -49,6 +58,16 @@ module DXRubySDL
49
58
  return @_surface.h
50
59
  end
51
60
 
61
+ def set_color_key(color)
62
+ @_surface.set_color_key(SDL::SRCCOLORKEY | SDL::RLEACCEL, color)
63
+ @_surface_is_dirty = true
64
+ end
65
+
66
+ def compare(x, y, color)
67
+ pixel = lock { @_surface.get_pixel(x, y) }
68
+ return @_surface.format.get_rgb(pixel) == color
69
+ end
70
+
52
71
  def slice(x, y, width, height)
53
72
  s = @_surface.copy_rect(x, y, width, height)
54
73
  image = Image.new(0, 0)
@@ -61,6 +80,7 @@ module DXRubySDL
61
80
  @_surface.draw_line(x1, y1, x2, y2,
62
81
  to_sdl_color(color), true, to_sdl_alpha(color))
63
82
  end
83
+ @_surface_is_dirty = true
64
84
  return self
65
85
  end
66
86
 
@@ -69,6 +89,7 @@ module DXRubySDL
69
89
  @_surface.draw_circle(x, y, r, to_sdl_color(color), false, true,
70
90
  to_sdl_alpha(color))
71
91
  end
92
+ @_surface_is_dirty = true
72
93
  return self
73
94
  end
74
95
 
@@ -77,6 +98,7 @@ module DXRubySDL
77
98
  @_surface.draw_circle(x, y, r, to_sdl_color(color), true, false,
78
99
  to_sdl_alpha(color))
79
100
  end
101
+ @_surface_is_dirty = true
80
102
  return self
81
103
  end
82
104
 
@@ -89,6 +111,7 @@ module DXRubySDL
89
111
  @_surface.draw_rect(x, y, w, h, to_sdl_color(color), false,
90
112
  to_sdl_alpha(color))
91
113
  end
114
+ @_surface_is_dirty = true
92
115
  return self
93
116
  end
94
117
 
@@ -101,18 +124,41 @@ module DXRubySDL
101
124
  @_surface.draw_rect(x, y, w, h, to_sdl_color(color), true,
102
125
  to_sdl_alpha(color))
103
126
  end
127
+ @_surface_is_dirty = true
128
+ return self
129
+ end
130
+
131
+ def clear
132
+ @_surface.fill_rect(0, 0, width, height, @color)
133
+ @_surface_is_dirty = true
134
+ end
135
+
136
+ def draw_font(x, y, string, font, color = [255, 255, 255])
137
+ if string.empty?
138
+ return
139
+ end
140
+ r, g, b = *color
141
+ h = font._ttf.height + 1
142
+ string.lines.each.with_index do |line, i|
143
+ line.chomp!
144
+ if line.empty?
145
+ next
146
+ end
147
+ font._ttf.draw_blended_utf8(@_surface, line, x, y + i * h, r, g, b)
148
+ end
149
+ @_surface_is_dirty = true
104
150
  return self
105
151
  end
106
152
 
107
- # rubocop:disable SymbolName
108
153
  class << self
109
154
  alias_method :loadTiles, :load_tiles
110
155
  alias_method :load_to_array, :load_tiles
111
156
  alias_method :loadToArray, :load_to_array
112
157
  end
158
+ alias_method :setColorKey, :set_color_key
113
159
  alias_method :circleFill, :circle_fill
114
160
  alias_method :boxFill, :box_fill
115
- # rubocop:enable SymbolName
161
+ alias_method :drawFont, :draw_font
116
162
 
117
163
  private
118
164
 
@@ -122,7 +168,7 @@ module DXRubySDL
122
168
  else
123
169
  begin
124
170
  @_surface.lock
125
- yield
171
+ return yield
126
172
  ensure
127
173
  @_surface.unlock
128
174
  end
@@ -1,5 +1,7 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
+ require 'set'
4
+
3
5
  module DXRubySDL
4
6
  module Input
5
7
  module_function
@@ -98,7 +100,10 @@ module DXRubySDL
98
100
  return SDL::Mouse.state[index] && !@last_mouse_state[index]
99
101
  end
100
102
 
101
- # rubocop:disable SymbolName
103
+ def keys
104
+ return @keys
105
+ end
106
+
102
107
  class << self
103
108
  alias_method :setRepeat, :set_repeat
104
109
  alias_method :padDown?, :pad_down?
@@ -110,12 +115,12 @@ module DXRubySDL
110
115
  alias_method :mouseDown?, :mouse_down?
111
116
  alias_method :mousePush?, :mouse_push?
112
117
  end
113
- # rubocop:enable SymbolName
114
118
 
115
119
  private
116
120
 
117
- @current_key_state = Set.new
118
- @last_key_state = Set.new
121
+ @keys = Set.new
122
+ @checked_keys = Set.new
123
+ @down_keys = Set.new
119
124
  @last_mouse_state = [false, false, false]
120
125
  @joysticks = []
121
126
 
@@ -123,7 +128,7 @@ module DXRubySDL
123
128
 
124
129
  private
125
130
 
126
- KEY_TABLE = {}
131
+ SDL_KEY_TABLE = {}
127
132
  replace_table = {
128
133
  'BACK' => 'BACKSPACE',
129
134
  'ADD' => 'PLUS',
@@ -156,40 +161,35 @@ module DXRubySDL
156
161
  end
157
162
  end
158
163
  begin
159
- KEY_TABLE[DXRubySDL.const_get(k)] = SDL::Key.const_get(name.to_sym)
164
+ SDL_KEY_TABLE[DXRubySDL.const_get(k)] =
165
+ SDL::Key.const_get(name.to_sym)
160
166
  rescue NameError
161
167
  end
162
168
  end
163
- private_constant :KEY_TABLE
169
+ private_constant :SDL_KEY_TABLE
170
+
171
+ DXRUBY_KEY_TABLE = SDL_KEY_TABLE.invert
172
+ private_constant :DXRUBY_KEY_TABLE
164
173
 
165
174
  def store_last_state
166
- keys = (@last_key_state - @current_key_state)
167
- if keys.length > 0
168
- SDL::Key.scan
169
- keys.each do |key|
170
- if SDL::Key.press?(key)
171
- @current_key_state.add(key)
172
- end
173
- end
174
- end
175
- @last_key_state = @current_key_state
176
- @current_key_state = Set.new
175
+ @down_keys.merge(@checked_keys)
176
+ @checked_keys.clear
177
177
  @last_mouse_state = SDL::Mouse.state
178
178
  end
179
179
 
180
180
  def sdl_key_press?(key)
181
- SDL::Key.scan
182
- if SDL::Key.press?(key)
183
- @current_key_state.add(key)
181
+ dkey = to_dxruby_key(key)
182
+ if @keys.include?(dkey)
183
+ @checked_keys.add(dkey)
184
184
  return true
185
185
  else
186
- @current_key_state.delete(key)
187
186
  return false
188
187
  end
189
188
  end
190
189
 
191
190
  def sdl_key_push?(key)
192
- return sdl_key_press?(key) && !@last_key_state.include?(key)
191
+ dkey = to_dxruby_key(key)
192
+ return sdl_key_press?(key) && !@down_keys.include?(dkey)
193
193
  end
194
194
 
195
195
  def joystick(pad_number)
@@ -203,7 +203,23 @@ module DXRubySDL
203
203
  end
204
204
 
205
205
  def to_sdl_key(key_code)
206
- return KEY_TABLE[key_code]
206
+ return SDL_KEY_TABLE[key_code]
207
+ end
208
+
209
+ def to_dxruby_key(key_code)
210
+ return DXRUBY_KEY_TABLE[key_code]
211
+ end
212
+
213
+ def handle_key_event(event)
214
+ dkey = to_dxruby_key(event.sym)
215
+ case event
216
+ when SDL::Event::KeyDown
217
+ @keys.add(dkey)
218
+ when SDL::Event::KeyUp
219
+ @keys.delete(dkey)
220
+ @checked_keys.delete(dkey)
221
+ @down_keys.delete(dkey)
222
+ end
207
223
  end
208
224
  end
209
225
  end
@@ -1,7 +1,11 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
+ require 'forwardable'
4
+
3
5
  module DXRubySDL
4
6
  class Sound
7
+ extend Forwardable
8
+
5
9
  @sdl_mixer_openend = false
6
10
 
7
11
  def initialize(filename)
@@ -17,9 +21,9 @@ module DXRubySDL
17
21
  end
18
22
  end
19
23
 
20
- def play
21
- @sound.play
22
- end
24
+ def_delegators :@sound, :play, :set_volume
25
+
26
+ alias_method :setVolume, :set_volume
23
27
 
24
28
  private
25
29
 
@@ -31,10 +35,16 @@ module DXRubySDL
31
35
  def play
32
36
  SDL::Mixer.play_music(@music, -1)
33
37
  end
38
+
39
+ def set_volume(volume, time = 0)
40
+ raise NotImplementedError, 'Sound#set_volume(volume, time) with MIDI'
41
+ end
34
42
  end
35
43
  private_constant :Music
36
44
 
37
45
  class Wave
46
+ extend Forwardable
47
+
38
48
  def initialize(filename)
39
49
  @wave = SDL::Mixer::Wave.load(filename)
40
50
  @last_played_channel = nil
@@ -48,6 +58,13 @@ module DXRubySDL
48
58
  retry
49
59
  end
50
60
  end
61
+
62
+ def set_volume(volume, time = 0)
63
+ if time > 0
64
+ raise NotImplementedError, 'Sound#set_volume(volume, time != 0)'
65
+ end
66
+ @wave.set_volume(volume)
67
+ end
51
68
  end
52
69
  private_constant :Wave
53
70
  end
@@ -3,9 +3,13 @@
3
3
  module DXRubySDL
4
4
  class SoundEffect
5
5
  def initialize(time, wavetype = WAVE_RECT, resolution = 1000)
6
+ @time = time
7
+
8
+ @time.times { yield }
6
9
  end
7
10
 
8
11
  def add(wavetype = WAVE_RECT, resolution = 1000)
12
+ @time.times { yield }
9
13
  end
10
14
 
11
15
  def play