From: Regis d'Aubarede Date: 2013-06-07T03:51:09+09:00 Subject: Re: My car is "falling" off the screen green shoes and then, a little physics ========================================================== require 'green_shoes' def inside(a,m,b) m b ? b : m) end def inside?(a,m,b) inside(a,m,b)==m end Shoes.app :width => 600,:height=> 100 do info= para "" @carim = image "car.png" #!!!!! speed=10 acceleration=0.0 pos=300 h={"Left" => -0.3 , "Right" => +0.4 } keypress do |k| acceleration = inside(-10, (acceleration+(h[k] || 0)) ,+10) end animate do speed+=acceleration speed*=0.97 acceleration=0 speed *= -1 unless inside?(0,pos+speed,width-@carim.width) pos=pos+speed speed=inside(-10,speed,+10) @carim.move pos, 100-@carim.height info.replace " Speed=%5.2f " %[speed] end end ========================================================== -- Posted via http://www.ruby-forum.com/.