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
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
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
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
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