Esempio n. 1
0
    def move_many(self,
                  objects: typing.List['ObjectBase'],
                  x,
                  y,
                  fire_onscreen_event: bool = True,
                  static: typing.List['ObjectBase'] = None):
        """
        Moves many objects by a factor of x, and y
        :param objects: The list of objects to move
        :param x: The distance (in pixels) to move each object by along the x axis
        :param y: The distance (in pixels) to move each object by along the y axis
        :param fire_onscreen_event: If the "onscreen" event should be fired if an object moves on screen while being moved
        :param static: The list of objects which each object that is moving should check collision against. If not specified, use all objects. If there is collision, all movement will be undone  
        """
        if static is None:
            static = self.props

        abort = False
        for p in objects:
            p.move(x, y, fire_onscreen_event)
            for s in static:
                if rect_a_touch_b(p.rect, s.rect):
                    abort = True

        if abort:
            for p in objects:
                p.undo_last_move()
Esempio n. 2
0
 def collision_detecion(self, objects: typing.List['ObjectBase']):
     """
     Checks collision between this object, and a list of other objects.
     If collision is detected, the "oncollide" event of both objects is run
     :param objects: The list of objects to check
     """
     for obj in objects:
         if rect_a_touch_b(self.rect, obj.rect):
             self.oncollide(obj)
             obj.oncollide(self)
Esempio n. 3
0
 def is_touching_type(self, model:str):
     """
     Checks if this object is touching another object of a specified type (from a specified Class)
     NOTE: Will NOT fire the "oncollide" event
     :param model: The name of the type/class to check against
     :return: If there is colloision
     """
     for obj in self.parent.props.array:
         if obj.model_type == model:
             if rect_a_touch_b(self.rect, obj.rect):
                 return True
     return False
Esempio n. 4
0
 def get_touching_type(self, model:str):
     """
     returns all of the objects which are of the specified model, and are touching this object
     NOTE: Will NOT fire the "oncollide" event
     :param model: The name of the type/class to check against
     :return: the collided objects
     """
     touching = []
     for obj in self.parent.props.array:
         if obj.model_type == model and obj != self:
             if rect_a_touch_b(self.rect, obj.rect):
                 touching.append(obj)
     return touching
Esempio n. 5
0
 def is_onscreen(self):
     """
     Returns if this object is in any way touching the screen
     """
     return rect_a_touch_b(self.rect, (0, 0, self.screen_w, self.screen_h))
Esempio n. 6
0
 def is_onscreen(self):
     """
     Returns if this object is completly on the screen
     """
     return rect_a_touch_b(self.rect, (0, 0, self.screen_w, self.screen_h))