class SpaceInvaders::Bullet

Attributes

bullet_collection[R]
bullet_offset[R]
fireing_vehicle[R]
going_down[R]
going_down?[R]
image[R]
x_position[R]
y_position[R]

Public Class Methods

new(fireing_vehicle, going_down, bullet_collection, bullet_offset=10) click to toggle source
Calls superclass method SpaceInvaders::Base::new
# File lib/space_invaders/bullets/bullet.rb, line 8
def initialize fireing_vehicle, going_down, bullet_collection, bullet_offset=10
  super(fireing_vehicle.app)
  @fireing_vehicle = fireing_vehicle
  @image = app.images.bullet
  @bullet_offset = bullet_offset
  @going_down = going_down
  @bullet_collection = bullet_collection
  @bullet_collection << self
  set_position
end

Public Instance Methods

delete() click to toggle source
# File lib/space_invaders/bullets/bullet.rb, line 27
def delete
  bullet_collection.delete(self)
end
draw() click to toggle source
# File lib/space_invaders/bullets/bullet.rb, line 23
def draw
  image.draw x_position, y_position, 1
end
out_of_screen() click to toggle source
# File lib/space_invaders/bullets/bullet.rb, line 31
def out_of_screen
  if going_down
    y_position > app.height
  else
    y_position < 0
  end
end
set_position() click to toggle source
# File lib/space_invaders/bullets/bullet.rb, line 39
def set_position
  @x_position = fireing_vehicle.x_middle - image.width/2
  @y_position = fireing_vehicle.y_position
  @y_position += fireing_vehicle.height if going_down
end
update() click to toggle source
# File lib/space_invaders/bullets/bullet.rb, line 19
def update
  @y_position += going_down? ? bullet_offset : -bullet_offset
end