Class: Player
- Inherits:
-
Chingu::GameObject
- Object
- Chingu::GameObject
- Player
- Includes:
- GamespacePersistence
- Defined in:
- lib/prkwars/player.rb
Overview
Class holding all the logic related to the player - input controller and any manipulation of player’s sprite.
Constant Summary collapse
- STARTING_LIVES =
3
- SHOOT_GAP =
8
- STARTING_BOMBS =
3
- INVUL_FRAMES =
30
Instance Attribute Summary collapse
-
#invulnerable ⇒ Object
readonly
Returns the value of attribute invulnerable.
-
#lives ⇒ Object
Returns the value of attribute lives.
Instance Method Summary collapse
-
#initialize(gamespace, options = {}) ⇒ Player
constructor
A new instance of Player.
- #move_down ⇒ Object
- #move_left ⇒ Object
- #move_right ⇒ Object
- #move_up ⇒ Object
- #shoot_down ⇒ Object
- #shoot_left ⇒ Object
- #shoot_right ⇒ Object
- #shoot_up ⇒ Object
- #update ⇒ Object
Methods included from GamespacePersistence
Constructor Details
#initialize(gamespace, options = {}) ⇒ Player
Returns a new instance of Player.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/prkwars/player.rb', line 19 def initialize(gamespace, = {}) super() @image = Image['./media/player_ship.png'] self.input = { holding_w: :move_up, holding_a: :move_left, holding_d: :move_right, holding_s: :move_down, holding_left: :shoot_left, holding_right: :shoot_right, holding_up: :shoot_up, holding_down: :shoot_down } init_vector_variables @gamespace = gamespace @lives = STARTING_LIVES @bombs = STARTING_BOMBS end |
Instance Attribute Details
#invulnerable ⇒ Object (readonly)
Returns the value of attribute invulnerable.
11 12 13 |
# File 'lib/prkwars/player.rb', line 11 def invulnerable @invulnerable end |
#lives ⇒ Object
Returns the value of attribute lives.
10 11 12 |
# File 'lib/prkwars/player.rb', line 10 def lives @lives end |
Instance Method Details
#move_down ⇒ Object
39 40 41 42 |
# File 'lib/prkwars/player.rb', line 39 def move_down @y += Constants::PLAYER_VELOCITY @y_change = Constants::PLAYER_VELOCITY end |
#move_left ⇒ Object
44 45 46 47 |
# File 'lib/prkwars/player.rb', line 44 def move_left @x -= Constants::PLAYER_VELOCITY @x_change = -Constants::PLAYER_VELOCITY end |
#move_right ⇒ Object
49 50 51 52 |
# File 'lib/prkwars/player.rb', line 49 def move_right @x += Constants::PLAYER_VELOCITY @x_change = Constants::PLAYER_VELOCITY end |
#move_up ⇒ Object
34 35 36 37 |
# File 'lib/prkwars/player.rb', line 34 def move_up @y -= Constants::PLAYER_VELOCITY @y_change = -Constants::PLAYER_VELOCITY end |
#shoot_down ⇒ Object
66 67 68 |
# File 'lib/prkwars/player.rb', line 66 def shoot_down @shoot_vec_y = Constants::BULLET_VELOCITY end |
#shoot_left ⇒ Object
54 55 56 |
# File 'lib/prkwars/player.rb', line 54 def shoot_left @shoot_vec_x = -Constants::BULLET_VELOCITY end |
#shoot_right ⇒ Object
58 59 60 |
# File 'lib/prkwars/player.rb', line 58 def shoot_right @shoot_vec_x = Constants::BULLET_VELOCITY end |
#shoot_up ⇒ Object
62 63 64 |
# File 'lib/prkwars/player.rb', line 62 def shoot_up @shoot_vec_y = -Constants::BULLET_VELOCITY end |
#update ⇒ Object
70 71 72 73 74 75 76 77 78 |
# File 'lib/prkwars/player.rb', line 70 def update rotate_player correct_coords(self, @gamespace) unless in_bounds(self, @gamespace) @shoot_timer += 1 return unless @shoot_timer == SHOOT_GAP shoot_bullet @shoot_timer = 0 end |