예제 #1
0
파일: pong.py 프로젝트: derchrisuk/flipdots
    def bounce(self, players, boundaries):
        lower_left = self.lower_left()
        upper_right = self.upper_right()

        if lower_left[1] <= 0 or upper_right[1] >= boundaries[1]:
            self.mirror_direction_y()

        player_boundaries = players[0].get_boundaries()
        if self.direction[0] < 0 and overlaps(
            (self.prev_center[0], self.center[0] - 1),
            (player_boundaries[0][0], player_boundaries[1][0])) and overlaps(
                (lower_left[1], upper_right[1]),
                (player_boundaries[0][1], player_boundaries[1][1])):
            self.mirror_direction_x()
            if players[0].direction == (0, 1):
                self.change_direction(
                    fliputils.addVector(self.direction, (1, 1)))
            elif players[0].direction == (0, -1):
                self.change_direction(
                    fliputils.addVector(self.direction, (1, -1)))

        player_boundaries = players[1].get_boundaries()
        if self.direction[0] > 0 and overlaps(
            (self.prev_center[0], self.center[0] + 1),
            (player_boundaries[0][0], player_boundaries[1][0])) and overlaps(
                (lower_left[1], upper_right[1]),
                (player_boundaries[0][1], player_boundaries[1][1])):
            self.mirror_direction_x()
            if players[1].direction == (0, 1):
                self.change_direction(
                    fliputils.addVector(self.direction, (-1, 1)))
            elif players[1].direction == (0, -1):
                self.change_direction(
                    fliputils.addVector(self.direction, (-1, -1)))
예제 #2
0
파일: pong.py 프로젝트: derchrisuk/flipdots
    def move(self, boundaries):
        nv = fliputils.normVector(self.direction)
        self.prev_center = self.center
        self.center = fliputils.addVector(
            self.center, fliputils.multiplyVector(nv, self.speed))

        lower_left = self.lower_left()
        if lower_left[0] < 0:
            self.center = fliputils.addVector(
                self.center,
                fliputils.multiplyVector((1, 0), abs(lower_left[0])))
        if lower_left[1] < 0:
            self.center = fliputils.addVector(
                self.center,
                fliputils.multiplyVector((0, 1), abs(lower_left[1])))

        upper_right = self.upper_right()
        if upper_right[0] > boundaries[0]:
            self.center = fliputils.addVector(
                self.center,
                fliputils.multiplyVector((-1, 0),
                                         upper_right[0] - boundaries[0]))
        if upper_right[1] > boundaries[1]:
            self.center = fliputils.addVector(
                self.center,
                fliputils.multiplyVector((0, -1),
                                         upper_right[1] - boundaries[1]))

        self.direction = nv
예제 #3
0
파일: race.py 프로젝트: muccc/flipdots
    def inScope(self, x, y, z):
        vector = fliputils.subVector((x,y,z), self.camera)
        vector = fliputils.normVector(vector)

        try:
            factor = (self.sizez - self.camera[2]) / vector[2]
        except ZeroDivisionError:
            return None

        endvector = fliputils.addVector(self.camera, fliputils.multiplyVector(vector, factor))

        if self.plain_offset[0] <= endvector[0] and self.plain_offset[0] + self.sizex > endvector[0] + 1 and self.plain_offset[1] <= endvector[1] and self.plain_offset[1] + self.sizey > endvector[1] + 1:
            return (int(round(endvector[0]-self.plain_offset[0])),int(round(endvector[1]-self.plain_offset[1])))

        return None
예제 #4
0
    def inScope(self, x, y, z):
        vector = fliputils.subVector((x, y, z), self.camera)
        vector = fliputils.normVector(vector)

        try:
            factor = (self.sizez - self.camera[2]) / vector[2]
        except ZeroDivisionError:
            return None

        endvector = fliputils.addVector(
            self.camera, fliputils.multiplyVector(vector, factor))

        if self.plain_offset[0] <= endvector[0] and self.plain_offset[
                0] + self.sizex > endvector[0] + 1 and self.plain_offset[
                    1] <= endvector[1] and self.plain_offset[
                        1] + self.sizey > endvector[1] + 1:
            return (int(round(endvector[0] - self.plain_offset[0])),
                    int(round(endvector[1] - self.plain_offset[1])))

        return None