def fill_entity_dict(): entity_index_map = {} index = 0 for k in Entity.get_entity_size_dict().keys(): if not str(k).endswith("remnants"): entity_index_map[str(k)] = index index += 1 return entity_index_map
def _get_entity_index_dicts() -> Tuple[dict, dict]: entity_index_map = {} reverse_index_map = {} index = 0 for k in Entity.get_entity_size_dict().keys(): if not str(k).endswith("remnants"): entity_index_map[str(k)] = index reverse_index_map[index] = str(k) index += 1 return entity_index_map, reverse_index_map
def add_entity(self, entity: Entity): mask = entity.get_collision_mask() bl, tl, br, tr = entity.bounding_box x_offset = int(tl[0] - self.x_offset) y_offset = int(tl[1] - self.y_offset) if np.all(mask): self.grid[y_offset:y_offset + mask.shape[0], x_offset:x_offset + mask.shape[1]] = entity else: obj_mask = np.ma.masked_where( ~mask, np.full(mask.shape, entity, dtype=Entity)) self.grid[y_offset:y_offset + mask.shape[0], x_offset:x_offset + mask.shape[1]][~obj_mask.mask] = np.ma.compressed( obj_mask)
def test_round_to_corrected_halve(self): self.assertEqual(0.5, Entity._round_to_corrected_halve(0)) self.assertEqual(0.5, Entity._round_to_corrected_halve(0.2)) self.assertEqual(0.5, Entity._round_to_corrected_halve(0.4)) self.assertEqual(0.5, Entity._round_to_corrected_halve(0.6)) self.assertEqual(0.5, Entity._round_to_corrected_halve(0.8)) self.assertEqual(0.5, Entity._round_to_corrected_halve(0.99)) self.assertEqual(1.5, Entity._round_to_corrected_halve(1)) self.assertEqual(1.5, Entity._round_to_corrected_halve(1.1)) self.assertEqual(1.5, Entity._round_to_corrected_halve(1.5)) self.assertEqual(1.5, Entity._round_to_corrected_halve(1.99)) self.assertEqual(2.5, Entity._round_to_corrected_halve(2)) self.assertEqual(-0.5, Entity._round_to_corrected_halve(-0.2)) self.assertEqual(-0.5, Entity._round_to_corrected_halve(-0.4)) self.assertEqual(-0.5, Entity._round_to_corrected_halve(-0.6)) self.assertEqual(-0.5, Entity._round_to_corrected_halve(-0.8)) self.assertEqual(-0.5, Entity._round_to_corrected_halve(-0.99)) self.assertEqual(-0.5, Entity._round_to_corrected_halve(-1)) self.assertEqual(-1.5, Entity._round_to_corrected_halve(-1.5)) self.assertEqual(-1.5, Entity._round_to_corrected_halve(-1.99)) self.assertEqual(-1.5, Entity._round_to_corrected_halve(-2)) self.assertEqual(-2.5, Entity._round_to_corrected_halve(-2.1))
def test_round_corrected(self): self.assertEqual(0, Entity._round_corrected(-0.5)) self.assertEqual(1, Entity._round_corrected(0.5))
def get_entity(entity_name: str, x: float, y: float, direction: int = 0) -> Entity: return Entity(**get_entity_dict(entity_name, x, y, direction=direction))
def _create_entity(entity_dict: EntityDict): if entity_dict["name"] == "curved-rail": return CurvedRailEntity(**entity_dict) return Entity(**entity_dict)