Class: Gembots::Arena

Inherits:
Gosu::Window
  • Object
show all
Defined in:
lib/gembots/arena.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*bots) ⇒ Arena

Returns a new instance of Arena.



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/gembots/arena.rb', line 7

def initialize *bots
  super 640, 480, false
  self.caption = "Gembots battle"
  @bots = []
  @projs = []

  bots.each do |bot_class|
    bot = bot_class.new self
    bot.warp 320, 240
    @bots << bot
  end
end

Instance Attribute Details

#arenaObject (readonly)

Returns the value of attribute arena.



6
7
8
# File 'lib/gembots/arena.rb', line 6

def arena
  @arena
end

#botsObject (readonly)

Returns the value of attribute bots.



5
6
7
# File 'lib/gembots/arena.rb', line 5

def bots
  @bots
end

Instance Method Details

#button_down(id) ⇒ Object



40
41
42
# File 'lib/gembots/arena.rb', line 40

def button_down id
  close if id == Gosu::KbEscape
end

#drawObject



20
21
22
23
# File 'lib/gembots/arena.rb', line 20

def draw
  @bots.each &:draw
  @projs.each &:draw
end

#spawn_proj(bot) ⇒ Object



44
45
46
# File 'lib/gembots/arena.rb', line 44

def spawn_proj bot
  @projs << Gembots::Projectile.new(self, bot.x, bot.y, bot.angle)
end

#updateObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/gembots/arena.rb', line 25

def update
  @bots.each &:update
  @bots.each do |bot|
    bot.on_idle if bot.actions.empty?
    @projs.each do |proj|
      if (Gosu::distance bot.x, bot.y, proj.x, proj.y) < 10
        @bots.delete bot
        @projs.delete proj
      end
    end
  end

  @projs.each &:update
end