dxruby_sdl
dxruby_sdl copied to clipboard
衝突判定 === が、配列だとエラーになる
衝突判定の === で、 右側に配列を指定するとエラーが出ます。
/Users/user_name/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/dxruby_sdl-0.0.10/lib/dxruby_sdl/sprite.rb:132:in `===': undefined method `collision_enable' for #<Array:0x007fe57c86a330> (NoMethodError)
左右を入れ替えて、配列を左側に指定するとエラーは出ませんが、衝突判定しません。
環境; dxruby_sdl 0.0.10 Ruby 1.9.3-p448、2.1.2 ともに Mac OS X 10.9.3
サンプルコード;
require 'dxruby'
C_BLACK = [255, 0, 0, 0]
C_RED = [255, 255, 0, 0]
C_GREEN = [255, 0, 255, 0]
C_BLUE = [255, 0, 0, 255]
C_YELLOW = [255, 255, 255, 0]
C_CYAN = [255, 0, 255, 255]
C_MAGENTA = [255, 255, 0, 255]
C_WHITE = [255, 255, 255, 255]
C_DEFAULT = [ 0, 0, 0, 0]
s = [Sprite.new(100, 100, Image.new(100, 100, C_RED)),
Sprite.new(200, 200, Image.new(100, 100, C_GREEN)),
Sprite.new(300, 300, Image.new(100, 100, C_BLUE))]
m = Sprite.new(0, 0, Image.new(50, 50, C_WHITE))
font = Font.new(32)
Window.loop do
m.x, m.y = Input.mouse_pos_x, Input.mouse_pos_y
Sprite.draw(s)
m.draw
if m === s
Window.draw_font(0, 0, "hit!", font)
end
end
「DXRuby プロジェクトWiki - Spriteを使うためのチュートリアル03 2.衝突判定の使い方」2つめの例より。色定数は補足。 http://dxruby.sourceforge.jp/cgi-bin/hiki.cgi?Sprite%A4%F2%BB%C8%A4%A6%A4%BF%A4%E1%A4%CE%A5%C1%A5%E5%A1%BC%A5%C8%A5%EA%A5%A2%A5%EB03
あるいは、 松江Ruby会議05に参加してきた - mirichiの日記 でのライブコーディングによる「ブロック崩し」 http://d.hatena.ne.jp/mirichi/20140317/p1