smalruby 0.1.10-x86-mingw32 → 0.1.11-x86-mingw32

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,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4de81755881df577b8df42c9c1a48f4dc2a873e2
4
- data.tar.gz: 4bae43f78318894db8b44a763de404aa41f5bf64
3
+ metadata.gz: 92e5998bc53ec3da2c3feeaf5bfeca7d7b624159
4
+ data.tar.gz: 4ca3ba06b85379c063c16f9bb79aa0c247fc6409
5
5
  SHA512:
6
- metadata.gz: 97c03a1720b43af95f0fa00b75de5f258768e262da85c878b8b5639fbd0a4a0f6b36a1372c703a5f574083f766d75529f32520ff9f23986a6676795dd23506d4
7
- data.tar.gz: 6a5ef2b469e2a8bd7ec772941648fd6bffdd24ce98ca6a2cb37ec3d23938932d5f723748e9dbe9b64a7e77e57682bcd96e4e0a3f737183dc0743c14b2fa3a643
6
+ metadata.gz: ee5dfdfa2b482dfecb2e11ba6528e331d9c8c836e95d99de938469fc550610dcf43ccc88663615451b56d1167ef211463c68fe1405c3a475dbf7b6875aca1bb9
7
+ data.tar.gz: 443025a3c48212026f047c7bf20f54377bdf5c86bc6484081867444b3d0103363ec3a63a48e4aa9c4d299207c0542b45db9a87c093c903657dca9fb7a6341687
data/.rubocop.yml CHANGED
@@ -27,7 +27,7 @@ Metrics/ClassLength:
27
27
  Max: 1000
28
28
 
29
29
  Metrics/CyclomaticComplexity:
30
- Max: 8
30
+ Max: 10
31
31
 
32
32
  # Configuration parameters: AllowURI, URISchemes.
33
33
  Metrics/LineLength:
@@ -39,12 +39,12 @@ Metrics/MethodLength:
39
39
 
40
40
  # Configuration parameters: CountComments.
41
41
  Metrics/ModuleLength:
42
- Max: 170
42
+ Max: 500
43
43
 
44
44
  Metrics/PerceivedComplexity:
45
- Max: 8
45
+ Max: 15
46
46
 
47
- Performance/ParallelAssignment:
47
+ Style/ParallelAssignment:
48
48
  Enabled: false
49
49
 
50
50
  Style/AccessorMethodName:
@@ -98,8 +98,10 @@ Style/StringLiterals:
98
98
  Style/SymbolProc:
99
99
  Enabled: false
100
100
 
101
- # Configuration parameters: EnforcedStyleForMultiline, SupportedStyles.
102
- Style/TrailingComma:
101
+ Style/TrailingCommaInLiteral:
102
+ Enabled: false
103
+
104
+ Style/TrailingCommaInArguments:
103
105
  Enabled: false
104
106
 
105
107
  Style/UnneededPercentQ:
@@ -107,3 +109,50 @@ Style/UnneededPercentQ:
107
109
 
108
110
  Style/NegatedIf:
109
111
  Enabled: false
112
+
113
+ Performance/RedundantMatch:
114
+ Enabled: false
115
+
116
+ Style/ExtraSpacing:
117
+ Exclude:
118
+ - 'smalruby.gemspec'
119
+
120
+ Style/SpaceAroundOperators:
121
+ Exclude:
122
+ - 'smalruby.gemspec'
123
+
124
+ Style/MutableConstant:
125
+ Enabled: false
126
+
127
+ Style/ConditionalAssignment:
128
+ Enabled: false
129
+
130
+ Style/ZeroLengthPredicate:
131
+ Enabled: false
132
+
133
+ Style/SignalException:
134
+ Enabled: false
135
+
136
+ Style/MultilineMethodCallIndentation:
137
+ Enabled: false
138
+
139
+ Style/Alias:
140
+ Enabled: false
141
+
142
+ Lint/UselessAccessModifier:
143
+ Enabled: false
144
+
145
+ Style/SpaceInsideStringInterpolation:
146
+ Enabled: false
147
+
148
+ Style/NumericPredicate:
149
+ Enabled: false
150
+
151
+ Style/EmptyMethod:
152
+ Enabled: false
153
+
154
+ Style/MethodMissing:
155
+ Enabled: false
156
+
157
+ Metrics/BlockLength:
158
+ Max: 35
data/.travis.yml CHANGED
@@ -1,7 +1,7 @@
1
1
  language: ruby
2
2
 
3
3
  rvm:
4
- - 2.1.5
4
+ - 2.3.3
5
5
 
6
6
  env:
7
7
  AUDIODEV=null
@@ -9,3 +9,4 @@ env:
9
9
  before_install:
10
10
  - sudo apt-get update -qq
11
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
+ - gem update bundler
data/README.md CHANGED
@@ -6,6 +6,13 @@
6
6
  smalruby is a 2D game development library. This is part of "Smalruby"
7
7
  project that is a learning ruby programming environment for kids.
8
8
 
9
+ ## Requirement
10
+
11
+ * Windows or UNIX like OS (MAC OS X, Linux, etc...)
12
+ * Ruby 2.0.0-p353 or higher
13
+ * dxruby_sdl (for Mac OS X and Linux): https://github.com/smalruby/dxruby_sdl
14
+ * rsdl (for Mac OS X): http://www.kumaryu.net/proj/ruby-rsdl/
15
+
9
16
  ## Installation
10
17
 
11
18
  Add this line to your application's Gemfile:
data/lib/smalruby.rb CHANGED
@@ -99,7 +99,7 @@ module Smalruby
99
99
  attach_thread_input =
100
100
  Win32API.new('user32', 'AttachThreadInput', %w(i i i), 'v')
101
101
  attach_thread_input.call(this_thread_id, active_thread_id, 1)
102
- Win32API.new('user32', 'SetForegroundWindow', %w(i), 'i')
102
+ Win32API.new('user32', 'BringWindowToTop', %w(i), 'i')
103
103
  .call(Window.hWnd)
104
104
  attach_thread_input.call(this_thread_id, active_thread_id, 0)
105
105
 
@@ -27,6 +27,7 @@ module Smalruby
27
27
  attr_reader :rotation_style
28
28
  attr_reader :enable_pen
29
29
  attr_accessor :pen_color
30
+ attr_accessor :volume
30
31
 
31
32
  def initialize(option = {})
32
33
  defaults = {
@@ -61,6 +62,7 @@ module Smalruby
61
62
  @angle = 0 unless Util.windows?
62
63
  @enable_pen = false
63
64
  @pen_color = 'black'
65
+ @volume = 100
64
66
 
65
67
  self.scale_x = 1.0
66
68
  self.scale_y = 1.0
@@ -205,17 +207,17 @@ module Smalruby
205
207
  @vector[:y] = Math.sin(radian)
206
208
 
207
209
  if @rotation_style == :free
208
- self.scale_x = 1
210
+ self.scale_x = scale_x.abs
209
211
  super(val)
210
212
  elsif @rotation_style == :left_right
211
213
  if @vector[:x] >= 0
212
- self.scale_x = 1
214
+ self.scale_x = scale_x.abs
213
215
  else
214
- self.scale_x = -1
216
+ self.scale_x = scale_x.abs * -1
215
217
  end
216
218
  super(0)
217
219
  else
218
- self.scale_x = 1
220
+ self.scale_x = scale_x.abs
219
221
  super(0)
220
222
  end
221
223
  end
@@ -365,13 +367,20 @@ module Smalruby
365
367
  }
366
368
  opt = process_optional_arguments(option, defaults)
367
369
 
368
- new_sound(opt[:name]).play
370
+ sound = new_sound(opt[:name])
371
+ sound.set_volume(calc_volume)
372
+ sound.play
369
373
  end
370
374
 
371
375
  # @!endgroup
372
376
 
373
377
  # @!group ペン
374
378
 
379
+ # Clears all pen marks from the Stage
380
+ def clear
381
+ world.current_stage.clear
382
+ end
383
+
375
384
  # ペンを下ろす
376
385
  def down_pen
377
386
  @enable_pen = true
@@ -382,8 +391,37 @@ module Smalruby
382
391
  @enable_pen = false
383
392
  end
384
393
 
385
- # @!method pen_color=(val)
386
- # ペンの色を( )にする
394
+ # set pen color
395
+ #
396
+ # @param [Array<Integer>|Symbol|Integer] val color
397
+ # When color is Array<Integer>, it means [R, G, B].
398
+ # When color is Symbol, it means the color code; like :white, :black, etc...
399
+ # When color is Integer, it means hue.
400
+ def pen_color=(val)
401
+ if val.is_a?(Numeric)
402
+ val %= 201
403
+ _, s, l = Color.rgb_to_hsl(*pen_color)
404
+ val = Color.hsl_to_rgb(val, s, l)
405
+ end
406
+ @pen_color = val
407
+ end
408
+
409
+ # change pen color
410
+ #
411
+ # @param [Integer] val color
412
+ def change_pen_color_by(val)
413
+ h, s, l = Color.rgb_to_hsl(*pen_color)
414
+ @pen_color = Color.hsl_to_rgb(h + val, s, l)
415
+ end
416
+
417
+ # set pen shade
418
+ #
419
+ # @param Integer val shade
420
+ def pen_shade=(val)
421
+ val %= 101
422
+ h, s, = *Color.rgb_to_hsl(*pen_color)
423
+ @pen_color = Color.hsl_to_rgb(h, s, val)
424
+ end
387
425
 
388
426
  # @!endgroup
389
427
 
@@ -617,5 +655,11 @@ module Smalruby
617
655
  $stderr.puts("#{exception.class}: #{exception.message}")
618
656
  $stderr.puts(" #{exception.backtrace.join("\n ")}")
619
657
  end
658
+
659
+ private
660
+
661
+ def calc_volume
662
+ (255 * @volume / 100.0).to_i
663
+ end
620
664
  end
621
665
  end
@@ -148,6 +148,9 @@ module Smalruby
148
148
  'mediumslateblue' => [0x7b, 0x68, 0xee]
149
149
  }
150
150
 
151
+ # 3 = R, G, B, 2 = Up, Down
152
+ HUE_PER_6 = 200.0 / (3.0 * 2.0)
153
+
151
154
  # 色名の配列
152
155
  NAMES = NAME_TO_CODE.keys
153
156
 
@@ -168,5 +171,102 @@ module Smalruby
168
171
  color
169
172
  end
170
173
  end
174
+
175
+ # Convert RGB Color model to HSL Color model
176
+ #
177
+ # @param [Integer] red
178
+ # @param [Integer] green
179
+ # @param [Integer] blue
180
+ # @return [Array] hue, saturation, lightness
181
+ # hue in the range [0,200],
182
+ # saturation and lightness in the range [0, 100]
183
+ def rgb_to_hsl(red, green, blue)
184
+ red = round_rgb_color(red)
185
+ green = round_rgb_color(green)
186
+ blue = round_rgb_color(blue)
187
+
188
+ color_max = [red, green, blue].max
189
+ color_min = [red, green, blue].min
190
+ color_range = color_max - color_min
191
+ if color_range == 0
192
+ return [0, 0, (color_max * 100.0 / 255).to_i]
193
+ end
194
+ color_range = color_range.to_f
195
+ hue = (case color_max
196
+ when red then
197
+ HUE_PER_6 * ((green - blue) / color_range)
198
+ when green then
199
+ HUE_PER_6 * ((blue - red) / color_range) + HUE_PER_6 * 2
200
+ else
201
+ HUE_PER_6 * ((red - green) / color_range) + HUE_PER_6 * 4
202
+ end)
203
+
204
+ cnt = color_range / 2.0
205
+ if cnt <= 127
206
+ saturation = color_range / (color_max + color_min) * 100
207
+ else
208
+ saturation = color_range / (510 - color_max - color_min) * 100
209
+ end
210
+ lightness = (color_max + color_min) / 2.0 / 255.0 * 100
211
+
212
+ [hue.round, saturation.round, lightness.round]
213
+ end
214
+
215
+ # Round rgb color 0 to 255
216
+ #
217
+ # @param [Integer] value RGB color
218
+ # @return [Integer] rounded RGB color
219
+ def round_rgb_color(value)
220
+ if value > 255
221
+ 255
222
+ elsif value < 0
223
+ 0
224
+ else
225
+ value
226
+ end
227
+ end
228
+
229
+ # Convert HSV Color model to RGB Color model
230
+ #
231
+ # @param [Integer] h
232
+ # @param [Integer] s
233
+ # @param [Integer] l
234
+ # @return [Array] red,green,blue color
235
+ # red,green,blue in the range [0,255]
236
+ def hsl_to_rgb(h, s, l)
237
+ h %= 201
238
+ s %= 101
239
+ l %= 101
240
+ if l <= 49
241
+ color_max = 255.0 * (l + l * (s / 100.0)) / 100.0
242
+ color_min = 255.0 * (l - l * (s / 100.0)) / 100.0
243
+ else
244
+ color_max = 255.0 * (l + (100 - l) * (s / 100.0)) / 100.0
245
+ color_min = 255.0 * (l - (100 - l) * (s / 100.0)) / 100.0
246
+ end
247
+
248
+ if h < HUE_PER_6
249
+ base = h
250
+ elsif h < HUE_PER_6 * 3
251
+ base = (h - HUE_PER_6 * 2).abs
252
+ elsif h < HUE_PER_6 * 5
253
+ base = (h - HUE_PER_6 * 4).abs
254
+ else
255
+ base = (200 - h)
256
+ end
257
+ base = base / HUE_PER_6 * (color_max - color_min) + color_min
258
+
259
+ divide = (h / HUE_PER_6).to_i
260
+ red, green, blue = (case divide
261
+ when 0 then [color_max, base, color_min]
262
+ when 1 then [base, color_max, color_min]
263
+ when 2 then [color_min, color_max, base]
264
+ when 3 then [color_min, base, color_max]
265
+ when 4 then [base, color_min, color_max]
266
+ else [color_max, color_min, base]
267
+ end)
268
+
269
+ [red.round, green.round, blue.round]
270
+ end
171
271
  end
172
272
  end
@@ -11,12 +11,19 @@ module Smalruby
11
11
 
12
12
  super(opts.reject { |k, _| defaults.keys.include?(k) })
13
13
 
14
+ @background_color = opts[:color]
15
+
14
16
  # HACK: ステージを一番最初に描画する
15
17
  World.instance.objects.delete(self)
16
18
  World.instance.objects.unshift(self)
17
19
  World.instance.current_stage = self
18
20
 
19
- fill(color: opts[:color])
21
+ clear
22
+ end
23
+
24
+ # clear with background color or image
25
+ def clear
26
+ fill(color: @background_color)
20
27
  end
21
28
  end
22
29
  end
@@ -1,5 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
3
  module Smalruby
4
- VERSION = '0.1.10'
4
+ VERSION = '0.1.11'
5
5
  end
data/smalruby.gemspec CHANGED
@@ -25,7 +25,7 @@ Gem::Specification.new do |spec|
25
25
  spec.require_paths = ['lib']
26
26
 
27
27
  spec.add_development_dependency 'bundler', '~> 1.3'
28
- spec.add_development_dependency 'rake'
28
+ spec.add_development_dependency 'rake', '~> 10.4'
29
29
  spec.add_development_dependency 'yard'
30
30
  spec.add_development_dependency 'redcarpet'
31
31
  spec.add_development_dependency 'rspec'
@@ -40,7 +40,7 @@ Gem::Specification.new do |spec|
40
40
  if is_windows
41
41
  spec.add_runtime_dependency 'dxruby', '~> 1.4.0'
42
42
  else
43
- spec.add_runtime_dependency 'dxruby_sdl', '~> 0.0.13'
43
+ spec.add_runtime_dependency 'dxruby_sdl', '~> 0.0.14'
44
44
  end
45
45
  spec.add_runtime_dependency 'smalrubot', '~> 0.0.6'
46
46
  end
@@ -149,7 +149,7 @@ describe Smalruby::Color do
149
149
  }
150
150
 
151
151
  name_to_code.each do |name, code|
152
- context '引数が #{ name.inspect } の場合' do
152
+ context "引数が #{ name.inspect } の場合" do
153
153
  let(:color_name) { name }
154
154
 
155
155
  it { should eq(code) }
data/spec/spec_helper.rb CHANGED
@@ -12,7 +12,6 @@ Dir.glob(File.expand_path('../support/**/*.rb', __FILE__)).each do |path|
12
12
  end
13
13
 
14
14
  RSpec.configure do |config|
15
- config.treat_symbols_as_metadata_keys_with_true_values = true
16
15
  config.run_all_when_everything_filtered = true
17
16
  config.filter_run :focus
18
17
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smalruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.10
4
+ version: 0.1.11
5
5
  platform: x86-mingw32
6
6
  authors:
7
7
  - Kouji Takao
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-29 00:00:00.000000000 Z
11
+ date: 2017-01-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -28,16 +28,16 @@ dependencies:
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: '10.4'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: '10.4'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: yard
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -330,7 +330,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
330
330
  version: '0'
331
331
  requirements: []
332
332
  rubyforge_project:
333
- rubygems_version: 2.2.2
333
+ rubygems_version: 2.5.2
334
334
  signing_key:
335
335
  specification_version: 4
336
336
  summary: 2D game development library for kids.