Class: Powerup

Inherits:
GameObject show all
Defined in:
lib/entities/powerups/powerup.rb

Instance Attribute Summary

Attributes inherited from GameObject

#components, #location, #x, #y

Instance Method Summary collapse

Methods inherited from GameObject

#collide, #draw, #effect?, #mark_for_removal, #move, #removable?, #update

Constructor Details

#initialize(object_pool, x, y) ⇒ Powerup

Returns a new instance of Powerup.



2
3
4
5
# File 'lib/entities/powerups/powerup.rb', line 2

def initialize(object_pool, x, y)
  super
  PowerupGraphics.new(self, graphics)
end

Instance Method Details

#boxObject



7
8
9
10
11
12
# File 'lib/entities/powerups/powerup.rb', line 7

def box
  [x - 8, y - 8,
   x + 8, y - 8,
   x + 8, y + 8,
   x - 8, y + 8]
end

#on_collision(object) ⇒ Object



14
15
16
17
18
19
# File 'lib/entities/powerups/powerup.rb', line 14

def on_collision(object)
  if pickup(object)
    PowerupSounds.play(object, object_pool.camera)
    remove
  end
end

#pickup(object) ⇒ Object



21
22
23
# File 'lib/entities/powerups/powerup.rb', line 21

def pickup(object)
  # override and implement application
end

#removeObject



25
26
27
28
29
30
# File 'lib/entities/powerups/powerup.rb', line 25

def remove
  object_pool.powerup_respawn_queue.enqueue(
    respawn_delay,
    self.class, x, y)
  mark_for_removal
end

#respawn_delayObject



32
33
34
# File 'lib/entities/powerups/powerup.rb', line 32

def respawn_delay
  30
end