class ObjectPool
Attributes
camera[RW]
map[RW]
objects[RW]
powerup_respawn_queue[RW]
Public Class Methods
new(box)
click to toggle source
# File lib/entities/object_pool.rb, line 8 def initialize(box) @tree = QuadTree.new(box) @powerup_respawn_queue = PowerupRespawnQueue.new @objects = [] end
Public Instance Methods
add(object)
click to toggle source
# File lib/entities/object_pool.rb, line 14 def add(object) @objects << object @tree.insert(object) end
nearby(object, max_distance)
click to toggle source
# File lib/entities/object_pool.rb, line 51 def nearby(object, max_distance) cx, cy = object.location nearby_point(cx, cy, max_distance, object) end
nearby_point(cx, cy, max_distance, object = nil)
click to toggle source
# File lib/entities/object_pool.rb, line 38 def nearby_point(cx, cy, max_distance, object = nil) hx, hy = cx + max_distance, cy + max_distance # Fast, rough results results = @tree.query_range( AxisAlignedBoundingBox.new([cx, cy], [hx, hy])) # Sift through to select fine-grained results results.select do |o| o != object && Utils.distance_between( o.x, o.y, cx, cy) <= max_distance end end
query_range(box)
click to toggle source
# File lib/entities/object_pool.rb, line 56 def query_range(box) @tree.query_range(box) end
size()
click to toggle source
# File lib/entities/object_pool.rb, line 4 def size @objects.size end
tree_insert(object)
click to toggle source
# File lib/entities/object_pool.rb, line 23 def tree_insert(object) @tree.insert(object) end
tree_remove(object)
click to toggle source
# File lib/entities/object_pool.rb, line 19 def tree_remove(object) @tree.remove(object) end
update_all()
click to toggle source
# File lib/entities/object_pool.rb, line 27 def update_all @objects.each(&:update) @objects.reject! do |o| if o.removable? @tree.remove(o) true end end @powerup_respawn_queue.respawn(self) end