Exemple #1
0
    def move(self, poly):
        if self.frozen:
            return

        dot = (self.x, self.y)

        # check if we are still on the new poly, because if we are not, then
        # we will keep walking the old one until we get back on track
        if game_utils.on_line(dot, poly):
            self._polys_stack = [poly]
        else:
            if poly not in self._polys_stack:
                self._polys_stack.append(poly)

                if len(self._polys_stack) == 2:
                    self.show_confusion()

            # we go from the freshest to oldest poly to see if we can find ourselves
            for i, p in enumerate(reversed(self._polys_stack)):
                if game_utils.on_line(dot, p):
                    poly = p
                    break

        if not poly:
            return

        dot2 = None
        if dot in poly:
            dot2 = self.next(dot, poly)
        else:
            line = game_utils.on_line(dot, poly)
            if not line:
                return
            dot2 = line[1] if self.clockwise else line[0]


        # distance is sum because one of them will be the same

        speed = self.speed
        while speed > 0:
            distance = game_utils.distance(dot, dot2)
            direction = 1 if any ((a<b for a, b in zip(dot, dot2))) else -1

            step_speed = min(speed, distance)

            if dot[0] == dot2[0]:
                # vertical movement
                self.y += step_speed * direction
            else:
                # horizontal movement
                self.x += step_speed * direction

            distance = distance - step_speed
            if distance == 0:
                dot, dot2 = dot2, self.next(dot2, poly)

            speed = speed - step_speed

        self.current_line = game_utils.on_line((self.x, self.y), poly)
Exemple #2
0
    def check_death(self, claiming):
        x, y = self.cube.x, self.cube.y
        if not claiming:
            # while not claiming beware of sparks
            for spark in self.sparks:
                if set(spark.current_line or []) & set(self.cube.current_line or []):
                    if game_utils.distance((x, y), (spark.x, spark.y)) < 10:
                        # on spark collision spark dies
                        self.sparks.remove(spark)
                        spark.parent.remove_child(spark)
                        return True

        else:
            # while claiming beware of Qix
            for qix in self.qix:
                if game_utils.distance((x, y), (qix.x, qix.y)) < 20:
                    return True

                if qix.touching_poly(self.current_polygon + [(self.cube.x, self.cube.y)]):
                    return True
        return False