Compare commits
	
		
			8 Commits
		
	
	
		
			testing
			...
			658709ebce
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|  | 658709ebce | ||
|  | d5c79c0770 | ||
|  | 24f9a126d4 | ||
|  | c316d4e570 | ||
|  | e66655d75f | ||
|  | c5406d5089 | ||
|  | b5b472eebe | ||
|  | 9f03de15b8 | 
							
								
								
									
										82
									
								
								__init__.py
									
									
									
									
									
								
							
							
						
						
									
										82
									
								
								__init__.py
									
									
									
									
									
								
							| @@ -32,6 +32,7 @@ except ImportError: | |||||||
| import math | import math | ||||||
| import numpy as np | import numpy as np | ||||||
| import time | import time | ||||||
|  | import wx | ||||||
|  |  | ||||||
| localConfig = configparser.ConfigParser() | localConfig = configparser.ConfigParser() | ||||||
| globalConfig = configparser.ConfigParser() | globalConfig = configparser.ConfigParser() | ||||||
| @@ -116,6 +117,18 @@ def read_config(readGlobal = False): | |||||||
|         except: |         except: | ||||||
|             pass |             pass | ||||||
|  |  | ||||||
|  |  | ||||||
|  | def get_input(prompt = "Enter text:", text = ""): | ||||||
|  |     app = wx.App(False) | ||||||
|  |     dialog = wx.TextEntryDialog(None, prompt, "Input", text) | ||||||
|  |     dialog.SetValue(text) | ||||||
|  |     if dialog.ShowModal() == wx.ID_OK: | ||||||
|  |         userInput = dialog.GetValue() | ||||||
|  |     else: | ||||||
|  |         userInput = None | ||||||
|  |     dialog.Destroy() | ||||||
|  |     return userInput | ||||||
|  |  | ||||||
| def speak(text, interupt=True): | def speak(text, interupt=True): | ||||||
|     if speechProvider == "speechd": |     if speechProvider == "speechd": | ||||||
|         if interupt: spd.cancel() |         if interupt: spd.cancel() | ||||||
| @@ -356,6 +369,65 @@ def play_random(sounds, soundName, pause = False, interrupt = False): | |||||||
|     if pause == True: |     if pause == True: | ||||||
|         time.sleep(sounds[randomKey].get_length()) |         time.sleep(sounds[randomKey].get_length()) | ||||||
|      |      | ||||||
|  | def play_random_positional(sounds, soundName, playerX, objectX): | ||||||
|  |     """Play a random sound with positional audio. | ||||||
|  |      | ||||||
|  |     Args: | ||||||
|  |         sounds: Dictionary of sound objects | ||||||
|  |         soundName: Base name of sound (e.g. 'falling_skull' will match 'falling_skull1', 'falling_skull2', etc.) | ||||||
|  |         playerX: Player's x position for audio panning | ||||||
|  |         objectX: Object's x position for audio panning | ||||||
|  |      | ||||||
|  |     Returns: | ||||||
|  |         The sound channel object for updating position | ||||||
|  |     """ | ||||||
|  |     keys = [k for k in sounds.keys() if k.startswith(soundName)] | ||||||
|  |     if not keys: | ||||||
|  |         return None | ||||||
|  |      | ||||||
|  |     randomKey = random.choice(keys) | ||||||
|  |     volume, left, right = calculate_volume_and_pan(playerX, objectX) | ||||||
|  |     if volume == 0: | ||||||
|  |         return None | ||||||
|  |          | ||||||
|  |     channel = sounds[randomKey].play() | ||||||
|  |     if channel: | ||||||
|  |         channel.set_volume(volume * left, volume * right) | ||||||
|  |     return channel | ||||||
|  |  | ||||||
|  | def play_random_falling(sounds, soundName, playerX, objectX, startY, currentY=0, maxY=20): | ||||||
|  |     """Play a random sound with positional audio that increases in volume as it 'falls'. | ||||||
|  |      | ||||||
|  |     Args: | ||||||
|  |         sounds: Dictionary of sound objects | ||||||
|  |         soundName: Base name of sound (e.g. 'falling_skull' will match 'falling_skull1', 'falling_skull2', etc.) | ||||||
|  |         playerX: Player's x position for audio panning | ||||||
|  |         objectX: Object's x position for audio panning | ||||||
|  |         startY: Starting Y position (0-20, higher = quieter start) | ||||||
|  |         currentY: Current Y position (0 = ground level) | ||||||
|  |         maxY: Maximum Y value (default 20) | ||||||
|  |      | ||||||
|  |     Returns: | ||||||
|  |         The sound channel object for updating position/volume | ||||||
|  |     """ | ||||||
|  |     keys = [k for k in sounds.keys() if k.startswith(soundName)] | ||||||
|  |     if not keys: | ||||||
|  |         return None | ||||||
|  |          | ||||||
|  |     randomKey = random.choice(keys) | ||||||
|  |     # Calculate horizontal positioning | ||||||
|  |     volume, left, right = calculate_volume_and_pan(playerX, objectX) | ||||||
|  |     if volume == 0: | ||||||
|  |         return None | ||||||
|  |          | ||||||
|  |     # Calculate vertical fall volume multiplier (0 at maxY, 1 at y=0) | ||||||
|  |     fallMultiplier = 1 - (currentY / maxY) | ||||||
|  |      | ||||||
|  |     channel = sounds[randomKey].play() | ||||||
|  |     if channel: | ||||||
|  |         channel.set_volume(volume * left * fallMultiplier, volume * right * fallMultiplier) | ||||||
|  |     return channel | ||||||
|  |  | ||||||
| def instructions(): | def instructions(): | ||||||
|     # Read in the instructions file |     # Read in the instructions file | ||||||
|     try: |     try: | ||||||
| @@ -406,6 +478,16 @@ def display_text(text): | |||||||
|         event = pygame.event.clear() |         event = pygame.event.clear() | ||||||
|         time.sleep(0.001) |         time.sleep(0.001) | ||||||
|  |  | ||||||
|  | def messagebox(text): | ||||||
|  |     speak(text + "\nPress any key to repeat or enter to continue.") | ||||||
|  |     while True: | ||||||
|  |         event = pygame.event.wait() | ||||||
|  |         if event.type == pygame.KEYDOWN: | ||||||
|  |             if event.key == pygame.K_ESCAPE or event.key == pygame.K_RETURN: | ||||||
|  |                 return | ||||||
|  |             else: | ||||||
|  |                 speak(text + "\nPress any key to repeat or enter to continue.") | ||||||
|  |  | ||||||
| def learn_sounds(sounds): | def learn_sounds(sounds): | ||||||
|     loop = True |     loop = True | ||||||
|     pygame.mixer.music.pause() |     pygame.mixer.music.pause() | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user