class SpaceInvaders::Block
Attributes
health[RW]
u_block[RW]
x_position[RW]
y_position[RW]
Public Class Methods
new(u_block, x_position, y_position)
click to toggle source
Calls superclass method
SpaceInvaders::Base::new
# File lib/space_invaders/blocks/block.rb, line 10 def initialize u_block, x_position, y_position super(u_block.app) @u_block = u_block @x_position = x_position @y_position = y_position @health = 3 set_image end
Public Instance Methods
dead?()
click to toggle source
# File lib/space_invaders/blocks/block.rb, line 40 def dead? health.zero? end
downgrade_image_or_die()
click to toggle source
# File lib/space_invaders/blocks/block.rb, line 44 def downgrade_image_or_die self.health -= 1 if health > 0 set_image else u_block.delete(self) end end
draw()
click to toggle source
# File lib/space_invaders/blocks/block.rb, line 24 def draw @image.draw x_position, y_position, 1 end
height()
click to toggle source
# File lib/space_invaders/blocks/block.rb, line 36 def height @image.height end
rival_bullets()
click to toggle source
# File lib/space_invaders/blocks/block.rb, line 28 def rival_bullets app.ship.bullets.bullets + app.invaders_container.bullets.bullets end
set_image()
click to toggle source
# File lib/space_invaders/blocks/block.rb, line 53 def set_image @image = case health when 3 then app.images.full_block when 2 then app.images.ok_block when 1 then app.images.weak_block end end
update()
click to toggle source
# File lib/space_invaders/blocks/block.rb, line 20 def update downgrade_image_or_die if collides_with? rival_bullets end
width()
click to toggle source
# File lib/space_invaders/blocks/block.rb, line 32 def width @image.width end