Class: Gtk::Pong::Field
- Inherits:
-
Object
- Object
- Gtk::Pong::Field
- Defined in:
- lib/games_paradise/pong/gtk/cairo_pong.rb
Instance Attribute Summary collapse
-
#height ⇒ Object
Returns the value of attribute height.
-
#width ⇒ Object
Returns the value of attribute width.
Instance Method Summary collapse
-
#draw(cr) ⇒ Object
draw.
-
#initialize(margin = 0.05) ⇒ Field
constructor
initialize.
-
#update ⇒ Object
update.
Constructor Details
#initialize(margin = 0.05) ⇒ Field
initialize
148 149 150 151 152 153 154 |
# File 'lib/games_paradise/pong/gtk/cairo_pong.rb', line 148 def initialize(margin = 0.05) @margin = margin @left_paddle = Paddle.new(self, @margin, 0.5) @right_paddle = Paddle.new(self, 1 - @margin, 0.7) @paddles = [@left_paddle, @right_paddle] @ball = Ball.new end |
Instance Attribute Details
#height ⇒ Object
Returns the value of attribute height.
145 146 147 |
# File 'lib/games_paradise/pong/gtk/cairo_pong.rb', line 145 def height @height end |
#width ⇒ Object
Returns the value of attribute width.
145 146 147 |
# File 'lib/games_paradise/pong/gtk/cairo_pong.rb', line 145 def width @width end |
Instance Method Details
#draw(cr) ⇒ Object
draw
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 |
# File 'lib/games_paradise/pong/gtk/cairo_pong.rb', line 168 def draw(cr) cr.set_source_rgba(1, 1, 1) cr.rectangle(0, 0, 1, 1) cr.fill cr.save { cr.set_source_rgba(0.8, 0.8, 0.8, 0.8) cr.set_line_join(Cairo::LINE_JOIN_ROUND) @paddles.each { |paddle| cr.save {paddle.draw(cr)} } } cr.set_source_rgba(0, 0, 0) cr.save {@ball.draw(cr)} end |
#update ⇒ Object
update
157 158 159 160 161 162 163 164 165 |
# File 'lib/games_paradise/pong/gtk/cairo_pong.rb', line 157 def update @paddles.each { |paddle| paddle.update(@ball) } @ball.update @paddles.each { |paddle| paddle.update_ball(@ball) } end |