def update_cloud_distance(self): segment = b2.b2Segment() segment.p1 = self.body.position segment.p2 = self.game_screen.sun.position _, _, shape = self.game_screen.world.RaycastOne(segment, False, None) if shape is not None and isinstance(shape.GetBody().userData, Cloud): cloud_position = shape.GetBody().position self.cloud_distance = (self.body.position - cloud_position).Length() else: self.cloud_distance = 1000
def update_state(self): if (not self.immortal and (self.damage >= 1 or self.fatigue >= 1) or self.body.position.y <= 0): self.state = 'falling' elif pyglet.window.key.UP in self.keys: self.state = 'flying' else: # See if there's any ground beneath Icarus's feet. segment = b2.b2Segment() segment.p1 = self.body.position segment.p2 = segment.p1 + b2.b2Vec2(0, -0.6) _, _, shape = self.game_screen.world.RaycastOne(segment, False, None) if shape is not None and not shape.isSensor: if self.state not in ('standing', 'walking'): self.state = 'standing' else: self.state = 'flying'
def get_bodies_at_point(self, point): segment = b2.b2Segment() segment.p1 = tuple(point) segment.p2 = tuple(point) count, shapes = self.world.Raycast(segment, 1000, True, None) return list(set(s.GetBody() for s in shapes))