Class: Rubots::Graphics::Window
- Inherits:
-
Gosu::Window
- Object
- Gosu::Window
- Rubots::Graphics::Window
- Defined in:
- lib/rubots/graphics/window.rb
Constant Summary collapse
- GAME_END_TICKS =
150
Instance Method Summary collapse
- #draw ⇒ Object
-
#initialize(game) ⇒ Window
constructor
A new instance of Window.
- #update ⇒ Object
Constructor Details
#initialize(game) ⇒ Window
Returns a new instance of Window.
4 5 6 7 8 9 10 |
# File 'lib/rubots/graphics/window.rb', line 4 def initialize(game) @game = game super Game::MAP_WIDTH, Game::MAP_HEIGHT, false self.caption = "LASER RUBOTS PEW PEW PEW" @robots = @game.robots.map { |r| Robot.new self, r } @beams = [] end |
Instance Method Details
#draw ⇒ Object
30 31 32 33 |
# File 'lib/rubots/graphics/window.rb', line 30 def draw @robots.each &:draw @beams.each &:draw end |
#update ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/rubots/graphics/window.rb', line 13 def update if !@game_over @game.tick @beams += @game.laser_beams.map { |b| Beam.new self, b } decay_beams @game_over = @game.over? else @game_over_countdown ||= GAME_END_TICKS @game_over_countdown -= 1 if @game_over_countdown == 0 puts "#{@game.winner.name} wins the game." exit end end end |