Class: Pugnacious::Player
- Inherits:
-
Object
- Object
- Pugnacious::Player
- Defined in:
- lib/pugnacious/player.rb
Constant Summary collapse
- SPEED =
10
- POINTER_SIZE =
10
Instance Attribute Summary collapse
-
#army ⇒ Object
Returns the value of attribute army.
-
#color ⇒ Object
Returns the value of attribute color.
-
#control_keys ⇒ Object
Returns the value of attribute control_keys.
-
#pointer ⇒ Object
Returns the value of attribute pointer.
-
#speed ⇒ Object
Returns the value of attribute speed.
Instance Method Summary collapse
- #control_keys_down ⇒ Object
- #control_keys_left ⇒ Object
- #control_keys_right ⇒ Object
-
#control_keys_up ⇒ Object
Control keys aliases.
-
#initialize(options = {}) ⇒ Player
constructor
A new instance of Player.
- #move(direction) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Player
Returns a new instance of Player.
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/pugnacious/player.rb', line 8 def initialize( = {}) @color = [:color] || Ray::Color.blue position = [:position] || [200, 200] @control_keys = [:control_keys] @control_keys ||= [:up, :right, :down, :left] @pointer = Ray::Polygon.circle(position, POINTER_SIZE, @color , 3, @color) @pointer.filled = false end |
Instance Attribute Details
#army ⇒ Object
Returns the value of attribute army.
3 4 5 |
# File 'lib/pugnacious/player.rb', line 3 def army @army end |
#color ⇒ Object
Returns the value of attribute color.
3 4 5 |
# File 'lib/pugnacious/player.rb', line 3 def color @color end |
#control_keys ⇒ Object
Returns the value of attribute control_keys.
3 4 5 |
# File 'lib/pugnacious/player.rb', line 3 def control_keys @control_keys end |
#pointer ⇒ Object
Returns the value of attribute pointer.
3 4 5 |
# File 'lib/pugnacious/player.rb', line 3 def pointer @pointer end |
#speed ⇒ Object
Returns the value of attribute speed.
3 4 5 |
# File 'lib/pugnacious/player.rb', line 3 def speed @speed end |
Instance Method Details
#control_keys_down ⇒ Object
44 45 46 |
# File 'lib/pugnacious/player.rb', line 44 def control_keys_down control_keys[2] end |
#control_keys_left ⇒ Object
48 49 50 |
# File 'lib/pugnacious/player.rb', line 48 def control_keys_left control_keys[3] end |
#control_keys_right ⇒ Object
40 41 42 |
# File 'lib/pugnacious/player.rb', line 40 def control_keys_right control_keys[1] end |
#control_keys_up ⇒ Object
Control keys aliases
36 37 38 |
# File 'lib/pugnacious/player.rb', line 36 def control_keys_up control_keys[0] end |
#move(direction) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/pugnacious/player.rb', line 19 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 |