Class: Termfront::DropItem::Weapon

Inherits:
Base
  • Object
show all
Defined in:
lib/termfront/drop_item/weapon.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#x, #y

Instance Method Summary collapse

Methods inherited from Base

#in_range?

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

#ammoObject

Returns the value of attribute ammo.



6
7
8
# File 'lib/termfront/drop_item/weapon.rb', line 6

def ammo
  @ammo
end

#typeObject

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_colorObject



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_labelObject



33
34
35
# File 'lib/termfront/drop_item/weapon.rb', line 33

def radar_label
  Weapon::Base.registry[@type].new.name[0]
end

#sprite_colorObject



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