smalruby 0.0.18-x86-mingw32 → 0.0.19-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.
Potentially problematic release.
This version of smalruby might be problematic. Click here for more details.
- checksums.yaml +4 -4
 - data/lib/smalruby/character.rb +88 -15
 - data/lib/smalruby/version.rb +1 -1
 - data/samples/car.rb +15 -2
 - metadata +1 -1
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 886f9154c9a5d9f06fdf961ce49576345c285066
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: fd1558575d25653e853d8d119ba0281c5d015bb6
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 07bfb6aa3a83624501d2c389f6199cb0f23c5cd8030ccb2343c73581031e49b1f2fe84fbb5ef136438dfa566fe8daf8602b9624d4c4901d0888c5f5dd8041f03
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: e13781695595a0bc7f0ba2d48feab15e4abdabbae73c0d64763226b6805a01b3dfc57e9ca8e228344a1acd9a27b58ca9fe6bb3806d887a7b680d91de99e34627
         
     | 
    
        data/lib/smalruby/character.rb
    CHANGED
    
    | 
         @@ -11,6 +11,10 @@ module Smalruby 
     | 
|
| 
       11 
11 
     | 
    
         
             
                self.font_cache = {}
         
     | 
| 
       12 
12 
     | 
    
         
             
                font_cache.extend(Mutex_m)
         
     | 
| 
       13 
13 
     | 
    
         | 
| 
      
 14 
     | 
    
         
            +
                cattr_accessor :sound_cache
         
     | 
| 
      
 15 
     | 
    
         
            +
                self.sound_cache = {}
         
     | 
| 
      
 16 
     | 
    
         
            +
                sound_cache.extend(Mutex_m)
         
     | 
| 
      
 17 
     | 
    
         
            +
             
     | 
| 
       14 
18 
     | 
    
         
             
                cattr_accessor :hardware_cache
         
     | 
| 
       15 
19 
     | 
    
         
             
                self.hardware_cache = {}
         
     | 
| 
       16 
20 
     | 
    
         
             
                hardware_cache.extend(Mutex_m)
         
     | 
| 
         @@ -19,6 +23,7 @@ module Smalruby 
     | 
|
| 
       19 
23 
     | 
    
         
             
                attr_accessor :threads
         
     | 
| 
       20 
24 
     | 
    
         
             
                attr_accessor :checking_hit_targets
         
     | 
| 
       21 
25 
     | 
    
         
             
                attr_accessor :angle unless Util.windows?
         
     | 
| 
      
 26 
     | 
    
         
            +
                attr_reader :rotation_style
         
     | 
| 
       22 
27 
     | 
    
         | 
| 
       23 
28 
     | 
    
         
             
                def initialize(option = {})
         
     | 
| 
       24 
29 
     | 
    
         
             
                  defaults = {
         
     | 
| 
         @@ -40,6 +45,7 @@ module Smalruby 
     | 
|
| 
       40 
45 
     | 
    
         
             
                  @threads = []
         
     | 
| 
       41 
46 
     | 
    
         
             
                  @checking_hit_targets = []
         
     | 
| 
       42 
47 
     | 
    
         
             
                  @angle = 0 unless Util.windows?
         
     | 
| 
      
 48 
     | 
    
         
            +
                  @rotation_style = :free
         
     | 
| 
       43 
49 
     | 
    
         | 
| 
       44 
50 
     | 
    
         
             
                  self.scale_x = 1.0
         
     | 
| 
       45 
51 
     | 
    
         
             
                  self.scale_y = 1.0
         
     | 
| 
         @@ -55,6 +61,12 @@ module Smalruby 
     | 
|
| 
       55 
61 
     | 
    
         
             
                    rotate(opt[:angle])
         
     | 
| 
       56 
62 
     | 
    
         
             
                  end
         
     | 
| 
       57 
63 
     | 
    
         | 
| 
      
 64 
     | 
    
         
            +
                  # HACK: Windows XP SP3の環境でワーカースレッドで音声を読み込めな
         
     | 
| 
      
 65 
     | 
    
         
            +
                  # い不具合が発生した。このためメインスレッドでプリロードしておく。
         
     | 
| 
      
 66 
     | 
    
         
            +
                  %w(do re mi fa so ra si do_2).each do |n|
         
     | 
| 
      
 67 
     | 
    
         
            +
                    new_sound("piano_#{n}.wav")
         
     | 
| 
      
 68 
     | 
    
         
            +
                  end
         
     | 
| 
      
 69 
     | 
    
         
            +
             
     | 
| 
       58 
70 
     | 
    
         
             
                  World.instance.objects << self
         
     | 
| 
       59 
71 
     | 
    
         
             
                end
         
     | 
| 
       60 
72 
     | 
    
         | 
| 
         @@ -71,16 +83,32 @@ module Smalruby 
     | 
|
| 
       71 
83 
     | 
    
         
             
                  move(-val)
         
     | 
| 
       72 
84 
     | 
    
         
             
                end
         
     | 
| 
       73 
85 
     | 
    
         | 
| 
       74 
     | 
    
         
            -
                #  
     | 
| 
      
 86 
     | 
    
         
            +
                # くるっと振り返る
         
     | 
| 
       75 
87 
     | 
    
         
             
                def turn
         
     | 
| 
       76 
     | 
    
         
            -
                  @vector[:x]  
     | 
| 
       77 
     | 
    
         
            -
             
     | 
| 
       78 
     | 
    
         
            -
             
     | 
| 
      
 88 
     | 
    
         
            +
                  sync_angle(@vector[:x] * -1, @vector[:y] * -1)
         
     | 
| 
      
 89 
     | 
    
         
            +
                end
         
     | 
| 
      
 90 
     | 
    
         
            +
             
     | 
| 
      
 91 
     | 
    
         
            +
                # 横に振り返る
         
     | 
| 
      
 92 
     | 
    
         
            +
                def turn_x
         
     | 
| 
      
 93 
     | 
    
         
            +
                  sync_angle(@vector[:x] * -1, @vector[:y])
         
     | 
| 
      
 94 
     | 
    
         
            +
                end
         
     | 
| 
      
 95 
     | 
    
         
            +
             
     | 
| 
      
 96 
     | 
    
         
            +
                # 縦に振り返る
         
     | 
| 
      
 97 
     | 
    
         
            +
                def turn_y
         
     | 
| 
      
 98 
     | 
    
         
            +
                  sync_angle(@vector[:x], @vector[:y] * -1)
         
     | 
| 
       79 
99 
     | 
    
         
             
                end
         
     | 
| 
       80 
100 
     | 
    
         | 
| 
       81 
101 
     | 
    
         
             
                # もし端に着いたら、跳ね返る
         
     | 
| 
       82 
102 
     | 
    
         
             
                def turn_if_reach_wall
         
     | 
| 
       83 
     | 
    
         
            -
                   
     | 
| 
      
 103 
     | 
    
         
            +
                  lr = reach_left_or_right_wall?
         
     | 
| 
      
 104 
     | 
    
         
            +
                  tb = reach_top_or_bottom_wall?
         
     | 
| 
      
 105 
     | 
    
         
            +
                  if lr && tb
         
     | 
| 
      
 106 
     | 
    
         
            +
                    turn
         
     | 
| 
      
 107 
     | 
    
         
            +
                  elsif lr
         
     | 
| 
      
 108 
     | 
    
         
            +
                    turn_x
         
     | 
| 
      
 109 
     | 
    
         
            +
                  elsif tb
         
     | 
| 
      
 110 
     | 
    
         
            +
                    turn_y
         
     | 
| 
      
 111 
     | 
    
         
            +
                  end
         
     | 
| 
       84 
112 
     | 
    
         
             
                end
         
     | 
| 
       85 
113 
     | 
    
         | 
| 
       86 
114 
     | 
    
         
             
                # (  )度回転する
         
     | 
| 
         @@ -88,13 +116,38 @@ module Smalruby 
     | 
|
| 
       88 
116 
     | 
    
         
             
                  self.angle += angle
         
     | 
| 
       89 
117 
     | 
    
         
             
                end
         
     | 
| 
       90 
118 
     | 
    
         | 
| 
      
 119 
     | 
    
         
            +
                def rotation_style=(val)
         
     | 
| 
      
 120 
     | 
    
         
            +
                  @rotation_style = val
         
     | 
| 
      
 121 
     | 
    
         
            +
                  sync_angle(@vector[:x], @vector[:y])
         
     | 
| 
      
 122 
     | 
    
         
            +
                end
         
     | 
| 
      
 123 
     | 
    
         
            +
             
     | 
| 
      
 124 
     | 
    
         
            +
                # 角度
         
     | 
| 
      
 125 
     | 
    
         
            +
                def angle
         
     | 
| 
      
 126 
     | 
    
         
            +
                  return super if @rotation_style == :free
         
     | 
| 
      
 127 
     | 
    
         
            +
             
     | 
| 
      
 128 
     | 
    
         
            +
                  x, y = @vector[:x], @vector[:y]
         
     | 
| 
      
 129 
     | 
    
         
            +
                  a = Math.acos(x / Math.sqrt(x**2 + y**2)) * 180 / Math::PI
         
     | 
| 
      
 130 
     | 
    
         
            +
                  a = 360 - a if y < 0
         
     | 
| 
      
 131 
     | 
    
         
            +
                  a
         
     | 
| 
      
 132 
     | 
    
         
            +
                end
         
     | 
| 
      
 133 
     | 
    
         
            +
             
     | 
| 
       91 
134 
     | 
    
         
             
                # ( )度に向ける
         
     | 
| 
       92 
135 
     | 
    
         
             
                def angle=(val)
         
     | 
| 
       93 
136 
     | 
    
         
             
                  val %= 360
         
     | 
| 
       94 
137 
     | 
    
         
             
                  radian = val * Math::PI / 180
         
     | 
| 
       95 
     | 
    
         
            -
                  @vector[:x] =  
     | 
| 
       96 
     | 
    
         
            -
                  @vector[:y] =  
     | 
| 
       97 
     | 
    
         
            -
             
     | 
| 
      
 138 
     | 
    
         
            +
                  @vector[:x] = Math.cos(radian)
         
     | 
| 
      
 139 
     | 
    
         
            +
                  @vector[:y] = Math.sin(radian)
         
     | 
| 
      
 140 
     | 
    
         
            +
             
     | 
| 
      
 141 
     | 
    
         
            +
                  if @rotation_style == :free
         
     | 
| 
      
 142 
     | 
    
         
            +
                    self.scale_x = 1
         
     | 
| 
      
 143 
     | 
    
         
            +
                    super(val)
         
     | 
| 
      
 144 
     | 
    
         
            +
                  elsif @rotation_style == :left_right
         
     | 
| 
      
 145 
     | 
    
         
            +
                    if @vector[:x] >= 0
         
     | 
| 
      
 146 
     | 
    
         
            +
                      self.scale_x = 1
         
     | 
| 
      
 147 
     | 
    
         
            +
                    else
         
     | 
| 
      
 148 
     | 
    
         
            +
                      self.scale_x = -1
         
     | 
| 
      
 149 
     | 
    
         
            +
                    end
         
     | 
| 
      
 150 
     | 
    
         
            +
                  end
         
     | 
| 
       98 
151 
     | 
    
         
             
                end
         
     | 
| 
       99 
152 
     | 
    
         | 
| 
       100 
153 
     | 
    
         
             
                # (  )に向ける
         
     | 
| 
         @@ -166,10 +219,19 @@ module Smalruby 
     | 
|
| 
       166 
219 
     | 
    
         
             
                            (self.y + center_y - y).abs**2).to_i
         
     | 
| 
       167 
220 
     | 
    
         
             
                end
         
     | 
| 
       168 
221 
     | 
    
         | 
| 
       169 
     | 
    
         
            -
                #  
     | 
| 
      
 222 
     | 
    
         
            +
                # 端に着いた?
         
     | 
| 
       170 
223 
     | 
    
         
             
                def reach_wall?
         
     | 
| 
       171 
     | 
    
         
            -
                   
     | 
| 
       172 
     | 
    
         
            -
             
     | 
| 
      
 224 
     | 
    
         
            +
                  reach_left_or_right_wall? || reach_top_or_bottom_wall?
         
     | 
| 
      
 225 
     | 
    
         
            +
                end
         
     | 
| 
      
 226 
     | 
    
         
            +
             
     | 
| 
      
 227 
     | 
    
         
            +
                # 左右の端に着いた?
         
     | 
| 
      
 228 
     | 
    
         
            +
                def reach_left_or_right_wall?
         
     | 
| 
      
 229 
     | 
    
         
            +
                  self.x < 0 || self.x >= (Window.width - image.width)
         
     | 
| 
      
 230 
     | 
    
         
            +
                end
         
     | 
| 
      
 231 
     | 
    
         
            +
             
     | 
| 
      
 232 
     | 
    
         
            +
                # 上下の端に着いた?
         
     | 
| 
      
 233 
     | 
    
         
            +
                def reach_top_or_bottom_wall?
         
     | 
| 
      
 234 
     | 
    
         
            +
                  self.y < 0 || self.y >= (Window.height - image.height)
         
     | 
| 
       173 
235 
     | 
    
         
             
                end
         
     | 
| 
       174 
236 
     | 
    
         | 
| 
       175 
237 
     | 
    
         
             
                def hit?(other)
         
     | 
| 
         @@ -186,9 +248,7 @@ module Smalruby 
     | 
|
| 
       186 
248 
     | 
    
         
             
                  }
         
     | 
| 
       187 
249 
     | 
    
         
             
                  opt = process_optional_arguments(option, defaults)
         
     | 
| 
       188 
250 
     | 
    
         | 
| 
       189 
     | 
    
         
            -
                   
     | 
| 
       190 
     | 
    
         
            -
                  (@sound_cache[opt[:name]] ||= Sound.new(asset_path(opt[:name])))
         
     | 
| 
       191 
     | 
    
         
            -
                    .play
         
     | 
| 
      
 251 
     | 
    
         
            +
                  new_sound(opt[:name]).play
         
     | 
| 
       192 
252 
     | 
    
         
             
                end
         
     | 
| 
       193 
253 
     | 
    
         | 
| 
       194 
254 
     | 
    
         
             
                # @!endgroup
         
     | 
| 
         @@ -365,6 +425,12 @@ module Smalruby 
     | 
|
| 
       365 
425 
     | 
    
         | 
| 
       366 
426 
     | 
    
         
             
                private
         
     | 
| 
       367 
427 
     | 
    
         | 
| 
      
 428 
     | 
    
         
            +
                def sync_angle(x, y)
         
     | 
| 
      
 429 
     | 
    
         
            +
                  a = Math.acos(x / Math.sqrt(x**2 + y**2)) * 180 / Math::PI
         
     | 
| 
      
 430 
     | 
    
         
            +
                  a = 360 - a if y < 0
         
     | 
| 
      
 431 
     | 
    
         
            +
                  self.angle = a
         
     | 
| 
      
 432 
     | 
    
         
            +
                end
         
     | 
| 
      
 433 
     | 
    
         
            +
             
     | 
| 
       368 
434 
     | 
    
         
             
                def asset_path(name)
         
     | 
| 
       369 
435 
     | 
    
         
             
                  program_path = Pathname($PROGRAM_NAME).expand_path(Dir.pwd)
         
     | 
| 
       370 
436 
     | 
    
         
             
                  paths = [Pathname("../#{name}").expand_path(program_path),
         
     | 
| 
         @@ -376,7 +442,14 @@ module Smalruby 
     | 
|
| 
       376 
442 
     | 
    
         
             
                  self.class.font_cache.synchronize do
         
     | 
| 
       377 
443 
     | 
    
         
             
                    self.class.font_cache[size] ||= Font.new(size)
         
     | 
| 
       378 
444 
     | 
    
         
             
                  end
         
     | 
| 
       379 
     | 
    
         
            -
                   
     | 
| 
      
 445 
     | 
    
         
            +
                  self.class.font_cache[size]
         
     | 
| 
      
 446 
     | 
    
         
            +
                end
         
     | 
| 
      
 447 
     | 
    
         
            +
             
     | 
| 
      
 448 
     | 
    
         
            +
                def new_sound(name)
         
     | 
| 
      
 449 
     | 
    
         
            +
                  self.class.sound_cache.synchronize do
         
     | 
| 
      
 450 
     | 
    
         
            +
                    self.class.sound_cache[name] ||= Sound.new(asset_path(name))
         
     | 
| 
      
 451 
     | 
    
         
            +
                  end
         
     | 
| 
      
 452 
     | 
    
         
            +
                  self.class.sound_cache[name]
         
     | 
| 
       380 
453 
     | 
    
         
             
                end
         
     | 
| 
       381 
454 
     | 
    
         | 
| 
       382 
455 
     | 
    
         
             
                def draw_balloon
         
     | 
    
        data/lib/smalruby/version.rb
    CHANGED
    
    
    
        data/samples/car.rb
    CHANGED
    
    | 
         @@ -2,14 +2,27 @@ 
     | 
|
| 
       2 
2 
     | 
    
         
             
            require 'smalruby'
         
     | 
| 
       3 
3 
     | 
    
         | 
| 
       4 
4 
     | 
    
         
             
            car1 = Character.new(x: 0, y: 0, costume: 'car1.png')
         
     | 
| 
      
 5 
     | 
    
         
            +
            car1.rotation_style = :free
         
     | 
| 
       5 
6 
     | 
    
         | 
| 
       6 
7 
     | 
    
         
             
            car1.on(:start) do
         
     | 
| 
       7 
8 
     | 
    
         
             
              loop do
         
     | 
| 
       8 
     | 
    
         
            -
                move( 
     | 
| 
      
 9 
     | 
    
         
            +
                move(15)
         
     | 
| 
       9 
10 
     | 
    
         
             
                turn_if_reach_wall
         
     | 
| 
       10 
11 
     | 
    
         
             
              end
         
     | 
| 
       11 
12 
     | 
    
         
             
            end
         
     | 
| 
       12 
13 
     | 
    
         | 
| 
       13 
14 
     | 
    
         
             
            car1.on(:click) do
         
     | 
| 
       14 
     | 
    
         
            -
              rotate( 
     | 
| 
      
 15 
     | 
    
         
            +
              rotate(15)
         
     | 
| 
      
 16 
     | 
    
         
            +
            end
         
     | 
| 
      
 17 
     | 
    
         
            +
             
     | 
| 
      
 18 
     | 
    
         
            +
            car1.on(:key_push, K_1) do
         
     | 
| 
      
 19 
     | 
    
         
            +
              self.rotation_style = :free
         
     | 
| 
      
 20 
     | 
    
         
            +
            end
         
     | 
| 
      
 21 
     | 
    
         
            +
             
     | 
| 
      
 22 
     | 
    
         
            +
            car1.on(:key_push, K_2) do
         
     | 
| 
      
 23 
     | 
    
         
            +
              self.rotation_style = :left_right
         
     | 
| 
      
 24 
     | 
    
         
            +
            end
         
     | 
| 
      
 25 
     | 
    
         
            +
             
     | 
| 
      
 26 
     | 
    
         
            +
            car1.on(:key_push, K_3) do
         
     | 
| 
      
 27 
     | 
    
         
            +
              self.rotation_style = :none
         
     | 
| 
       15 
28 
     | 
    
         
             
            end
         
     |