Class: Asteroids::Ship
- Inherits:
-
GameObject
- Object
- GameObject
- Asteroids::Ship
- Defined in:
- lib/asteroids/ship/ship.rb
Constant Summary collapse
- SHOOT_DELAY =
600
Instance Attribute Summary collapse
-
#angle ⇒ Object
Returns the value of attribute angle.
-
#lives ⇒ Object
Returns the value of attribute lives.
-
#radius ⇒ Object
Returns the value of attribute radius.
-
#score ⇒ Object
Returns the value of attribute score.
-
#thrust ⇒ Object
Returns the value of attribute thrust.
-
#vel_x ⇒ Object
Returns the value of attribute vel_x.
-
#vel_y ⇒ Object
Returns the value of attribute vel_y.
-
#x ⇒ Object
Returns the value of attribute x.
-
#y ⇒ Object
Returns the value of attribute y.
Instance Method Summary collapse
- #add_score(points) ⇒ Object
- #can_shoot? ⇒ Boolean
- #explode ⇒ Object
-
#initialize(object_pool) ⇒ Ship
constructor
A new instance of Ship.
- #is_alive? ⇒ Boolean
- #shoot ⇒ Object
- #spawn ⇒ Object
Methods inherited from GameObject
#components, #draw, #mark_for_removal, #removable?, #update
Constructor Details
#initialize(object_pool) ⇒ Ship
Returns a new instance of Ship.
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/asteroids/ship/ship.rb', line 9 def initialize(object_pool) super(object_pool) @physics = ShipPhysics.new(self, object_pool) @graphics = ShipGraphics.new(self) @vel_x = @vel_y = @angle = 0.0 @radius = 35 @lives = 3 @score = 0 @object_pool = object_pool end |
Instance Attribute Details
#angle ⇒ Object
Returns the value of attribute angle.
6 7 8 |
# File 'lib/asteroids/ship/ship.rb', line 6 def angle @angle end |
#lives ⇒ Object
Returns the value of attribute lives.
6 7 8 |
# File 'lib/asteroids/ship/ship.rb', line 6 def lives @lives end |
#radius ⇒ Object
Returns the value of attribute radius.
6 7 8 |
# File 'lib/asteroids/ship/ship.rb', line 6 def radius @radius end |
#score ⇒ Object
Returns the value of attribute score.
6 7 8 |
# File 'lib/asteroids/ship/ship.rb', line 6 def score @score end |
#thrust ⇒ Object
Returns the value of attribute thrust.
6 7 8 |
# File 'lib/asteroids/ship/ship.rb', line 6 def thrust @thrust end |
#vel_x ⇒ Object
Returns the value of attribute vel_x.
6 7 8 |
# File 'lib/asteroids/ship/ship.rb', line 6 def vel_x @vel_x end |
#vel_y ⇒ Object
Returns the value of attribute vel_y.
6 7 8 |
# File 'lib/asteroids/ship/ship.rb', line 6 def vel_y @vel_y end |
#x ⇒ Object
Returns the value of attribute x.
6 7 8 |
# File 'lib/asteroids/ship/ship.rb', line 6 def x @x end |
#y ⇒ Object
Returns the value of attribute y.
6 7 8 |
# File 'lib/asteroids/ship/ship.rb', line 6 def y @y end |
Instance Method Details
#add_score(points) ⇒ Object
46 47 48 |
# File 'lib/asteroids/ship/ship.rb', line 46 def add_score(points) @score += points end |
#can_shoot? ⇒ Boolean
27 28 29 |
# File 'lib/asteroids/ship/ship.rb', line 27 def can_shoot? Gosu.milliseconds - (@last_shot || 0) > SHOOT_DELAY end |
#explode ⇒ Object
31 32 33 34 35 |
# File 'lib/asteroids/ship/ship.rb', line 31 def explode Explosion.new(object_pool, @x, @y) @lives -= 1 spawn end |
#is_alive? ⇒ Boolean
37 38 39 |
# File 'lib/asteroids/ship/ship.rb', line 37 def is_alive? return true if @lives != 0 or @lives > 0 end |
#shoot ⇒ Object
20 21 22 23 24 25 |
# File 'lib/asteroids/ship/ship.rb', line 20 def shoot if can_shoot? @last_shot = Gosu.milliseconds Missile.new(self, object_pool, @x, @y, @vel_x, @vel_y, @angle) end end |
#spawn ⇒ Object
41 42 43 44 |
# File 'lib/asteroids/ship/ship.rb', line 41 def spawn @x = object_pool.find_empty_space[:x] @y = object_pool.find_empty_space[:y] end |