Class: EnemyCommand
- Inherits:
-
Actor
- Object
- Actor
- EnemyCommand
- Defined in:
- lib/enemy_command.rb
Instance Attribute Summary collapse
-
#attack_every ⇒ Object
Returns the value of attribute attack_every.
Instance Method Summary collapse
- #attack!(opts = {}) ⇒ Object
-
#initialize(opts = {}) ⇒ EnemyCommand
constructor
A new instance of EnemyCommand.
- #to_s ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ EnemyCommand
Returns a new instance of EnemyCommand.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/enemy_command.rb', line 5 def initialize opts={} super @defeated = false @stock = opts[:stock] || 10 @attack_every = opts[:attack_every] || 1 # Missiles configuration @missile_conf = { :width => opts[:missile_width] || 14, :max_force => opts[:missile_max_force] || 10, :max_speed => opts[:missile_max_speed] || 50, :mass => opts[:missile_mass] || 1, :color => opts[:missile_color] || 0xffccbcff } on :extra! do unless Gosu::Song.current_song $lotu.song('Amenoske-Overtura_Ce_en_Re_menor.mp3').play end end end |
Instance Attribute Details
#attack_every ⇒ Object
Returns the value of attribute attack_every.
3 4 5 |
# File 'lib/enemy_command.rb', line 3 def attack_every @attack_every end |
Instance Method Details
#attack!(opts = {}) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/enemy_command.rb', line 27 def attack! opts={} unless @defeated if @stock > 0 surprise = rand(5.0/@stock) surprise *= 2 if opts[:extra] @extra ||= {} @extra[:max_speed] = 0 @extra[:color] = nil if opts[:extra] == :speed @extra[:max_speed] = @missile_conf[:max_speed] * 4 @extra[:color] = Gosu::Color.new(0xff000000) @extra[:color].saturation = 0 end missile = EnemyMissile.new(:mass => @missile_conf[:mass] + surprise, :max_force => @missile_conf[:max_force] + surprise*10, :max_speed => @missile_conf[:max_speed] + surprise*10 + @extra[:max_speed], :color => @extra[:color] || @missile_conf[:color], :x => rand($lotu.width), :y => 0, :angle => 180) missile.save_init_pos missile.target = Vector2d.new(rand($lotu.width), $lotu.height) missile.play_animation('missile.png', :width => @missile_conf[:width] + surprise * 10) if opts[:extra] == :speed missile.interpolate_saturation( :init => 0.2, :end => 1, :duration => 1 ) missile.interpolate_value( :init => 1, :end => 0.2, :duration => 1, :bounce => true ) missile.interpolate_hue( :init => missile.color.hue, :end => missile.color.hue, :duration => 1, :loop => true) end @stock -= 1 else @defeated = true end end end |
#to_s ⇒ Object
62 63 64 |
# File 'lib/enemy_command.rb', line 62 def to_s "Stock: #{@stock}" end |