From: Ruby Student Date: 2013-06-07T04:10:27+09:00 Subject: Re: My car is "falling" off the screen green shoes --047d7b3a8f6810bf3c04de8111d7 Content-Type: text/plain; charset=ISO-8859-1 This also works very nicely! Thank you very much for taking the time to answer my post. On Thu, Jun 6, 2013 at 2:51 PM, Regis d'Aubarede wrote: > 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/. > > -- Ruby Student --047d7b3a8f6810bf3c04de8111d7 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
This also works very nicely!

Thank you v= ery much for taking the time to answer my post.


On Thu, Jun 6, 2013 at 2:51 PM,= Regis d'Aubarede <lists@ruby-forum.com> wrote:
and then, a little physics


=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D
require 'green_shoes'

def inside(a,m,b) m<a ? a : (m> b ? b : m) end
def inside?(a,m,b) =A0inside(a,m,b)=3D=3Dm end

Shoes.app :width =3D> 600,:height=3D> 100 do
=A0 info=3D para ""
=A0 @carim =3D image "car.png" #!!!!!

=A0 speed=3D10
=A0 acceleration=3D0.0
=A0 pos=3D300

=A0 h=3D{"Left" =3D> -0.3 , "Right" =3D> +0.4 }
=A0 keypress do |k|
=A0 =A0 acceleration =3D inside(-10, (acceleration+(h[k] || 0)) ,+10)
=A0 end

=A0 animate do
=A0 =A0 speed+=3Dacceleration
=A0 =A0 speed*=3D0.97
=A0 =A0 acceleration=3D0
=A0 =A0 speed *=3D -1 unless inside?(0,pos+speed,width-@carim.width)
=A0 =A0 pos=3Dpos+speed
=A0 =A0 speed=3Dinside(-10,speed,+10)

=A0 =A0 @carim.move pos, 100-@carim.height
=A0 =A0 info.replace " =A0Speed=3D%5.2f " %[speed]
=A0 end
end
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D

--
Posted via http://= www.ruby-forum.com/.




--
Ruby Stud= ent
--047d7b3a8f6810bf3c04de8111d7--