Class: Gtk::Pong::Ball
- Inherits:
-
CenteredCircle
- Object
- CenteredItem
- CenteredCircle
- Gtk::Pong::Ball
- Defined in:
- lib/games_paradise/pong/gtk/cairo_pong.rb
Constant Summary
Constants inherited from CenteredItem
Instance Attribute Summary collapse
-
#dx ⇒ Object
Returns the value of attribute dx.
-
#dy ⇒ Object
Returns the value of attribute dy.
Attributes inherited from CenteredItem
Instance Method Summary collapse
-
#initialize(dx = 0.02, dy = 0.02) ⇒ Ball
constructor
initialize.
-
#update ⇒ Object
update.
Methods inherited from CenteredCircle
Methods inherited from CenteredItem
#max_x, #max_y, #min_x, #min_y
Constructor Details
#initialize(dx = 0.02, dy = 0.02) ⇒ Ball
initialize
76 77 78 79 80 |
# File 'lib/games_paradise/pong/gtk/cairo_pong.rb', line 76 def initialize(dx=0.02, dy=0.02) super(0.8, 0.5, 0.04, 0.04) @dx = dx @dy = dy end |
Instance Attribute Details
#dx ⇒ Object
Returns the value of attribute dx.
73 74 75 |
# File 'lib/games_paradise/pong/gtk/cairo_pong.rb', line 73 def dx @dx end |
#dy ⇒ Object
Returns the value of attribute dy.
73 74 75 |
# File 'lib/games_paradise/pong/gtk/cairo_pong.rb', line 73 def dy @dy end |
Instance Method Details
#update ⇒ Object
update
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/games_paradise/pong/gtk/cairo_pong.rb', line 83 def update @x += @dx @y += @dy # ball bouncing if max_y > 1 @y = 1 - (max_y - 1) @dy *= -1 elsif min_y < 0 @y -= min_y @dy *= -1 end if max_x > 1 @x = 1 - (max_x - 1) @dx *= -1 elsif min_x < 0 @x -= min_x @dx *= -1 end end |