Class: RTanque::Shell

Inherits:
Object
  • Object
show all
Includes:
Movable
Defined in:
lib/rtanque/shell.rb

Constant Summary collapse

RATIO =
Configuration.shell.ratio
SHELL_SPEED_FACTOR =
Configuration.shell.speed_factor

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Movable

#arena=, #heading, #heading=, #position, #position=, #speed, #speed=, #tick, #update_position

Constructor Details

#initialize(bot, position, heading, fire_power) ⇒ Shell


12
13
14
15
16
17
18
19
20
# File 'lib/rtanque/shell.rb', line 12

def initialize(bot, position, heading, fire_power)
  @bot = bot
  @arena = bot.arena
  @fire_power = fire_power
  self.position = position
  self.heading = heading
  self.speed = self.class.speed(fire_power) # TODO: add bot's relative speed in this heading
  @dead = false
end

Instance Attribute Details

#arenaObject (readonly)

Returns the value of attribute arena


6
7
8
# File 'lib/rtanque/shell.rb', line 6

def arena
  @arena
end

#botObject (readonly)

Returns the value of attribute bot


6
7
8
# File 'lib/rtanque/shell.rb', line 6

def bot
  @bot
end

#fire_powerObject (readonly)

Returns the value of attribute fire_power


6
7
8
# File 'lib/rtanque/shell.rb', line 6

def fire_power
  @fire_power
end

Class Method Details

.speed(fire_power) ⇒ Object


8
9
10
# File 'lib/rtanque/shell.rb', line 8

def self.speed fire_power
  fire_power * SHELL_SPEED_FACTOR
end

Instance Method Details

#bound_to_arenaObject


22
23
24
# File 'lib/rtanque/shell.rb', line 22

def bound_to_arena
  false
end

#dead!Object


30
31
32
# File 'lib/rtanque/shell.rb', line 30

def dead!
  @dead = true
end

#dead?Boolean


26
27
28
# File 'lib/rtanque/shell.rb', line 26

def dead?
  @dead ||= self.position.outside_arena?
end

#hits(bots, &on_hit) ⇒ Object


34
35
36
37
38
39
40
41
42
# File 'lib/rtanque/shell.rb', line 34

def hits(bots, &on_hit)
  bots.each do |hit_bot|
    if hit_bot.position.within_radius?(self.position, Bot::RADIUS)
      self.dead!
      on_hit.call(self.bot, hit_bot) if on_hit
      break
    end
  end
end