Exemple #1
0
    def __init__(self, RESOURCE_DIR):
        WorldObject.init(RESOURCE_DIR)
        self.RESOURCES = sdl2.ext.Resources(RESOURCE_DIR)
        sdl2.ext.init()

        self.window = sdl2.ext.Window("Py-craft",
                                      size=(self.WIDTH, self.HEIGHT))
        self.window.show()

        self.p_surface = self.window.get_surface()
        self.c_surface = video.SDL_GetWindowSurface(self.window.window)

        UiHelper.font_manager = self.font_manager = sdl2.ext.FontManager(
            self.RESOURCES.get_path('helvetica-neue-bold.ttf'))

        UiHelper.sprite_factory = self.sprite_factory =\
            sdl2.ext.SpriteFactory(sdl2.ext.SOFTWARE)

        UiHelper.BLOCK_SIZE = self.BLOCK_SIZE

        self.offset = Coord(0, 0)  # offset in world coordinates
        self.world = WorldGenerator.generate_world(None, (100, 100))

        self.dirty = True
        UiHelper.texture_map = {}

        sprite = self.sprite_factory.from_image(
            self.RESOURCES.get_path('player.png'))
        self.player = Player(self.world, sprite)

        self.init()
        self.world.tick()
        self.loop()
Exemple #2
0
 def test_SDL_GetWindowSurface(self):
     flags = (video.SDL_WINDOW_BORDERLESS,
              video.SDL_WINDOW_BORDERLESS | video.SDL_WINDOW_HIDDEN,
              video.SDL_WINDOW_RESIZABLE | video.SDL_WINDOW_MINIMIZED)
     for flag in flags:
         window = video.SDL_CreateWindow(b"Test", 200, 200, 200, 200, flag)
         sf = video.SDL_GetWindowSurface(window)
         assert isinstance(sf.contents, surface.SDL_Surface)
         video.SDL_DestroyWindow(window)
Exemple #3
0
    def test_SDL_UpdateWindowSurfaceRects(self):
        rectlist = (rect.SDL_Rect * 4)(rect.SDL_Rect(),
                                       rect.SDL_Rect(10, 10, 10, 10),
                                       rect.SDL_Rect(0, 0, 5, 4),
                                       rect.SDL_Rect(-5, -5, 6, 2))
        rptr = cast(rectlist, POINTER(rect.SDL_Rect))

        flags = (video.SDL_WINDOW_BORDERLESS,
                 video.SDL_WINDOW_BORDERLESS | video.SDL_WINDOW_HIDDEN,
                 video.SDL_WINDOW_RESIZABLE | video.SDL_WINDOW_MINIMIZED)
        for flag in flags:
            window = video.SDL_CreateWindow(b"Test", 200, 200, 200, 200, flag)
            # self.assertRaises(sdl.SDLError,
            #                  video.SDL_UpdateWindowSurfaceRects,
            #                  window, rectlist)
            sf = surface.SDL_Surface()
            video.SDL_GetWindowSurface(window, byref(sf))
            ret = video.SDL_UpdateWindowSurfaceRects(window, rptr, 4)
            assert ret == 0
            video.SDL_DestroyWindow(window)