示例#1
0
 def test_hex_dimensions(self):
     m = gen_hex_map([[{'a':'a'}]], 32)
     assert m.pxw, m.pxh == (36, 32)
     m = gen_hex_map([[{'a':'a'}]*2], 32)
     assert m.pxw, m.pxh == (36, 64)
     m = gen_hex_map([[{'a':'a'}]]*2, 32)
     assert m.pxw, m.pxh == (63, 48)
示例#2
0
 def test_hex_dimensions(self):
     m = gen_hex_map([[{'a': 'a'}]], 32)
     assert m.pxw, m.pxh == (36, 32)
     m = gen_hex_map([[{'a': 'a'}] * 2], 32)
     assert m.pxw, m.pxh == (36, 64)
     m = gen_hex_map([[{'a': 'a'}]] * 2, 32)
     assert m.pxw, m.pxh == (63, 48)
示例#3
0
 def test_hex_neighbor(self):
     # test hexagonal tile map
     # tiles = [['a', 'b'], ['c', 'd'], ['e', 'f'], ['g', 'h']]
     # /d\ /h\
     # /b\_/f\_/
     # \_/c\_/g\
     # /a\_/e\_/
     # \_/ \_/
     m = gen_hex_map(hmd, 32)
     t = m.get_cell(0, 0)
     assert (t.x, t.y) == (0, 0) and t.properties['meta'] == 'a'
     assert m.get_neighbor(t, m.DOWN) is None
     assert m.get_neighbor(t, m.UP).properties['meta'] == 'b'
     assert m.get_neighbor(t, m.DOWN_LEFT) is None
     assert m.get_neighbor(t, m.DOWN_RIGHT) is None
     assert m.get_neighbor(t, m.UP_LEFT) is None
     assert m.get_neighbor(t, m.UP_RIGHT).properties['meta'] == 'c'
     t = m.get_neighbor(t, m.UP)
     assert (t.x, t.y) == (0, 1) and t.properties['meta'] == 'b'
     assert m.get_neighbor(t, m.DOWN).properties['meta'] == 'a'
     assert m.get_neighbor(t, m.UP) is None
     assert m.get_neighbor(t, m.DOWN_LEFT) is None
     assert m.get_neighbor(t, m.DOWN_RIGHT).properties['meta'] == 'c'
     assert m.get_neighbor(t, m.UP_LEFT) is None
     assert m.get_neighbor(t, m.UP_RIGHT).properties['meta'] == 'd'
     t = m.get_neighbor(t, m.DOWN_RIGHT)
     assert (t.x, t.y) == (1, 0) and t.properties['meta'] == 'c'
     assert m.get_neighbor(t, m.DOWN) is None
     assert m.get_neighbor(t, m.UP).properties['meta'] == 'd'
     assert m.get_neighbor(t, m.DOWN_LEFT).properties['meta'] == 'a'
     assert m.get_neighbor(t, m.DOWN_RIGHT).properties['meta'] == 'e'
     assert m.get_neighbor(t, m.UP_LEFT).properties['meta'] == 'b'
     assert m.get_neighbor(t, m.UP_RIGHT).properties['meta'] == 'f'
     t = m.get_neighbor(t, m.UP_RIGHT)
     assert (t.x, t.y) == (2, 1) and t.properties['meta'] == 'f'
     assert m.get_neighbor(t, m.DOWN).properties['meta'] == 'e'
     assert m.get_neighbor(t, m.UP) is None
     assert m.get_neighbor(t, m.DOWN_LEFT).properties['meta'] == 'c'
     assert m.get_neighbor(t, m.DOWN_RIGHT).properties['meta'] == 'g'
     assert m.get_neighbor(t, m.UP_LEFT).properties['meta'] == 'd'
     assert m.get_neighbor(t, m.UP_RIGHT).properties['meta'] == 'h'
     t = m.get_neighbor(t, m.DOWN_RIGHT)
     assert (t.x, t.y) == (3, 0) and t.properties['meta'] == 'g'
     assert m.get_neighbor(t, m.DOWN) is None
     assert m.get_neighbor(t, m.UP).properties['meta'] == 'h'
     assert m.get_neighbor(t, m.DOWN_LEFT).properties['meta'] == 'e'
     assert m.get_neighbor(t, m.DOWN_RIGHT) is None
     assert m.get_neighbor(t, m.UP_LEFT).properties['meta'] == 'f'
     assert m.get_neighbor(t, m.UP_RIGHT) is None
     t = m.get_neighbor(t, m.UP)
     assert (t.x, t.y) == (3, 1) and t.properties['meta'] == 'h'
     assert m.get_neighbor(t, m.DOWN).properties['meta'] == 'g'
     assert m.get_neighbor(t, m.UP) is None
     assert m.get_neighbor(t, m.DOWN_LEFT).properties['meta'] == 'f'
     assert m.get_neighbor(t, m.DOWN_RIGHT) is None
     assert m.get_neighbor(t, m.UP_LEFT) is None
     assert m.get_neighbor(t, m.UP_RIGHT) is None
示例#4
0
 def test_hex_neighbor(self):
     # test hexagonal tile map
     # tiles = [['a', 'b'], ['c', 'd'], ['e', 'f'], ['g', 'h']]
     #   /d\ /h\
     # /b\_/f\_/
     # \_/c\_/g\
     # /a\_/e\_/
     # \_/ \_/ 
     m = gen_hex_map(hmd, 32)
     t = m.get_cell(0,0)
     assert (t.x, t.y) == (0, 0) and t.properties['meta'] == 'a'
     assert m.get_neighbor(t, m.DOWN) is None
     assert m.get_neighbor(t, m.UP).properties['meta'] == 'b'
     assert m.get_neighbor(t, m.DOWN_LEFT) is None
     assert m.get_neighbor(t, m.DOWN_RIGHT) is None
     assert m.get_neighbor(t, m.UP_LEFT) is None
     assert m.get_neighbor(t, m.UP_RIGHT).properties['meta'] == 'c'
     t = m.get_neighbor(t, m.UP)
     assert (t.x, t.y) == (0, 1) and t.properties['meta'] == 'b'
     assert m.get_neighbor(t, m.DOWN).properties['meta'] == 'a'
     assert m.get_neighbor(t, m.UP) is None
     assert m.get_neighbor(t, m.DOWN_LEFT) is None
     assert m.get_neighbor(t, m.DOWN_RIGHT).properties['meta'] == 'c'
     assert m.get_neighbor(t, m.UP_LEFT) is None
     assert m.get_neighbor(t, m.UP_RIGHT).properties['meta'] == 'd'
     t = m.get_neighbor(t, m.DOWN_RIGHT)
     assert (t.x, t.y) == (1, 0) and t.properties['meta'] == 'c'
     assert m.get_neighbor(t, m.DOWN) is None
     assert m.get_neighbor(t, m.UP).properties['meta'] == 'd'
     assert m.get_neighbor(t, m.DOWN_LEFT).properties['meta'] == 'a'
     assert m.get_neighbor(t, m.DOWN_RIGHT).properties['meta'] == 'e'
     assert m.get_neighbor(t, m.UP_LEFT).properties['meta'] == 'b'
     assert m.get_neighbor(t, m.UP_RIGHT).properties['meta'] == 'f'
     t = m.get_neighbor(t, m.UP_RIGHT)
     assert (t.x, t.y) == (2, 1) and t.properties['meta'] == 'f'
     assert m.get_neighbor(t, m.DOWN).properties['meta'] == 'e'
     assert m.get_neighbor(t, m.UP) is None
     assert m.get_neighbor(t, m.DOWN_LEFT).properties['meta'] == 'c'
     assert m.get_neighbor(t, m.DOWN_RIGHT).properties['meta'] == 'g'
     assert m.get_neighbor(t, m.UP_LEFT).properties['meta'] == 'd'
     assert m.get_neighbor(t, m.UP_RIGHT).properties['meta'] == 'h'
     t = m.get_neighbor(t, m.DOWN_RIGHT)
     assert (t.x, t.y) == (3, 0) and t.properties['meta'] == 'g'
     assert m.get_neighbor(t, m.DOWN) is None
     assert m.get_neighbor(t, m.UP).properties['meta'] == 'h'
     assert m.get_neighbor(t, m.DOWN_LEFT).properties['meta'] == 'e'
     assert m.get_neighbor(t, m.DOWN_RIGHT) is None
     assert m.get_neighbor(t, m.UP_LEFT).properties['meta'] == 'f'
     assert m.get_neighbor(t, m.UP_RIGHT) is None
     t = m.get_neighbor(t, m.UP)
     assert (t.x, t.y) == (3, 1) and t.properties['meta'] == 'h'
     assert m.get_neighbor(t, m.DOWN).properties['meta'] == 'g'
     assert m.get_neighbor(t, m.UP) is None
     assert m.get_neighbor(t, m.DOWN_LEFT).properties['meta'] == 'f'
     assert m.get_neighbor(t, m.DOWN_RIGHT) is None
     assert m.get_neighbor(t, m.UP_LEFT) is None
     assert m.get_neighbor(t, m.UP_RIGHT) is None
示例#5
0
    def test_hex_coords(self):
        # test hexagonal tile map
        # tiles = [['a', 'b'], ['c', 'd'], ['e', 'f'], ['g', 'h']]
        # /d\ /h\
        # /b\_/f\_/
        # \_/c\_/g\
        # /a\_/e\_/
        # \_/ \_/
        m = gen_hex_map(hmd, 32)

        # test tile sides / corners
        t00 = m.get_cell(0, 0)
        assert t00.top == 32
        assert t00.bottom == 0
        assert t00.left == (0, 16)
        assert t00.right == (36, 16)
        assert t00.center == (18, 16)
        assert t00.topleft == (9, 32)
        assert t00.topright == (27, 32)
        assert t00.bottomleft == (9, 0)
        assert t00.bottomright == (27, 0)
        assert t00.midtop == (18, 32)
        assert t00.midbottom == (18, 0)
        assert t00.midtopleft == (4, 24)
        assert t00.midtopright == (31, 24)
        assert t00.midbottomleft == (4, 8)
        assert t00.midbottomright == (31, 8)

        t10 = m.get_cell(1, 0)
        assert t10.top == 48
        assert t10.bottom == 16
        assert t10.left == t00.topright
        assert t10.right == (63, 32)
        assert t10.center == (45, 32)
        assert t10.topleft == (36, 48)
        assert t10.topright == (54, 48)
        assert t10.bottomleft == t00.right
        assert t10.bottomright == (54, 16)
        assert t10.midtop == (45, 48)
        assert t10.midbottom == (45, 16)
        assert t10.midtopleft == (31, 40)
        assert t10.midtopright == (58, 40)
        assert t10.midbottomleft == t00.midtopright
        assert t10.midbottomright == (58, 24)

        t = m.get_cell(2, 0)
        assert t.top == 32
        assert t.bottom == 0
        assert t.left == t10.bottomright
        assert t.right == (90, 16)
        assert t.center == (72, 16)
        assert t.topleft == t10.right
        assert t.midtopleft == t10.midbottomright
示例#6
0
    def test_hex_coords(self):
        # test hexagonal tile map
        # tiles = [['a', 'b'], ['c', 'd'], ['e', 'f'], ['g', 'h']]
        #   /d\ /h\
        # /b\_/f\_/
        # \_/c\_/g\
        # /a\_/e\_/
        # \_/ \_/ 
        m = gen_hex_map(hmd, 32)

        # test tile sides / corners
        t00 = m.get_cell(0, 0)
        assert t00.top == 32
        assert t00.bottom == 0
        assert t00.left == (0, 16)
        assert t00.right == (36, 16)
        assert t00.center == (18, 16)
        assert t00.topleft == (9, 32)
        assert t00.topright == (27, 32)
        assert t00.bottomleft == (9, 0)
        assert t00.bottomright == (27, 0)
        assert t00.midtop == (18, 32)
        assert t00.midbottom == (18, 0)
        assert t00.midtopleft == (4, 24)
        assert t00.midtopright == (31, 24)
        assert t00.midbottomleft == (4, 8)
        assert t00.midbottomright == (31, 8)

        t10 = m.get_cell(1, 0)
        assert t10.top == 48
        assert t10.bottom == 16
        assert t10.left == t00.topright
        assert t10.right == (63, 32)
        assert t10.center == (45, 32)
        assert t10.topleft == (36, 48)
        assert t10.topright == (54, 48)
        assert t10.bottomleft == t00.right
        assert t10.bottomright == (54, 16)
        assert t10.midtop == (45, 48)
        assert t10.midbottom == (45, 16)
        assert t10.midtopleft == (31, 40)
        assert t10.midtopright == (58, 40)
        assert t10.midbottomleft == t00.midtopright
        assert t10.midbottomright == (58, 24)

        t = m.get_cell(2, 0)
        assert t.top == 32
        assert t.bottom == 0
        assert t.left == t10.bottomright
        assert t.right == (90, 16)
        assert t.center == (72, 16)
        assert t.topleft == t10.right
        assert t.midtopleft == t10.midbottomright
示例#7
0
 def test_hex_pixel(self):
     # test hexagonal tile map
     # tiles = [['a', 'b'], ['c', 'd'], ['e', 'f'], ['g', 'h']]
     # /d\ /h\
     # /b\_/f\_/
     # \_/c\_/g\
     # /a\_/e\_/
     # \_/ \_/
     m = gen_hex_map(hmd, 32)
     t = m.get(0, 0)
     assert t is None
     t = m.get(0, 16)
     assert (t.x, t.y) == (0, 0) and t.properties['meta'] == 'a'
     t = m.get(16, 16)
     assert (t.x, t.y) == (0, 0) and t.properties['meta'] == 'a'
     t = m.get(35, 16)
     assert (t.x, t.y) == (0, 0) and t.properties['meta'] == 'a'
     t = m.get(36, 16)
     assert (t.x, t.y) == (1, 0) and t.properties['meta'] == 'c'
示例#8
0
 def test_hex_pixel(self):
     # test hexagonal tile map
     # tiles = [['a', 'b'], ['c', 'd'], ['e', 'f'], ['g', 'h']]
     #   /d\ /h\
     # /b\_/f\_/
     # \_/c\_/g\
     # /a\_/e\_/
     # \_/ \_/ 
     m = gen_hex_map(hmd, 32)
     t = m.get(0,0)
     assert t is None
     t = m.get(0,16)
     assert (t.x, t.y) == (0, 0) and t.properties['meta'] == 'a'
     t = m.get(16,16)
     assert (t.x, t.y) == (0, 0) and t.properties['meta'] == 'a'
     t = m.get(35,16)
     assert (t.x, t.y) == (0, 0) and t.properties['meta'] == 'a'
     t = m.get(36,16)
     assert (t.x, t.y) == (1, 0) and t.properties['meta'] == 'c'
示例#9
0
    def test_main(self):
        self.init_window(256, 256)
        self.set_map(gen_hex_map([[dict()] * 10] * 10, 32))
        self.w.push_handlers(self.view)
        self.view.allow_oob = False

        @event(self.view)
        @for_cells()
        def on_mouse_enter(cells):
            for cell in cells:
                e = TintEffect((1, .5, .5, 1))
                cell.properties['hover'] = e
                cell.add_effect(e)

        @event(self.view)
        @for_cells()
        def on_mouse_leave(cells):
            for cell in cells:
                cell.remove_effect(cell.properties['hover'])

        @event(self.view)
        @for_cells()
        @for_sprites()
        def on_mouse_press(objs, x, y, button, modifiers):
            for obj in objs:
                if 'clicked' in obj.properties:
                    obj.remove_effect(obj.properties['clicked'])
                    del obj.properties['clicked']
                else:
                    e = TintEffect((.5, 1, .5, 1))
                    obj.properties['clicked'] = e
                    obj.add_effect(e)
                return

        self.show_focus()
        self.run_test()
示例#10
0
    def test_main(self):
        self.init_window(256, 256)
        self.set_map(gen_hex_map([[{}] * 10] * 10, 32))
        self.w.push_handlers(self.view)
        self.view.allow_oob = False

        @event(self.view)
        @for_cells()
        def on_mouse_enter(cells):
            for cell in cells:
                e = TintEffect((1, 0.5, 0.5, 1))
                cell.properties["hover"] = e
                cell.add_effect(e)

        @event(self.view)
        @for_cells()
        def on_mouse_leave(cells):
            for cell in cells:
                cell.remove_effect(cell.properties["hover"])

        @event(self.view)
        @for_cells()
        @for_sprites()
        def on_mouse_press(objs, x, y, button, modifiers):
            for obj in objs:
                if "clicked" in obj.properties:
                    obj.remove_effect(obj.properties["clicked"])
                    del obj.properties["clicked"]
                else:
                    e = TintEffect((0.5, 1, 0.5, 1))
                    obj.properties["clicked"] = e
                    obj.add_effect(e)
                return

        self.show_focus()
        self.run_test()
 def test_main(self):
     self.init_window(256, 256)
     self.set_map(gen_hex_map([[{}]*10]*10, 32), resize=True)
     self.view.allow_oob = False
     self.run_test()