Class: Termfront::DropItem::Weapon
- Defined in:
- lib/termfront/drop_item/weapon.rb
Instance Attribute Summary collapse
-
#ammo ⇒ Object
Returns the value of attribute ammo.
-
#type ⇒ Object
Returns the value of attribute type.
Attributes inherited from Base
Instance Method Summary collapse
-
#initialize(x:, y:, type:, ammo:) ⇒ Weapon
constructor
A new instance of Weapon.
- #pickup!(player) ⇒ Object
- #radar_color ⇒ Object
- #radar_label ⇒ Object
- #sprite_color ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(x:, y:, type:, ammo:) ⇒ Weapon
Returns a new instance of Weapon.
8 9 10 11 12 |
# File 'lib/termfront/drop_item/weapon.rb', line 8 def initialize(x:, y:, type:, ammo:) super(x: x, y: y) @type = type @ammo = ammo end |
Instance Attribute Details
#ammo ⇒ Object
Returns the value of attribute ammo.
6 7 8 |
# File 'lib/termfront/drop_item/weapon.rb', line 6 def ammo @ammo end |
#type ⇒ Object
Returns the value of attribute type.
6 7 8 |
# File 'lib/termfront/drop_item/weapon.rb', line 6 def type @type end |
Instance Method Details
#pickup!(player) ⇒ Object
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/termfront/drop_item/weapon.rb', line 14 def pickup!(player) cur = player.current_weapon if cur.type_id == @type max = cur.max_ammo cur.ammo = [cur.ammo + @ammo, max].min if max else player.drops << DropItem::Weapon.new(x: player.x, y: player.y, type: cur.type_id, ammo: cur.ammo) player.weapons[player.weapon_idx] = Weapon::Base.build(@type, @ammo) end end |
#radar_color ⇒ Object
29 30 31 |
# File 'lib/termfront/drop_item/weapon.rb', line 29 def radar_color @type.to_s.start_with?("shock") ? "\e[96m" : "\e[93m" end |
#radar_label ⇒ Object
33 34 35 |
# File 'lib/termfront/drop_item/weapon.rb', line 33 def radar_label Weapon::Base.registry[@type].new.name[0] end |
#sprite_color ⇒ Object
25 26 27 |
# File 'lib/termfront/drop_item/weapon.rb', line 25 def sprite_color @type.to_s.start_with?("shock") ? "60;200;220" : "220;200;60" end |