Esempio n. 1
0
def pygame_setup(settings):
    """(Dict) -> Dict
    Returns a Dictionary of game environment variables.
    The Dict given should be the default_game_settings dictionary.
    """

    # Make sure all pygame modules loaded successfully
    result = pg.init()
    if result[1]:
        raise SystemExit("Could not init all modules:".format(pg.geterror()))

    # A game env dict that will be returned to be passed around as
    # persistent data
    game_env = {}
    game_env["SCREEN"] = pg.display.set_mode(settings["SCREEN_SIZE"])
    game_env["SCREEN_RECT"] = game_env["SCREEN"].get_rect()
    game_env["CLOCK"] = pg.time.Clock()
    game_env["FPS"] = settings["FPS"]
    game_env["CAPTION"] = settings["GAME_CAPTION"]
    game_env["ALLOWED_QUEUE_EVENTS"] = settings["ALLOWED_QUEUE_EVENTS"]
    game_env["SCREEN_SIZE"] = settings["SCREEN_SIZE"]

    # Set game screen to centered
    if settings["SCREEN_CENTERED"]:
        os.environ["SDL_VIDEO_CENTERED"] = "True"

    return game_env
Esempio n. 2
0
def load_image(file):
    "loads an image, prepares it for play"
    file = os.path.join(main_dir, 'data', file)
    try:
        surface = pygame.image.load(file)
    except pygame.error:
        raise SystemExit('Could not load image "%s" %s'%(file, pygame.geterror()))
    return surface.convert()
Esempio n. 3
0
def load_image(name, colorkey=None):
    fullname = os.path.join('Images', name)
    try:
        image = pygame.image.load(fullname)
    except pygame.geterror():
        print("Cannot load image:" + name)
        raise SystemExit
    image = image.convert()
    if colorkey is not None:
        if colorkey is -1:
            colorkey = image.get_at((0, 0))
        image.set_colorkey(colorkey)
    return image
Esempio n. 4
0
def load_sound(name):
    class NoneSound:
        def play(self):
            pass
    if not pygame.mixer:
        return NoneSound()
    fullname = os.path.join('Sons', name)
    try:
        sound = pygame.mixer.Sound(fullname)
    except pygame.geterror():
        print('Cannot load sound:' + name)
        raise SystemExit
    return sound
Esempio n. 5
0
def load_image(name, colorkey=None):
    fullname = os.path.join('Images', name)
    try:
        image = pygame.image.load(fullname)
    except pygame.geterror():
        print("Cannot load image:" + name)
        raise SystemExit
    image = image.convert()
    if colorkey is not None:
        if colorkey is -1:
            colorkey = image.get_at((0, 0))
        image.set_colorkey(colorkey)
    return image
def load_image(name, colorkey=None):
    fullname = os.path.join(con.IMAGE_DIR, name)
    try:
        image = pygame.image.load(fullname)
    except pygame.error:
        print("Cannot load image:", fullname)
        raise SystemExit(str(pygame.geterror()))
    image = image.convert()
    if colorkey is not None:
        if colorkey == -1:
            colorkey = image.get_at((0, 0))
        image.set_colorkey(colorkey, con.RLEACCEL)
        image = image.convert_alpha()
    return image
Esempio n. 7
0
def load_sound(name):
    class NoneSound:
        def play(self):
            pass

    if not pygame.mixer:
        return NoneSound()
    fullname = os.path.join('Sons', name)
    try:
        sound = pygame.mixer.Sound(fullname)
    except pygame.geterror():
        print('Cannot load sound:' + name)
        raise SystemExit
    return sound