2Dç©çã¨ã³ã¸ã³ãRubyã«ç§»æ¤ãã¦ã¿ã¾ãã
http://github.com/technohippy/Pongo/tree/master
å
é±ã®RubyKaigi2009ã§ãRubyã§*1ä½ãä½ããã欲ããæ¿ããåºæ¿ãããã®ã§ãåãã欲ããã£ãç©çã¨ã³ã¸ã³ãRubyã«ç§»æ¤ãã¦ã¿ããæ¬æ°ã¢ããªãªãChipmunkのRubyバインディングã§FAã£ã½ããã©ããã¥ã¢Rubyã®ãããã°ãã£ãã§å¬ããã£ããã
ç©çã¨ã³ã¸ã³ã¨è¨ãã°åã«Box2DのAS3版をJSに移植ãããã¨ããããã ãã©ãRubyã®å ´åã¯JSã¿ããã«åç´ã«ç½®æã£ã¦ããã«ãããªãããé£åº¦é«ããã30åã½ã¼ã¹çºãã¦è«¦ãããã§ãããã¡ãã£ã¨ã·ã³ãã«ãããªã¨ã³ã¸ã³ã¨ãããã¨ã§ç§»æ¤ã®ã¿ã¼ã²ããã¨ãã¦ã¯APE (Actionscript Physics Engine)ãé¸æãã¡ãªã¿ã«ä»åã¯ç½®æãããªãã¦ã¡ããã¨ç®è¦&ææã§ç§»æ¤ããã£ãã
移æ¤ãã¦ã¿ã¦åãã£ãã®ã¯ãAPEã¯ãã³ãã«ã·ã³ãã«ãBox2Dã«ãã£ã便å©æ©è½ã¨ããããããªãã®ã§ãã¡ããã¨ããã²ã¼ã ãä½ããªãã©ãèãã¦ãBox2D移æ¤ããã®ãæ£è§£ããã ãããããå¼ããªããç©çã¨ã³ã¸ã³ãåå¼·ãããã¨æã£ã¦ãèªåã«ã¯ãããã¯ããã§ããé¸æã ã£ãããªã¨ã
ã¬ã³ãã©ã¯å ¥ãæ¿ãå¯è½ã ãã©ãä»ã®ã¨ããShoesç¨ã®é©å½ãªã®ããç¨æãã¦ãªãã触ã£ã¦ã¿ãã人ã¯è¦³å¿µãã¦Shoes2ãã¤ã³ã¹ãã¼ã«ããã°ããã¨æããShoeså¯æããShoesããããSDLã¨ãTkãã£ã³ãã¹ã使ã£ãã¬ã³ãã©ã追å ããã¤ãããªã®ã§ãShoesãªãã¦å ¥ãã¦ãããã¼ã£ã¦äººã¯ä¸é±éãããå¾ ã¦ã°ãããã¨ããããã
ã¡ãªã¿ã«ååã®Pongoã¯ãªã©ã³ã¦ã¼ã¿ã³ã®ãã¨ãæ¤ç´¢ãããRed Apeã¨ãå¼ã°ãã¦ããããã®ã§èµ¤ãAPEã£ã¦ãã¨ã§ãæåã¯åç´ã«APEã®é ã«Rãã¤ããããã¨æã£ããã©ããã¯ãããã«ãããã»ã»ã»ã
...
ä¾
require 'pongo' require 'pongo/renderer/shoes_renderer' require 'pongo/logger/shoes_logger' include Pongo Shoes.app :width => 500, :height => 350 do # ã¬ã³ãã©ã¨ããã¬ã¼ã¨ãéåã¨ãããããè¨å® APEngine.setup APEngine.renderer = Renderer::ShoesRenderer.new(self) APEngine.logger = Logger::ShoesLogger.new(self) APEngine.add_force VectorForce.new(false, 0, 2) # ãã¼ãã£ã¯ã«ã¯ã°ã«ã¼ãã«ç»é²ããªãã¨é§ç®ãããã®ã§æºå default_group = Group.new default_group.collide_internal = true # è½ä¸ç©ãç®±ã¨ã丸ã¨ã default_group.add_particle(RectangleParticle.new(275, 90, 20, 30)) default_group.add_particle(CircleParticle.new(255, 150, 3)) # å°é¢ default_group.add_particle(RectangleParticle.new(250, 250, 300, 50, :fixed => true)) # ã°ã«ã¼ããã¨ã³ã¸ã³ã«ç»é² APEngine.add_group(default_group) # å®è¡ animate(10) do |anim| APEngine.step APEngine.draw end end