def collision(self, bolt): """ Returns: True if the bolt was fired by the player and collides with this alien Suggestion to make all points Point2 objects by Caleb Berman (ckb65). Parameter bolt: The laser bolt to check Precondition: bolt is of class Bolt """ assert isinstance(bolt, Bolt) if bolt.isPlayerBolt(): if self.contains(Point2(bolt.x - BOLT_WIDTH/2, bolt.y + BOLT_HEIGHT/2)) or \ self.contains(Point2(bolt.x - BOLT_WIDTH/2, bolt.y - BOLT_HEIGHT/2)) or \ self.contains(Point2(bolt.x + BOLT_WIDTH/2, bolt.y + BOLT_HEIGHT/2)) or \ self.contains(Point2(bolt.x + BOLT_WIDTH/2, bolt.y - BOLT_HEIGHT/2)): return True
def touch(self): """ The current (x,y) coordinate of the mouse, if pressed. This method only returns coordinates if the mouse button is pressed. If the mouse button is not pressed it returns None. The origin (0,0) corresponds to the bottom left corner of the application window. There is currently no way to get the location of the mouse when the button is not pressed. This a limitation of Kivy. **Immutable**: This value cannot be altered. **Invariant**: Must be either a :class:`Point2` or None (if there is no touch). """ if self._touch is None: return None return Point2(self._touch.x / dp(1), self._touch.y / dp(1))
def transform(self, point): """ Transforms the point to the local coordinate system This method is important for mouse selection. It helps you understand where in the shape the selection takes place. In the case of objects with children, like :class:`GScene`, this method is necessary to properly use the contains method on the children. :param point: the point to transform :type point: :class:`Point2` or a pair of numbers :return: The point transformed to local coordinate system :rtype: :class:`Point2` """ if isinstance(point, Point2): return self.inverse.transform(point) else: assert is_num_tuple(point, 2), "%s is not a valid point" % repr(point) p = self.inverse._transform(point[0], point[2]) return Point2(p[0], p[1])