Move ball with Ruby(/Shoes)

Hello,

we need to move a Ball with ruby and Shoes. It should move through the
window, but not leave. Now we have the class ball, it is there if we
open Shoes. But it doesn´t move. We know we need a method for this. But
we don´t know how we could make this. Please can you help me :)?Thank
you :slight_smile:

So this is the ball:

class Kugel < Shoes::Widget #erzeugt die Klasse Quadrat
@x
@y
@t
@l
@r
@farbe
@objekt

def initialize( x, y, t, l,r, farbe) # Konstruktor
@x = x
@y = y
@t = t
@l=l
@r = r
@farbe = farbe
fill farbe # F¸llfarbe setzen
@objekt = oval( x, y, t, l,r,farbe)

end

Shoes.app width: 500, height: 500 do # opens Shoes
Shoes.show_log
background black
x=kugel(400,200,20,20,60,deeppink) # makes a new ball
end

Can please someone answer me :/?

On 01/23/2014 03:05 AM, Johanna B. wrote:

end

Shoes.app width: 500, height: 500 do # opens Shoes
Shoes.show_log
background black
x=kugel(400,200,20,20,60,deeppink) # makes a new ball
end

You want to look at:

http://shoesrb.com/manual/Common.html#displace
http://shoesrb.com/manual/Common.html#move
http://shoesrb.com/manual/Element.html#animate

Look near the bottom of this page http://shoesrb.com/walkthrough.html
where it has examples of moving a star and some shoes.

Hope that helps.

-Justin

Hi Johanna,

Try out this one? :wink:

class Kugel < Shoes::Widget
def initialize( x, y, t, l,r, farbe)
@x, @y, @t, @l, @r, @farbe = x, y, t, l,r, farbe
@xdir, @ydir = 1, 1
fill farbe
@objekt = oval( x, y, t, l,r,farbe)
end
def move_in_the_window
@x += 7 * @xdir
@y += 5 * @ydir
@xdir *= -1 if @x > 500 or @x < 0
@ydir *= -1 if @y > 500 or @y < 0
@objekt.move @x, @y
end
end

Shoes.app width: 500, height: 500 do
Shoes.show_log
background black
x=kugel(400,200,20,20,60,deeppink)
animate do
x.move_in_the_window
end
end

Hope this helps,
ashbb