Esempio n. 1
0
 def __init__(self, position, relative_position, buttons):
     self.position = _pixel_position_to_tile_position(Vec2(position))
     self.relative_pixels = Vec2(relative_position)
     self.last_position = _pixel_position_to_tile_position(
         Vec2(position) - Vec2(relative_position))
     self.relative_tiles = self.position - self.last_position
     self.buttons = buttons
Esempio n. 2
0
 def __init__(self, window_dimensions, tile_dimensions, caption):
     pyrogi._backend = self
     self.window_dimensions = window_dimensions
     self.tile_dimensions = tile_dimensions
     self.caption = caption
     self.mouse_position = Vec2(0, 0)
     self.screens = []
Esempio n. 3
0
 def _load_font_json(self, filename):
     with open(filename) as f:
         data = json.load(f)
         font_config = FontConfig(
             Vec2(data['tileWidth'], data['tileHeight']), data['fontType']
             if 'fontType' in data else GRAYSCALE_FONT_TYPE,
             data['characterMap'])
         return font_config
Esempio n. 4
0
    def test_screens(self):
        backend = Backend(Vec2(0, 0), Vec2(0, 0), '')
        self.assertEqual(len(backend.screens), 0)

        backend.set_screen(TestScreen())
        self.assertEqual(len(backend.screens), 1)

        backend.set_screen(TestScreen())
        self.assertEqual(len(backend.screens), 2)

        backend.go_back_n_screens(1)
        self.assertEqual(len(backend.screens), 1)

        backend.set_screen(TestScreen())
        self.assertEqual(len(backend.screens), 2)

        backend.go_back_n_screens(2)
        self.assertEqual(len(backend.screens), 0)
Esempio n. 5
0
def _pixel_position_to_tile_position(position):
    """:param position: The pixel position to convert.
    :type position: Vec2
    :returns: The given pixel position's corresponding tile position.
    :rtype: Vec2
    """
    tile_dimensions = pyrogi.get_tile_dimensions()
    return Vec2(math.floor(position.x / tile_dimensions.x),
                math.floor(position.y / tile_dimensions.y))
Esempio n. 6
0
 def get_index(self, character):
     index = self.character_map[character]
     return Vec2(index[0], index[1])
Esempio n. 7
0
    def test_pixel_position_to_tile_position(self):
        self.assertEqual(_pixel_position_to_tile_position(Vec2(0, 0)), Vec2(0, 0))
        self.assertEqual(_pixel_position_to_tile_position(Vec2(1, 0)), Vec2(0, 0))
        self.assertEqual(_pixel_position_to_tile_position(Vec2(1, 1)), Vec2(0, 0))
        self.assertEqual(_pixel_position_to_tile_position(Vec2(1.99, 4.99)), Vec2(0, 0))

        self.assertEqual(_pixel_position_to_tile_position(Vec2(2, 5)), Vec2(1, 1))
        self.assertEqual(_pixel_position_to_tile_position(Vec2(2.1, 5.1)), Vec2(1, 1))
        self.assertEqual(_pixel_position_to_tile_position(Vec2(3.999, 9.999)), Vec2(1, 1))

        self.assertEqual(_pixel_position_to_tile_position(Vec2(30, 3)), Vec2(15, 0))
        self.assertEqual(_pixel_position_to_tile_position(Vec2(5, 17)), Vec2(2, 3))
Esempio n. 8
0
 def setUp(self):
     pyrogi.Backend(Vec2(100, 100), Vec2(2, 5), '')
Esempio n. 9
0
 def __init__(self, position, button):
     self.position = _pixel_position_to_tile_position(Vec2(position))
     self.button = button
Esempio n. 10
0
 def __init__(self, position, scroll_amount):
     self.position = _pixel_position_to_tile_position(Vec2(position))
     self.scroll_amount = scroll_amount
Esempio n. 11
0
 def __init__(self):
     super(Screen, self).__init__(Vec2(0, 0))
Esempio n. 12
0
 def add_rectangle(self, dimensions, character, fg_color, bg_color):
     for x in range(dimensions.x):
         for y in range(dimensions.y):
             self.add_tile(Tile(character, fg_color, bg_color), Vec2(x, y))
Esempio n. 13
0
    def test_linear_gradient(self):
        self._run_linear_gradient_test(Color(0, 0, 0, 0), Vec2(0, 0),
                                       Color(255, 255, 255, 255), Vec2(10, 0),
                                       Vec2(5, 0), Vec2(5, 0),
                                       Color(128, 128, 128, 128),
                                       Color(128, 128, 128, 128),
                                       Color(128, 128, 128, 128),
                                       Color(128, 128, 128, 128))
        self._run_linear_gradient_test(Color(0, 0, 0, 0), Vec2(0, 0),
                                       Color(255, 255, 255, 255), Vec2(10, 0),
                                       Vec2(-2, 0), Vec2(-2, 0),
                                       Color(51, 51, 51,
                                             51), Color(0, 0, 0, 0),
                                       Color(51, 51, 51, 51),
                                       Color(0, 0, 0, 0))
        self._run_linear_gradient_test(Color(0, 0, 0, 0), Vec2(0, 0),
                                       Color(255, 255, 255, 255), Vec2(10, 0),
                                       Vec2(8, 0), Vec2(8, 0),
                                       Color(204, 204, 204, 204),
                                       Color(204, 204, 204, 204),
                                       Color(204, 204, 204, 204),
                                       Color(204, 204, 204, 204))

        self._run_linear_gradient_test(Color(0, 0, 0, 0), Vec2(0, 0),
                                       Color(255, 255, 255, 255), Vec2(10, 0),
                                       Vec2(10.5, 0), Vec2(10.5, 0),
                                       Color(242, 242, 242, 242),
                                       Color(255, 255, 255, 255),
                                       Color(242, 242, 242, 242),
                                       Color(255, 255, 255, 255))
        self._run_linear_gradient_test(Color(0, 0, 0, 0), Vec2(0, 0),
                                       Color(255, 255, 255, 255), Vec2(3, 0),
                                       Vec2(6, 0), Vec2(6, 0),
                                       Color(0, 0, 0, 0),
                                       Color(255, 255, 255, 255),
                                       Color(0, 0, 0, 0),
                                       Color(255, 255, 255, 255))

        self._run_linear_gradient_test(Color(87, 105, 202, 7), Vec2(0, 0),
                                       Color(230, 188, 12, 38), Vec2(0, 10),
                                       Vec2(0, 5), Vec2(0, -5),
                                       Color(158, 146, 107, 22),
                                       Color(158, 146, 107, 22),
                                       Color(158, 146, 107, 22),
                                       Color(87, 105, 202, 7))
        self._run_linear_gradient_test(Color(99, 180, 39, 222), Vec2(0, -5),
                                       Color(0, 60, 120, 205), Vec2(0, 5),
                                       Vec2(-2, 3), Vec2(193, -7),
                                       Color(20, 84, 104, 208),
                                       Color(20, 84, 104, 208),
                                       Color(79, 156, 55, 219),
                                       Color(99, 180, 39, 222))

        self._run_linear_gradient_test(Color(0, 0, 0, 0), Vec2(1, 6),
                                       Color(255, 255, 255,
                                             255), Vec2(3, 17.2), Vec2(2, 15),
                                       Vec2(0.5, 5), Color(203, 203, 203, 203),
                                       Color(203, 203, 203, 203),
                                       Color(24, 24, 24, 24),
                                       Color(0, 0, 0, 0))
        self._run_linear_gradient_test(Color(0, 0, 0, 0), Vec2(1, 6),
                                       Color(255, 255, 255,
                                             255), Vec2(3, 17.2), Vec2(4, 23),
                                       Vec2(-2, -7), Color(123, 123, 123, 123),
                                       Color(255, 255, 255, 255),
                                       Color(211, 211, 211, 211),
                                       Color(0, 0, 0, 0))
        self._run_linear_gradient_test(Color(0, 0, 0, 0), Vec2(1, 6),
                                       Color(255, 255, 255, 255),
                                       Vec2(3, 17.2), Vec2(6, 30),
                                       Vec2(-4.5, -100), Color(39, 39, 39, 39),
                                       Color(255, 255, 255, 255),
                                       Color(190, 190, 190, 190),
                                       Color(0, 0, 0, 0))
        self._run_linear_gradient_test(Color(0, 0, 0, 0), Vec2(1.2, 12.9),
                                       Color(255, 255, 255, 255),
                                       Vec2(30.8, 3.05), Vec2(162.7, -40.7),
                                       Vec2(-201.5, 195.2),
                                       Color(139, 139, 139, 139),
                                       Color(255, 255, 255, 255),
                                       Color(3, 3, 3, 3), Color(0, 0, 0, 0))

        self._run_linear_gradient_test(Color(250, 29, 1, 167), Vec2(-7, 2),
                                       Color(88, 44, 222, 111), Vec2(4, 17.9),
                                       Vec2(28.8, -193.3), Vec2(-33.9, -2),
                                       Color(129, 40, 166, 125),
                                       Color(250, 29, 1, 167),
                                       Color(94, 43, 214, 113),
                                       Color(250, 29, 1, 167))
        self._run_linear_gradient_test(Color(3, 7, 159, 209), Vec2(-7, 2),
                                       Color(109, 0, 200, 183), Vec2(4, -10.4),
                                       Vec2(3.4, 7), Vec2(-8.3, -17),
                                       Color(23, 6, 167, 204),
                                       Color(23, 6, 167, 204),
                                       Color(88, 1, 192, 188),
                                       Color(88, 1, 192, 188))
        self._run_linear_gradient_test(Color(67, 29, 252, 67), Vec2(-7, 2),
                                       Color(90, 174, 39,
                                             105), Vec2(-20.3, 12),
                                       Vec2(-30, 200.5), Vec2(28.8, -77.7),
                                       Color(73, 69, 194, 77),
                                       Color(90, 174, 39, 105),
                                       Color(81, 116, 125, 90),
                                       Color(67, 29, 252, 67))
        self._run_linear_gradient_test(Color(29, 189, 75, 253), Vec2(-7, 2),
                                       Color(109, 0, 200, 183),
                                       Vec2(-20.3, -10.4), Vec2(-100, 0.4),
                                       Vec2(2.3, 23), Color(45, 151, 100, 239),
                                       Color(109, 0, 200, 183),
                                       Color(96, 31, 180, 194),
                                       Color(29, 189, 75, 253))