| |
Methods defined here:
- __contains__(self, obj)
- __init__(self, cell_size=50)
- __iter__(self)
- This method honors self.sort_key.
- __len__(self)
- __repr__(self)
- __str__(self)
- add(self, entity)
- Add or re-add obj. Return True if in bounds, else return False.
If this method returns False then the object is completely out of
bounds and cannot be stored in this space.
Note that when obj changes its position, you must add it again so that
its cell membership is updated. This method first removes the object if
it is already in the spatial hash.
- addlist(self, entities)
- clear(self)
- Clear all objects.
- collide(self, entity)
- Return list of entities that collide with entity.
- collidealldict(self, rect=None)
- Return dict of all collisions.
If rect is specified, only the cells that intersect rect will be
checked.
The contents of the returned dict are: {entity: [entity, ...}
- collideany(self, entity)
- Return True if entity collides with any other object, else False.
- collidedict(self, entities)
- Return dict of entities that collide with entities.
- get_cell(self, cell_id)
- Return the cell stored at bucket index cell_id.
The returned cell is a list of entities. None is returned if a cell does
not exist for cell_id.
- get_cell_pos(self, cell_id)
- Return the world coordinates for topleft corner of cell.
- get_nearby_entities(self, entity)
- Return a list of entities that share the same cells as entity.
This method honors self.sort_key.
- index(self, cell)
- Return the bucket index of cell.
Returns None if cell does not exist in buckets.
Note that SpatialHash.buckets.index(cell) does *NOT* work because
list.index() tests equality, not identity.
- index_at(self, x, y)
- Return the cell_id of the cell that contains point (x,y).
None is returned if point (x,y) is not in bounds.
- intersect_cell_ids(self, rect)
- Return list of cell ids that intersect rect.
The return value is a list of int. Each int is a key for self.buckets. Note: the values are NOT checked for
presence in buckets; so if self.buckets[i] is accessed directly, empty buckets may be accidentally created.
:param rect: pygame.Rect; bounding rect
:return: list of int
- intersect_entities(self, rect)
- Return list of entities whose rects intersect rect.
This method honors self.sort_key.
- remove(self, entity)
- removelist(self, entities)
Data descriptors defined here:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
- entities
- Return the entire list of entities.
This method honors self.sort_key.
|