Somewhat of a start on switching over to pyglet. It's in a very broken state with some remaining calls to pygame.

This commit is contained in:
Storm Dragon 2022-03-27 00:59:07 -04:00
parent 155ed6ec39
commit 639198e8de

View File

@ -10,7 +10,7 @@ from os.path import isfile, join
from inspect import isfunction from inspect import isfunction
from xdg import BaseDirectory from xdg import BaseDirectory
from setproctitle import setproctitle from setproctitle import setproctitle
import pygame import pyglet
import pyperclip import pyperclip
import random import random
import re import re
@ -125,9 +125,8 @@ def speak(text, interupt = True):
def exit_game(): def exit_game():
if speechProvider == "speechd": spd.close() if speechProvider == "speechd": spd.close()
pygame.mixer.music.stop() # Close the pyglet window
pygame.quit() pyglet.app.exit()
exit()
def initialize_gui(gameTitle): def initialize_gui(gameTitle):
# Check for, and possibly create, storm-games path # Check for, and possibly create, storm-games path
@ -142,24 +141,16 @@ def initialize_gui(gameTitle):
global gameName global gameName
gameName = gameTitle gameName = gameTitle
setproctitle(str.lower(str.replace(gameTitle, " ", ""))) setproctitle(str.lower(str.replace(gameTitle, " ", "")))
# start pygame # init pyglet window
pygame.init() window = pyglet.window.Window(500, 300, gameTitle)
# start the display (required by the event loop) # Load sounds from the sound directory and creates a list like {'bottle': 'bottle.ogg'}
pygame.display.set_mode((320, 200))
pygame.display.set_caption(gameTitle)
# Set 32 channels for sound by default
pygame.mixer.init()
pygame.mixer.set_num_channels(32)
# Reserve the cut scene channel
pygame.mixer.set_reserved(0)
# Load sounds from the sound directory and creates a list like that {'bottle': 'bottle.ogg'}
soundFiles = [f for f in listdir("sounds/") if isfile(join("sounds/", f)) and (f.split('.')[1].lower() in ["ogg","wav"])] soundFiles = [f for f in listdir("sounds/") if isfile(join("sounds/", f)) and (f.split('.')[1].lower() in ["ogg","wav"])]
#lets make a dict with pygame.mixer.Sound() objects {'bottle':<soundobject>} # make a dict with pyglet media {'bottle':<soundobject>}
soundData = {} soundData = {}
for f in soundFiles: for f in soundFiles:
soundData[f.split('.')[0]] = pygame.mixer.Sound("sounds/" + f) soundData[f.split('.')[0]] = pyglet.media.load("sounds/" + f, streaming = False)
soundData['game-intro'].play() soundData['game-intro'].play()
time.sleep(soundData['game-intro'].get_length()) time.sleep(soundData['game-intro'].duration)
return soundData return soundData
def cut_scene(sounds, soundName): def cut_scene(sounds, soundName):