Class: Gembots::Arena
- Inherits:
-
Gosu::Window
- Object
- Gosu::Window
- Gembots::Arena
- Defined in:
- lib/gembots/arena.rb
Instance Attribute Summary collapse
-
#arena ⇒ Object
readonly
Returns the value of attribute arena.
-
#bots ⇒ Object
readonly
Returns the value of attribute bots.
Instance Method Summary collapse
- #button_down(id) ⇒ Object
- #draw ⇒ Object
-
#initialize(*bots) ⇒ Arena
constructor
A new instance of Arena.
- #spawn_proj(bot) ⇒ Object
- #update ⇒ Object
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. = "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
#arena ⇒ Object (readonly)
Returns the value of attribute arena.
6 7 8 |
# File 'lib/gembots/arena.rb', line 6 def arena @arena end |
#bots ⇒ Object (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 id close if id == Gosu::KbEscape end |
#draw ⇒ Object
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 |
#update ⇒ Object
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 |