コード例 #1
0
 def test_two_octagons_dont_collide(self):
     oct_agent1 = StubAgentWithBoundaries(
         boundaries={intersect.Polygon : (intersect.makePolygonFromPoints(
                                             [(1, 2),
                                              (2, 1),
                                              (2, -1),
                                              (1, -2),
                                              (-1, -2),
                                              (-2, -1),
                                              (-2, 1),
                                              (-1, 2)]))},
         direction=0,
         position=(0, 0))
     oct_agent2 = StubAgentWithBoundaries(
         boundaries={intersect.Polygon : (intersect.makePolygonFromPoints(
                                             [(1, 2),
                                              (2, 1),
                                              (2, -1),
                                              (1, -2),
                                              (-1, -2),
                                              (-2, -1),
                                              (-2, 1),
                                              (-1, 2)]))},
         direction=0,
         position=(0, 14))
     self.assertFalse(intersect.collidesWith(
                         oct_agent1, 
                         oct_agent2))
コード例 #2
0
ファイル: tiles_world.py プロジェクト: krieghan/tiles
    def update(self, currentTime):
        if not self.current_time:
            self.current_time = currentTime
        timeElapsed = (currentTime - self.current_time)
        self.current_time = currentTime
        for canvasElement in list(self.getAllCanvasElements()):
            if not canvasElement.getActive():
                continue
            canvasElement.update(timeElapsed=timeElapsed)

        cleared_of_collisions = set([])

        for canvasElement in list(self.getAllCanvasElements()):
            for otherElement in list(self.getAllCanvasElements()):
                if canvasElement is otherElement:
                    continue

                # Don't double-count collisions when canvasElement
                # is reconsidered as otherElement
                if otherElement in cleared_of_collisions:
                    continue

                if intersect.collidesWith(canvasElement, otherElement):
                    canvasElement.handleCollision(otherElement)
                    otherElement.handleCollision(canvasElement)

            cleared_of_collisions.add(canvasElement)
コード例 #3
0
 def test_two_circles_dont_collide(self):
     circle_agent1 = StubAgentWithBoundaries(
             boundaries={intersect.Circle : ((0, 0), 1)},
             direction=0,
             position=(0, 0))
     circle_agent2 = StubAgentWithBoundaries(
             boundaries={intersect.Circle : ((0, 0), 1)},
             direction=0,
             position=(0, 2))
     self.assertFalse(intersect.collidesWith(
                         circle_agent1, 
                         circle_agent2))
コード例 #4
0
 def test_rectangle_collides_with_circle(self):
     rect_agent = StubAgentWithBoundaries(
             boundaries={intersect.Rectangle : (
                             (-1, 1),
                             (1, 1),
                             (1, -1),
                             (-1, -1))},
             direction=0,
             position=(0, 0))
     circle_agent = StubAgentWithBoundaries(
             boundaries={intersect.Circle : ((0, 0), 1)},
             direction=0,
             position=(0, 1))
     self.assertTrue(intersect.collidesWith(
                         rect_agent,
                         circle_agent))
コード例 #5
0
 def test_circle_inside_rectangle(self):
     rect_agent = StubAgentWithBoundaries(
             boundaries={intersect.Rectangle : (
                             (-100, 100),
                             (100, 100),
                             (100, -100),
                             (-100, -100))},
             direction=0,
             position=(0, 0))
     circle_agent = StubAgentWithBoundaries(
             boundaries={intersect.Circle : ((0, 0), 1)},
             direction=0,
             position=(0, 0))
     self.assertTrue(intersect.collidesWith(
                         circle_agent,
                         rect_agent))
コード例 #6
0
 def test_identical_rectangles_collide(self):
     rect_agent1 = StubAgentWithBoundaries(
             boundaries={intersect.Rectangle : (
                             (0, 0),
                             (1, 0),
                             (1, 1),
                             (0, 1))},
             direction=0,
             position=(0, 0))
     rect_agent2 = StubAgentWithBoundaries(
             boundaries={intersect.Rectangle : (
                             (0, 0),
                             (1, 0),
                             (1, 1),
                             (0, 1))},
             direction=0,
             position=(0, 0))
     self.assertTrue(intersect.collidesWith(
                         rect_agent1, 
                         rect_agent2))
コード例 #7
0
 def test_two_rectangles_do_not_collide(self):
     rect_agent1 = StubAgentWithBoundaries(
             boundaries={intersect.Rectangle : (
                             (0, 0),
                             (1, 0),
                             (1, 1),
                             (0, 1))},
             direction=0,
             position=(0, 0))
     rect_agent2 = StubAgentWithBoundaries(
             boundaries={intersect.Rectangle : (
                             (0, 0),
                             (1, 0),
                             (1, 1),
                             (0, 1))},
             direction=0,
             position=(2, 2))
     self.assertFalse(intersect.collidesWith(
                         rect_agent1, 
                         rect_agent2))