Class: Pugnacious::Molecule

Inherits:
Object
  • Object
show all
Includes:
Movable
Defined in:
lib/pugnacious/molecule.rb

Constant Summary collapse

MAX_LIFE =
40

Constants included from Movable

Pugnacious::Movable::DIRECTIONS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Movable

#can_i_move_there?, #here, #move, #move_there, #pointer_at_east, #pointer_at_north, #pointer_at_north_east, #pointer_at_north_west, #pointer_at_south, #pointer_at_south_east, #pointer_at_south_west, #pointer_at_west, #try_to_go, #where_is_the_pointer?

Constructor Details

#initialize(options = {}) ⇒ Molecule

Returns a new instance of Molecule.



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/pugnacious/molecule.rb', line 9

def initialize(options = {})
  @player    = options[:player]
  @game_map  = options[:map]
  @position  = options[:pos]
  @game_map[@position[0]][@position[1]] = self
  @body = Ray::Polygon.rectangle([0, 0, MOLECULE_SIZE, MOLECULE_SIZE],
    Ray::Color.new(100, 100, 0) + @player.color)
  @body.pos  = [@position[0] * MOLECULE_SIZE, @position[1] * MOLECULE_SIZE] || [0, 0]
  @molecules = options[:molecules]
  @pointer   = @player.pointer
  @life      = MAX_LIFE
  @rival     = options[:rival]
end

Instance Attribute Details

#bodyObject

Returns the value of attribute body.



5
6
7
# File 'lib/pugnacious/molecule.rb', line 5

def body
  @body
end

#game_mapObject

Returns the value of attribute game_map.



5
6
7
# File 'lib/pugnacious/molecule.rb', line 5

def game_map
  @game_map
end

#lifeObject

Returns the value of attribute life.



5
6
7
# File 'lib/pugnacious/molecule.rb', line 5

def life
  @life
end

#moleculesObject

Returns the value of attribute molecules.



5
6
7
# File 'lib/pugnacious/molecule.rb', line 5

def molecules
  @molecules
end

#playerObject

Returns the value of attribute player.



5
6
7
# File 'lib/pugnacious/molecule.rb', line 5

def player
  @player
end

#pointerObject

Returns the value of attribute pointer.



5
6
7
# File 'lib/pugnacious/molecule.rb', line 5

def pointer
  @pointer
end

#positionObject

Returns the value of attribute position.



5
6
7
# File 'lib/pugnacious/molecule.rb', line 5

def position
  @position
end

#rivalObject

Returns the value of attribute rival.



5
6
7
# File 'lib/pugnacious/molecule.rb', line 5

def rival
  @rival
end

Instance Method Details

#receive_damageObject



23
24
25
26
27
28
29
30
31
# File 'lib/pugnacious/molecule.rb', line 23

def receive_damage()
  @life -=1
  if @life <= 0
    @player = @rival
    @body.color = Ray::Color.new(100, 100, 0) + @player.color
    @life = MAX_LIFE
    @pointer = @player.pointer
  end
end