2016-03-20 18:35:23 -04:00
|
|
|
#!/bin/python
|
|
|
|
# -*- coding: utf-8 -*-
|
2016-03-20 18:01:41 -04:00
|
|
|
"""Standard initializations and functions shared by all games."""
|
|
|
|
|
|
|
|
import os
|
2016-03-20 18:35:23 -04:00
|
|
|
from os import listdir
|
|
|
|
from os.path import isfile, join
|
2016-03-20 18:01:41 -04:00
|
|
|
import pygame
|
|
|
|
import time
|
|
|
|
|
2016-03-20 18:37:39 -04:00
|
|
|
SoundFolder = 'sounds'
|
|
|
|
|
2016-03-20 18:01:41 -04:00
|
|
|
def initialize_gui(gameTitle):
|
|
|
|
# start pygame
|
|
|
|
pygame.init()
|
|
|
|
# start the display (required by the event loop)
|
|
|
|
pygame.display.set_mode((320, 200))
|
|
|
|
pygame.display.set_caption(gameTitle)
|
2016-03-20 19:28:21 -04:00
|
|
|
# Load sounds from the sound directory and creates a list like that {'bottle': 'bottle.ogg'}
|
2016-03-21 06:34:25 -04:00
|
|
|
soundFiles = [f for f in listdir("sounds/") if isfile(join("sounds/", f)) and (f.split('.')[1].lower() in ["ogg","wav"])]
|
2016-03-20 19:28:21 -04:00
|
|
|
#lets make a dict with pygame.mixer.Sound() objects {'bottle':<soundobject>}
|
|
|
|
soundData = {}
|
|
|
|
for f in soundFiles:
|
2016-03-21 06:34:25 -04:00
|
|
|
soundData[f.split('.')[0]] = pygame.mixer.Sound("sounds/" + f)
|
2016-03-21 06:42:53 -04:00
|
|
|
return soundData
|