Class: Gtk::Pong::Field

Inherits:
Object
  • Object
show all
Defined in:
lib/games_paradise/pong/gtk/cairo_pong.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#heightObject

Returns the value of attribute height.



145
146
147
# File 'lib/games_paradise/pong/gtk/cairo_pong.rb', line 145

def height
  @height
end

#widthObject

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

#updateObject

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