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
-
#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 |
# File 'lib/pugnacious/player.rb', line 8 def initialize( = {}) @color = [:color] || Ray::Color.blue position = [:position] || [200, 200] @control_keys = [:control_keys] @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
#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 |