コード例 #1
0
 def test_no_stuck(self, generic_id, tilemap, start_rect, dx, dy, expect_dxdy):
     collider = RectMapCollider()
     new = start_rect.copy()
     new.x += dx
     new.y += dy
     new_dx, new_dy = collider.collide_map(tilemap, start_rect, new, dy, dx)
     assert new.position == (start_rect.x + expect_dxdy[0],
                             start_rect.y + expect_dxdy[1])
コード例 #2
0
 def test_no_stuck(self, generic_id, tilemap, start_rect, dx, dy, expect_dxdy):
     collider = RectMapCollider()
     new = start_rect.copy()
     new.x += dx
     new.y += dy
     new_dx, new_dy = collider.collide_map(tilemap, start_rect, new, dx, dy)
     assert new.position == (start_rect.x + expect_dxdy[0],
                             start_rect.y + expect_dxdy[1])
     # uncomment if changed behavior in RectMapCollider 
     assert (new_dx, new_dy) == expect_dxdy
コード例 #3
0
 def test_no_stuck(self, generic_id, tilemap, start_rect, dx, dy,
                   expect_dxdy):
     collider = RectMapCollider()
     new = start_rect.copy()
     new.x += dx
     new.y += dy
     new_dx, new_dy = collider.collide_map(tilemap, start_rect, new, dx, dy)
     assert new.position == (start_rect.x + expect_dxdy[0],
                             start_rect.y + expect_dxdy[1])
     # uncomment if changed behavior in RectMapCollider
     assert (new_dx, new_dy) == expect_dxdy
コード例 #4
0
    def change(self, delta):        
        if self.current_tilemap is not None:
            # ? unrelated to collision, but seen some strange:
            # if not removing the sprites opacity intensifies, like if the
            # associated triangles were not removed
            self.current_tilemap.remove(self.view_start)
            self.current_tilemap.remove(self.view_new)
            self.current_tilemap.remove(self.view_expected)
            self.scroller.remove(self.current_tilemap)
            print("num active tilemaps:", len(self.scroller.children))
            self.iCase = (self.iCase + delta) % len(self.cases)
        else:
            self.iCase = 0
        case = self.cases[self.iCase]
        generic_id = case['generic_id']
        tilemap = case['tilemap']
        start_rect = case['start_rect']
        dx = case['dx']
        dy = case['dy']
        expect_dxdy = case['expect_dxdy']

        s = "dxdy: %s, %s ep_dxdy: %s" % (dx, dy, expect_dxdy)
        self.label.element.text = s

        self.current_tilemap = tilemap

        # calc as in test_no_stuck
        collider = RectMapCollider()
        new = start_rect.copy()
        new.x += dx
        new.y += dy
        new_dx, new_dy = collider.collide_map(tilemap, start_rect, new, dy, dx)
        expected = start_rect.copy()
        expected.position = (expected.x + expect_dxdy[0],
                             expected.y + expect_dxdy[1])

        # update the view
        self.scroller.add(tilemap)
        self.view_start.position = start_rect.position
        self.view_new.position = new.position
        self.view_expected.position = expected.position
        tilemap.add(self.view_start, z=1)
        tilemap.add(self.view_new, z=2)
        tilemap.add(self.view_expected, z=3)
        tilemap.add(self.label, z=4)
コード例 #5
0
    def __init__(self, map_layers):
        CollisionManager.__init__(self, **constants.collision_params)
        RectMapCollider.__init__(self)

        self.map_layers = map_layers