Class: PowerupRespawnQueue

Inherits:
Object
  • Object
show all
Defined in:
lib/entities/powerups/powerup_respawn_queue.rb

Constant Summary collapse

RESPAWN_DELAY =
1000

Instance Method Summary collapse

Constructor Details

#initializePowerupRespawnQueue

Returns a new instance of PowerupRespawnQueue.



3
4
5
6
# File 'lib/entities/powerups/powerup_respawn_queue.rb', line 3

def initialize
  @respawn_queue = {}
  @last_respawn = Gosu.milliseconds
end

Instance Method Details

#enqueue(delay_seconds, type, x, y) ⇒ Object



8
9
10
11
# File 'lib/entities/powerups/powerup_respawn_queue.rb', line 8

def enqueue(delay_seconds, type, x, y)
  respawn_at = Gosu.milliseconds + delay_seconds * 1000
  @respawn_queue[respawn_at.to_i] = [type, x, y]
end

#respawn(object_pool) ⇒ Object



13
14
15
16
17
18
19
20
21
22
# File 'lib/entities/powerups/powerup_respawn_queue.rb', line 13

def respawn(object_pool)
  now = Gosu.milliseconds
  return if now - @last_respawn < RESPAWN_DELAY
  @respawn_queue.keys.each do |k|
    next if k > now # not yet
    type, x, y = @respawn_queue.delete(k)
    type.new(object_pool, x, y)
  end
  @last_respawn = now
end