Class: RTanque::Gui::Window

Inherits:
Gosu::Window
  • Object
show all
Defined in:
lib/rtanque/gui/window.rb

Constant Summary collapse

UPDATE_INTERVAL =
Configuration.gui.update_interval
FONT_NAME =
Gosu::default_font_name
SMALL_FONT_SIZE =
Configuration.gui.fonts.small

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(match) ⇒ Window

Returns a new instance of Window


12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# 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

Instance Attribute Details

#gui_botsObject (readonly)

Returns the value of attribute gui_bots


10
11
12
# File 'lib/rtanque/gui/window.rb', line 10

def gui_bots
  @gui_bots
end

#gui_explosionsObject (readonly)

Returns the value of attribute gui_explosions


10
11
12
# File 'lib/rtanque/gui/window.rb', line 10

def gui_explosions
  @gui_explosions
end

#gui_shellsObject (readonly)

Returns the value of attribute gui_shells


10
11
12
# File 'lib/rtanque/gui/window.rb', line 10

def gui_shells
  @gui_shells
end

Instance Method Details

#add_draw_proc(&b) ⇒ Object


59
60
61
# File 'lib/rtanque/gui/window.rb', line 59

def add_draw_proc &b
  @draw_procs << b
end

#drawObject


37
38
39
40
41
42
43
44
45
# 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_drawablesObject


47
48
49
50
51
52
53
54
55
56
57
# 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

#updateObject


33
34
35
# File 'lib/rtanque/gui/window.rb', line 33

def update
  @match.tick
end