Ejemplo n.º 1
0
def draw():
    """Frame drawing function.

    Wipes the screen, blits all game sprites then screen sprites
    (and calling update on them), then scales the screen and updates
    the main display.
    """

    # wipe game screen
    # to be replaced with background drawing
    game_screen.fill((0, 0, 0))

    # draw each map layer
    for map_layer in map:
        map_layer.draw(game_screen)

    # update and draw each game sprite
    for sprite in game_sprites:
        if sprite.is_particle:
            # check collision on only certain particles
            # i.e. projectiles
            if hasattr(sprite, "collide_sprite"):
                if sprite.collide_map() \
                        or any(sprite.collide_sprite(s) for s in game_sprites):
                    # the particle will then be removed and freed
                    remove_game_sprites(sprite)

        # update all sprites, then draw
        sprite.update()
        sprite.draw(game_screen)

    # update and draw each screen sprite
    # these are rendered after all game sprites because
    # they need to always show over other sprites.
    for sprite in screen_sprites:
        sprite.update()
        sprite.draw(game_screen)

    # blit the low-res screen onto the main screen and scale it
    screen.blit(pygame.transform.scale(game_screen, options.dimensions()), (0, 0))

    # update the display
    pygame.display.update()
Ejemplo n.º 2
0
def init():
    """Initialise the screen and game screen, and set default options.
    """
    try:
        flags = 0
        if options.fullscreen():
            flags |= FULLSCREEN
        # flags |= RESIZABLE

        # initialise the screen
        global screen
        screen = pygame.display.set_mode(options.dimensions(), flags)

        # initialise the game_screen
        global game_screen
        game_screen = pygame.Surface(options.game_dimensions())

        pygame.mouse.set_visible(False)
        pygame.display.update()

    except pygame.error as msg:
        raise pygame.error("Failed to initialize render engine {0}".format(str(msg)))