Module: Brawl::BasicWeapon
- Defined in:
- lib/brawl/parts/basic_weapon.rb
Instance Attribute Summary collapse
-
#power ⇒ Object
readonly
Returns the value of attribute power.
-
#range ⇒ Object
readonly
Returns the value of attribute range.
-
#reload_time ⇒ Object
readonly
Returns the value of attribute reload_time.
Instance Method Summary collapse
Instance Attribute Details
#power ⇒ Object (readonly)
Returns the value of attribute power.
4 5 6 |
# File 'lib/brawl/parts/basic_weapon.rb', line 4 def power @power end |
#range ⇒ Object (readonly)
Returns the value of attribute range.
4 5 6 |
# File 'lib/brawl/parts/basic_weapon.rb', line 4 def range @range end |
#reload_time ⇒ Object (readonly)
Returns the value of attribute reload_time.
4 5 6 |
# File 'lib/brawl/parts/basic_weapon.rb', line 4 def reload_time @reload_time end |
Instance Method Details
#initialize(params = {}) ⇒ Object
6 7 8 9 10 11 12 13 |
# File 'lib/brawl/parts/basic_weapon.rb', line 6 def initialize(params={}) @reload_time = params[:reload_time] || 10 @range = params[:range] || 10 @power = params[:power] || 1 @reload_countdown = 0 end |
#reload_countdown ⇒ Object
41 42 43 44 |
# File 'lib/brawl/parts/basic_weapon.rb', line 41 def reload_countdown return 0 if @reload_countdown <= @arena.ticks @reload_countdown - @arena.ticks end |
#shoot(direction = @heading) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/brawl/parts/basic_weapon.rb', line 15 def shoot(direction=@heading) return false if reload_countdown > 0 @reload_countdown = @reload_time + @arena.ticks cone = { origin: @location, direction: direction, radius: @range, angle: 2 } # refactor possible_hits = @arena.get_all_objects.collect do |object| if object[:id] != @id && hit = Helper.point_in_cone?(cone.merge(point: object[:location])) object.merge(hit) end end.compact return if possible_hits.empty? # refactor hit = possible_hits.sort{|a,b| a[:distance] <=> b[:distance]}.first @arena.forward_damage(damage: @power, target: hit[:id]) hit end |