class Asteroids::Ship

Constants

SHOOT_DELAY

Attributes

angle[RW]
lives[RW]
radius[RW]
score[RW]
thrust[RW]
vel_x[RW]
vel_y[RW]
x[RW]
y[RW]

Public Class Methods

new(object_pool) click to toggle source
Calls superclass method Asteroids::GameObject::new
# 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

Public Instance Methods

add_score(points) click to toggle source
# File lib/asteroids/ship/ship.rb, line 46
def add_score(points)
  @score += points
end
can_shoot?() click to toggle source
# File lib/asteroids/ship/ship.rb, line 27
 def can_shoot?
  Gosu.milliseconds - (@last_shot || 0) > SHOOT_DELAY
end
explode() click to toggle source
# File lib/asteroids/ship/ship.rb, line 31
def explode
  Explosion.new(object_pool, @x, @y)
  @lives -= 1
  spawn
end
is_alive?() click to toggle source
# File lib/asteroids/ship/ship.rb, line 37
def is_alive?
  return true if @lives != 0 or @lives > 0
end
shoot() click to toggle source
# 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() click to toggle source
# 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