Class: SpaceInvaders::Bullet
- Defined in:
- lib/space_invaders/bullets/bullet.rb
Instance Attribute Summary collapse
-
#bullet_collection ⇒ Object
readonly
Returns the value of attribute bullet_collection.
-
#bullet_offset ⇒ Object
readonly
Returns the value of attribute bullet_offset.
-
#fireing_vehicle ⇒ Object
readonly
Returns the value of attribute fireing_vehicle.
-
#going_down ⇒ Object
(also: #going_down?)
readonly
Returns the value of attribute going_down.
-
#image ⇒ Object
readonly
Returns the value of attribute image.
-
#x_position ⇒ Object
readonly
Returns the value of attribute x_position.
-
#y_position ⇒ Object
readonly
Returns the value of attribute y_position.
Attributes inherited from Base
Instance Method Summary collapse
- #delete ⇒ Object
- #draw ⇒ Object
-
#initialize(fireing_vehicle, going_down, bullet_collection, bullet_offset = 10) ⇒ Bullet
constructor
A new instance of Bullet.
- #out_of_screen ⇒ Object
- #set_position ⇒ Object
- #update ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(fireing_vehicle, going_down, bullet_collection, bullet_offset = 10) ⇒ Bullet
Returns a new instance of Bullet.
8 9 10 11 12 13 14 15 16 17 |
# 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 |
Instance Attribute Details
#bullet_collection ⇒ Object (readonly)
Returns the value of attribute bullet_collection.
4 5 6 |
# File 'lib/space_invaders/bullets/bullet.rb', line 4 def bullet_collection @bullet_collection end |
#bullet_offset ⇒ Object (readonly)
Returns the value of attribute bullet_offset.
4 5 6 |
# File 'lib/space_invaders/bullets/bullet.rb', line 4 def bullet_offset @bullet_offset end |
#fireing_vehicle ⇒ Object (readonly)
Returns the value of attribute fireing_vehicle.
4 5 6 |
# File 'lib/space_invaders/bullets/bullet.rb', line 4 def fireing_vehicle @fireing_vehicle end |
#going_down ⇒ Object (readonly) Also known as: going_down?
Returns the value of attribute going_down.
4 5 6 |
# File 'lib/space_invaders/bullets/bullet.rb', line 4 def going_down @going_down end |
#image ⇒ Object (readonly)
Returns the value of attribute image.
4 5 6 |
# File 'lib/space_invaders/bullets/bullet.rb', line 4 def image @image end |
#x_position ⇒ Object (readonly)
Returns the value of attribute x_position.
4 5 6 |
# File 'lib/space_invaders/bullets/bullet.rb', line 4 def x_position @x_position end |
#y_position ⇒ Object (readonly)
Returns the value of attribute y_position.
4 5 6 |
# File 'lib/space_invaders/bullets/bullet.rb', line 4 def y_position @y_position end |
Instance Method Details
#delete ⇒ Object
27 28 29 |
# File 'lib/space_invaders/bullets/bullet.rb', line 27 def delete bullet_collection.delete(self) end |
#draw ⇒ Object
23 24 25 |
# File 'lib/space_invaders/bullets/bullet.rb', line 23 def draw image.draw x_position, y_position, 1 end |
#out_of_screen ⇒ Object
31 32 33 34 35 36 37 |
# 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 ⇒ Object
39 40 41 42 43 |
# 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 ⇒ Object
19 20 21 |
# File 'lib/space_invaders/bullets/bullet.rb', line 19 def update @y_position += going_down? ? bullet_offset : -bullet_offset end |