def __init__(self,
              window,
              index=-1,
              logical_size=None,
              flags=render.SDL_RENDERER_ACCELERATED):
     Renderer.__init__(self, window, index, logical_size, flags)
     self.__default_window_size = window.size
Ejemplo n.º 2
0
    def render(self, renderer: Renderer):
        if self.cache is None or self.text != self.cache.text:
            # TODO: tc.cache.texture.destroy()
            self.cache = self.create_text_texture(renderer)

        source = (0, 0, self.cache.w, self.cache.h)
        dest = (self.x, self.y, self.cache.w, self.cache.h)
        renderer.copy(self.cache.texture, source, dest, angle=0, center=None, flip=SDL_FLIP_NONE)
Ejemplo n.º 3
0
    def render(self, renderer: Renderer, camera: Vector2d) -> None:
        if self.texture is None:
            factory = SpriteFactory(renderer=renderer)
            self.texture = factory.from_image(self.texture_path)
        texture = self.texture  # type: TextureSprite

        # Objective 4: Use the camera and player position to find the screen position
        #             |--1--2--3--4--| <-- x-axis screen (int)
        #             |     *        | <-- player
        # 0--1--2--3--|--5--6--7--8--| <-- x-axis world (float)
        #             ^                <-- camera
        x = self.pos.x - camera.x
        y = self.pos.y - camera.y

        # We need to cut up the player sheet into an array of tuples
        # The upper left is (0, 0). The total size is 256x128.
        #
        # If you divide the sections into 32x32 squares it looks like:
        #
        # |a a a|b b b|-|-|  a = body
        # |a a a|b b b|c c|  b = body shadow
        # |a a a|b b b|d d|  c = foot
        # |   |e|-|-|-|-|-|  d = foot shadow
        #                    e = basic eye (left)
        #
        # We take the pieces and overlay them on top of each other:
        #                           ( dx,  dy,   w,  h)
        # 1. foot shadow (back)  -> (-60,   0,  96, 48) <-- 3/2 scale
        # 2. foot (back)         -> (-60,   0,  96, 48) <-- 3/2 scale
        # 3. body shadow         -> (-48, -48,  96, 96)
        # 4. body                -> (-48, -48,  96, 96)
        # 5. foot shadow (front) -> (-36,   0,  96, 48) <-- 3/2 scale
        # 6. foot (front)        -> (-36,   0,  96, 48) <-- 3/2 scale
        # 7. basic eye (left)    -> (-18, -21,  36, 36) <-- 9/8 scale
        # 8. basic eye (right)   -> ( -6, -21,  36, 36) <-- 9/8 scale *FLIPPED*
        body_parts = [
            ((192, 64, 64, 32), (x - 60, y, 96, 48), SDL_FLIP_NONE),
            ((192, 32, 64, 32), (x - 60, y, 96, 48), SDL_FLIP_NONE),
            ((96, 0, 96, 96), (x - 48, y - 48, 96, 96), SDL_FLIP_NONE),
            ((0, 0, 96, 96), (x - 48, y - 48, 96, 96), SDL_FLIP_NONE),
            ((192, 64, 64, 32), (x - 36, y, 96, 48), SDL_FLIP_NONE),
            ((192, 32, 64, 32), (x - 36, y, 96, 48), SDL_FLIP_NONE),
            ((64, 96, 32, 32), (x - 18, y - 21, 36, 36), SDL_FLIP_NONE),
            ((64, 96, 32, 32), (x - 6, y - 21, 36, 36), SDL_FLIP_HORIZONTAL)
        ]

        # Objective 4: Iterate over the body parts and render each one
        for source, destination, flipped in body_parts:
            renderer.copy(texture, source, destination)
Ejemplo n.º 4
0
def main():
    screen_size = (WindowSize.WIDTH, WindowSize.HEIGHT)

    SDL_Init(SDL_INIT_EVERYTHING)

    window = Window("Soul Master", (WindowSize.WIDTH, WindowSize.HEIGHT))
    window.show()

    world = World()

    sprite_renderer = None
    texture_renderer = None

    if RENDERER == "software":
        sprite_renderer = SoftwareRenderer(window)
    elif RENDERER == "texture":
        texture_renderer = Renderer(window)
        sprite_renderer = TextureRenderer(texture_renderer)

    # world.add_system(sprite_renderer)

    factory = None
    if RENDERER == "software":
        factory = SpriteFactory(SOFTWARE)
    elif RENDERER == "texture":
        factory = SpriteFactory(TEXTURE, renderer=texture_renderer)

    menu = Menu(window, world, sprite_renderer, factory)
    menu.run()
Ejemplo n.º 5
0
def main():
    LOG.debug("INIT")
    screen_size = WindowSize.WIDTH, WindowSize.HEIGHT

    SDL_Init(SDL_INIT_EVERYTHING)

    window = Window("CyberMotor3000", screen_size)
    window.show()

    world = World()

    sprite_renderer = None
    texture_renderer = None

    if RENDERER == "software":
        sprite_renderer = SoftwareRenderer(window)
    elif RENDERER == "texture":
        texture_renderer = Renderer(window)
        sprite_renderer = TextureRenderer(texture_renderer)

    factory = None
    if RENDERER == "software":
        factory = SpriteFactory(SOFTWARE)
    elif RENDERER == "texture":
        factory = SpriteFactory(TEXTURE, renderer=texture_renderer)

    menu = Menu(window, world, sprite_renderer, factory)
    menu.run()
Ejemplo n.º 6
0
    def render(self, renderer: Renderer, camera: Vector2d):
        if self.texture is None:
            factory = SpriteFactory(renderer=renderer)
            self.texture = factory.from_image(self.texture_path)
        texture = self.texture  # type: TextureSprite

        for i, tile_nr in enumerate(self.tiles):
            if tile_nr == 0:
                continue
            clip_x = (tile_nr % TILES_PER_ROW) * TILE_WIDTH
            clip_y = int(tile_nr / TILES_PER_ROW) * TILE_HEIGHT
            dest_x = (i % self.width) * TILE_WIDTH - int(camera.x)
            dest_y = int(i / self.width) * TILE_HEIGHT - int(camera.y)

            clip = (clip_x, clip_y, TILE_WIDTH, TILE_HEIGHT)
            dest = (dest_x, dest_y, TILE_WIDTH, TILE_HEIGHT)
            renderer.copy(texture, clip, dest)
Ejemplo n.º 7
0
class Window(SDL_Window):
    def __init__(self, title='Fluent Window', size=(640, 480)):
        super(Window, self).__init__(title=title, size=size)

        self.renderer = SDL_Renderer(target=self)  # Initializing renderer instance
        self.factory = SpriteFactory(renderer=self.renderer)  # Initializing sprite factory instance
        self.events = list()  # Events list

    def update(self) -> None:
        self.events.clear()
        for event in get_events():
            if event.type == SDL_MOUSEBUTTONDOWN:
                self.events.append((event.button.x, event.button.y))
            elif event.type == SDL_QUIT:
                quit()

        self.renderer.present()  # Presenting renderer
        self.renderer.clear(color=(0, 0, 0, 255))  # Clearing renderer

        self.refresh()  # Refreshing window
Ejemplo n.º 8
0
def main() -> int:
    sdl2.ext.init()
    resources = Resources(__file__, "resources")
    controller = Controller()

    # Objective 1: Create and show the Window
    # YOUR CODE HERE...
    window = Window(WINDOW_TITLE, WINDOW_SIZE)
    window.show()

    # Objective 2: Create the Renderer with a background color
    # YOUR CODE HERE...
    renderer = Renderer(window)
    color = Color(110, 132, 174)
    renderer.color = color

    # Objective 3: Set up the game
    # YOUR CODE HERE...
    game = Game(resources)
    # Game Loop, draws each frame
    last_time = time()
    lag = 0.0
    while True:
        now = time()
        lag += now - last_time
        last_time = now

        controller.handle_input()
        if controller.has_input(Input.QUIT):
            break

        # Objective 3: Update the game the appropriate number of frames
        # YOUR CODE HERE...
        while lag >= SECONDS_PER_UPDATE:
            game.update(controller)
            lag -= SECONDS_PER_UPDATE

        # Objective 2: Draw over all drawings of the last frame with the default color
        # YOUR CODE HERE...
        renderer.clear()

        # Objective 3: Render the game
        # YOUR CODE HERE...
        game.render(renderer)
        # Objective 2: Show the result on screen
        # YOUR CODE HERE...
        renderer.present()
    sdl2.ext.quit()
    return 0
Ejemplo n.º 9
0
def main() -> int:
    sdl2.ext.init()
    resources = Resources(__file__, "resources")
    controller = Controller()

    window = Window(WINDOW_TITLE, WINDOW_SIZE)
    window.show()

    renderer = Renderer(window)
    color = Color(125, 148, 210)
    renderer.color = color

    # Objective 3: Set up the game
    game = Game(resources)

    # Game Loop, draws each frame
    last_time = time()
    lag = 0.0
    while True:
        now = time()
        lag += now - last_time
        last_time = now

        controller.handle_input()
        if controller.has_input(Input.QUIT):
            break

        # Objective 3: Update the game the appropriate number of frames
        while lag >= SECONDS_PER_UPDATE:
            game.update(controller)
            lag -= SECONDS_PER_UPDATE

        renderer.clear()

        # Objective 3: Render the game
        game.render(renderer)
        game.update(controller)

        renderer.present()

    sdl2.ext.quit()
    return 0
Ejemplo n.º 10
0
def main() -> int:
    sdl2.ext.init()
    resources = Resources(__file__, "resources")
    controller = Controller()

    # Objective 1: Create and show the Window
    window = Window(WINDOW_TITLE, WINDOW_SIZE)
    window.show()
    # Objective 2: Create the Renderer with a background color
    renderer = Renderer(window)
    color = Color(255, 255, 255)
    renderer.color = color

    # Objective 3: Set up the game


    # Game Loop, draws each frame
    last_time = time()
    lag = 0.0
    while True:
        now = time()
        lag += now - last_time
        last_time = now

        controller.handle_input()
        if controller.has_input(Input.QUIT):
            break

        # Objective 3: Update the game the appropriate number of frames
      while lag >= SECONDS_PER_UPDATE:
          lag -= SECONDS_PER_UPDATE

        # Objective 2: Draw over all drawings of the last frame with the default color
        renderer.clear()

        # Objective 3: Render the game
        renderer.present()
 def fill(self, rects, color=None):
     mapped_rects = self.__map_rects_to_window_coordinates(rects)
     Renderer.fill(self, mapped_rects, color)
 def draw_point(self, points, color=None):
     mapped_points = self.__map_points_to_window_coordinates(points)
     Renderer.draw_point(self, mapped_points, color)
Ejemplo n.º 13
0
    def __init__(self, title='Fluent Window', size=(640, 480)):
        super(Window, self).__init__(title=title, size=size)

        self.renderer = SDL_Renderer(target=self)  # Initializing renderer instance
        self.factory = SpriteFactory(renderer=self.renderer)  # Initializing sprite factory instance
        self.events = list()  # Events list