class Rubots::Graphics::Window
Constants
- GAME_END_TICKS
Public Class Methods
new(game)
click to toggle source
Calls superclass method
# 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
Public Instance Methods
draw()
click to toggle source
# File lib/rubots/graphics/window.rb, line 30 def draw @robots.each &:draw @beams.each &:draw end
update()
click to toggle source
# 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
Private Instance Methods
decay_beams()
click to toggle source
# File lib/rubots/graphics/window.rb, line 37 def decay_beams @beams.each(&:decay) @beams.reject!(&:expired?) end