I want to check if a bullet has collided with my lines to keep the player from moving outside the screen.
Here's my lines
def create_lines():
"""Prevent objects from moving out of the screen"""
static_lines = [
pymunk.Segment(space.static_body, (0,0), (current_map.width,0), 0.0),
pymunk.Segment(space.static_body, (current_map.width,0), (current_map.width,current_map.height), 0.0),
pymunk.Segment(space.static_body, (current_map.width,current_map.height), (0,current_map.height), 0.0),
pymunk.Segment(space.static_body, (0,current_map.height), (0,0), 0.0)]
space.add(static_lines)
Here's my collision code
def collision_bullet_line(arb, space, data):
bullet = arb.shapes[0]
line = arb.shapes[1]
print('collision line!!')
handler = space.add_collision_handler(1, 5)
handler.pre_solve = collision_bullet_line
I want to avoid creating a class but I can do it like this; but it doesn't work.. maybe I can set collision type somewhere else? Any help appreciated.
class Line(GamePhysicsObject):
""" This class extends the GamePhysicsObject to handle box objects. """
def __init__(self, x, y, sprite, space):
super().__init__(x , y, 0, sprite, space)
self.shape.collision_type = 5