def get_chunks_from_entity_location(self, entity: Entity) -> List[ColliderChunk]: _aabb = entity.get_component(Collider_AABB_2D) if _aabb is not None: return self.get_chunks_from_collider_aabb_2d(_aabb) _circle = entity.get_component(Collider_Circle_2D) if _circle is not None: print('process collision error 101') return list(None)
def process_collision(self, _entity: Entity, _others: List[Entity]): # Rigidbody Check _rigidbody: Rigidbody = _entity.get_component(Rigidbody) # Do nothing if ignoring both colliders if _rigidbody.ignore_static_colliders and _rigidbody.ignore_dynamic_colliders: return # Begin _entity.process_collision_start() # Create list of all possible entities in region _megalist: List[Entity] = [] # Static Collision if not _rigidbody.ignore_static_colliders: _chunks: List[ ColliderChunk] = self.get_chunks_from_entity_location(_entity) for c in _chunks: _megalist += c.get_entities() # Dynamic Collision if not _rigidbody.ignore_dynamic_colliders: _megalist += _others # Process all those entities # print('ent:', _entity.name, ' checking: ', len(_megalist)) _entity.process_collision_list(_megalist) # End _entity.process_collision_end()
def add_entity(self, _ent: Entity): if _ent is None: return # Add static collider if no rigidbody is present ColliderManager_2D.get_singleton().add(_ent) # Add to list of all entities self._entities[_ent.name] = _ent # Add to list of ordered entities _depth: int = _ent.get_layer() if _depth not in self._entities_ordered: # Create empty slot self._entities_ordered[_depth] = [] # Add entity to sorted list self._entities_ordered[_depth].append(_ent) # Sort Dictionary self._entities_ordered = OrderedDict( sorted(self._entities_ordered.items(), key=lambda t: t[0])) else: # Add entity to sorted list self._entities_ordered[_depth].append(_ent) # Add to dynamic entities if _ent.get_component(Rigidbody) is not None: self._dynamic_entities[_ent.name] = _ent
def add_entity(self, entity: Entity): # Make sure it has a sprite _spr = entity.get_component(Sprite) if _spr is not None: self._entities.append(entity) self._sprites_ref.append(_spr) else: print( 'cannot add entity to sprite batch because its missing a sprite', entity) return self
def add(self, ent: Entity): _rigid = ent.get_component(Rigidbody) # Static Collider if _rigid is None: # Check Types _aabb = ent.get_component(Collider_AABB_2D) _circle = ent.get_component(Collider_Circle_2D) # Add Collider based on type if _aabb is not None: _chunks = self.get_chunks_from_collider_aabb_2d(_aabb) for i in _chunks: i.add_entity(ent) elif _circle is not None: _chunks = self.get_chunks_from_square_region_unsafe( _circle.get_position().get_vec2(), Vector2(_circle.radius * 2.0, _circle.radius * 2.0)) for i in _chunks: i.add_entity(ent)
def remove_entity(self, _ent: Entity): # ENTITY deletion flag _ent.deleted = True # Check for entity existence and delete it from any of the following containers if _ent in self._entities.values(): self._entities.pop(_ent.name, None) _ordered_list: List[Entity] = self._entities_ordered[_ent.get_layer()] if _ent in _ordered_list: self._entities_ordered[_ent.get_layer()].remove(_ent) if _ent.get_component( Rigidbody ) is not None and _ent in self._dynamic_entities.values(): self._dynamic_entities.pop(_ent.name, None)