Class: Pugnacious::Player

Inherits:
Object
  • Object
show all
Defined in:
lib/pugnacious/player.rb

Constant Summary collapse

SPEED =
10
POINTER_SIZE =
10

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Player

Returns a new instance of Player.



8
9
10
11
12
13
14
15
16
# File 'lib/pugnacious/player.rb', line 8

def initialize(options = {})
  @color          = options[:color] || Ray::Color.blue
  position        = options[:position] || [200, 200]

  @control_keys   = options[:control_keys]

  @pointer = Ray::Polygon.circle(position, POINTER_SIZE, @color , 3, @color)
  @pointer.filled = false
end

Instance Attribute Details

#armyObject

Returns the value of attribute army.



3
4
5
# File 'lib/pugnacious/player.rb', line 3

def army
  @army
end

#colorObject

Returns the value of attribute color.



3
4
5
# File 'lib/pugnacious/player.rb', line 3

def color
  @color
end

#control_keysObject

Returns the value of attribute control_keys.



3
4
5
# File 'lib/pugnacious/player.rb', line 3

def control_keys
  @control_keys
end

#pointerObject

Returns the value of attribute pointer.



3
4
5
# File 'lib/pugnacious/player.rb', line 3

def pointer
  @pointer
end

#speedObject

Returns the value of attribute speed.



3
4
5
# File 'lib/pugnacious/player.rb', line 3

def speed
  @speed
end

Instance Method Details

#move(direction) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/pugnacious/player.rb', line 18

def move(direction)
  case direction
    when control_keys[:up]
      pointer.y -= SPEED unless (pointer.pos.y -= SPEED) < 0 + POINTER_SIZE
    when control_keys[:right]
      pointer.x += SPEED unless (pointer.pos.x += SPEED) > MAP_SIZE - POINTER_SIZE
    when control_keys[:down]
      pointer.y += SPEED unless (pointer.pos.y += SPEED) > MAP_SIZE - POINTER_SIZE
    when control_keys[:left]
      pointer.x -= SPEED unless (pointer.pos.x -= SPEED) < 0 + POINTER_SIZE
  end
end