class RTanque::Gui::Window

Constants

FONT_NAME
SMALL_FONT_SIZE
UPDATE_INTERVAL

Attributes

gui_bots[R]
gui_explosions[R]
gui_shells[R]

Public Class Methods

new(match) click to toggle source
Calls superclass method
# File lib/rtanque/gui/window.rb, line 12
def initialize(match)
  @match = match
  @arena = match.arena
  match.bots.each { |bot| bot.gui_window = self }
  @gui_bots = DrawGroup.new(match.bots) do |bot|
    RTanque::Gui::Bot.new(self, bot)
  end
  @gui_shells = DrawGroup.new(match.shells) do |shell|
    RTanque::Gui::Shell.new(self, shell)
  end
  @gui_explosions = DrawGroup.new(match.explosions) do |explosion|
    RTanque::Gui::Explosion.new(self, explosion)
  end
  # Fullscreen: https://github.com/jlnr/gosu/issues/159#issuecomment-12473172
  super(@arena.width, @arena.height, false, UPDATE_INTERVAL)
  self.caption = self.class.name.split('::').first
  @background = Gosu::Image.new(self, Gui.resource_path("images/grass.png"))

  @draw_procs = []
end

Public Instance Methods

add_draw_proc(&b) click to toggle source
# File lib/rtanque/gui/window.rb, line 59
def add_draw_proc &b
  @draw_procs << b
end
draw() click to toggle source
# File lib/rtanque/gui/window.rb, line 37
def draw
  self.close if button_down?(Gosu::Button::KbEscape)
  @background.draw(0, 0, ZOrder::BACKGROUND)
  if @match.finished?
    self.close if Configuration.quit_when_finished
    self.gui_bots.each { |bot| bot.grow(2) }
  end
  self.draw_drawables
end
draw_drawables() click to toggle source
# File lib/rtanque/gui/window.rb, line 47
def draw_drawables
  self.gui_bots.draw
  self.gui_shells.draw
  self.gui_explosions.draw

  @draw_procs.each do |proc|
    proc.call self
  end

  @draw_procs.clear
end
update() click to toggle source
# File lib/rtanque/gui/window.rb, line 33
def update
  @match.tick
end