Powerbars added and working.
This commit is contained in:
parent
0c73e98876
commit
fabf48ff42
76
__init__.py
76
__init__.py
@ -29,6 +29,7 @@ except ImportError:
|
|||||||
print("No other speech providers found.")
|
print("No other speech providers found.")
|
||||||
exit()
|
exit()
|
||||||
import math
|
import math
|
||||||
|
import numpy as np
|
||||||
import time
|
import time
|
||||||
|
|
||||||
localConfig = configparser.ConfigParser()
|
localConfig = configparser.ConfigParser()
|
||||||
@ -148,19 +149,69 @@ def initialize_gui(gameTitle):
|
|||||||
pygame.display.set_mode((320, 200))
|
pygame.display.set_mode((320, 200))
|
||||||
pygame.display.set_caption(gameTitle)
|
pygame.display.set_caption(gameTitle)
|
||||||
# Set 32 channels for sound by default
|
# Set 32 channels for sound by default
|
||||||
|
pygame.mixer.pre_init(44100, -16, 2, 1024)
|
||||||
pygame.mixer.init()
|
pygame.mixer.init()
|
||||||
pygame.mixer.set_num_channels(32)
|
pygame.mixer.set_num_channels(32)
|
||||||
# Reserve the cut scene channel
|
# Reserve the cut scene channel
|
||||||
pygame.mixer.set_reserved(0)
|
pygame.mixer.set_reserved(0)
|
||||||
# Load sounds from the sound directory and creates a list like that {'bottle': 'bottle.ogg'}
|
# 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"])]
|
try:
|
||||||
#lets make a dict with pygame.mixer.Sound() objects {'bottle':<soundobject>}
|
soundFiles = [f for f in listdir("sounds/") if isfile(join("sounds/", f)) and (f.split('.')[1].lower() in ["ogg","wav"])]
|
||||||
soundData = {}
|
#lets make a dict with pygame.mixer.Sound() objects {'bottle':<soundobject>}
|
||||||
for f in soundFiles:
|
soundData = {}
|
||||||
soundData[f.split('.')[0]] = pygame.mixer.Sound("sounds/" + f)
|
for f in soundFiles:
|
||||||
soundData['game-intro'].play()
|
soundData[f.split('.')[0]] = pygame.mixer.Sound("sounds/" + f)
|
||||||
time.sleep(soundData['game-intro'].get_length())
|
soundData['game-intro'].play()
|
||||||
return soundData
|
time.sleep(soundData['game-intro'].get_length())
|
||||||
|
return soundData
|
||||||
|
except Exception as e:
|
||||||
|
return False
|
||||||
|
|
||||||
|
def generate_tone(frequency, duration=0.1, sample_rate=44100, volume = 0.2):
|
||||||
|
t = np.linspace(0, duration, int(sample_rate * duration), False)
|
||||||
|
tone = np.sin(2 * np.pi * frequency * t)
|
||||||
|
stereo_tone = np.vstack((tone, tone)).T # Create a 2D array for stereo
|
||||||
|
stereo_tone = (stereo_tone * 32767).astype(np.int16)
|
||||||
|
stereo_tone = (stereo_tone * 32767 * volume).astype(np.int16) # Apply volume
|
||||||
|
stereo_tone = np.ascontiguousarray(stereo_tone) # Ensure C-contiguous array
|
||||||
|
return pygame.sndarray.make_sound(stereo_tone)
|
||||||
|
|
||||||
|
def x_powerbar():
|
||||||
|
clock = pygame.time.Clock()
|
||||||
|
position = -50
|
||||||
|
direction = 1
|
||||||
|
while True:
|
||||||
|
frequency = 440 # A4 note
|
||||||
|
left_volume = (position + 50) / 100
|
||||||
|
right_volume = (50 - position) / 100
|
||||||
|
tone = generate_tone(frequency)
|
||||||
|
channel = tone.play()
|
||||||
|
channel.set_volume(left_volume, right_volume)
|
||||||
|
for event in pygame.event.get():
|
||||||
|
if event.type == pygame.KEYDOWN and event.key == pygame.K_SPACE:
|
||||||
|
channel.stop()
|
||||||
|
return position
|
||||||
|
position += direction
|
||||||
|
if position >= 50 or position <= -50:
|
||||||
|
direction *= -1
|
||||||
|
clock.tick(45) # Speed of bar
|
||||||
|
|
||||||
|
def y_powerbar():
|
||||||
|
clock = pygame.time.Clock()
|
||||||
|
power = 0
|
||||||
|
direction = 1 # 1 for increasing, -1 for decreasing
|
||||||
|
while True:
|
||||||
|
frequency = 220 + (power * 5) # Adjust these values to change the pitch range
|
||||||
|
tone = generate_tone(frequency)
|
||||||
|
channel = tone.play()
|
||||||
|
for event in pygame.event.get():
|
||||||
|
if event.type == pygame.KEYDOWN and event.key == pygame.K_SPACE:
|
||||||
|
channel.stop()
|
||||||
|
return power
|
||||||
|
power += direction
|
||||||
|
if power >= 100 or power <= 0:
|
||||||
|
direction *= -1 # Reverse direction at limits
|
||||||
|
clock.tick(45)
|
||||||
|
|
||||||
def cut_scene(sounds, soundName):
|
def cut_scene(sounds, soundName):
|
||||||
pygame.event.clear()
|
pygame.event.clear()
|
||||||
@ -327,9 +378,12 @@ def game_menu(sounds, *options):
|
|||||||
if pygame.mixer.music.get_busy():
|
if pygame.mixer.music.get_busy():
|
||||||
pygame.mixer.music.unpause()
|
pygame.mixer.music.unpause()
|
||||||
else:
|
else:
|
||||||
pygame.mixer.music.load("sounds/music_menu.ogg")
|
try:
|
||||||
pygame.mixer.music.set_volume(0.75)
|
pygame.mixer.music.load("sounds/music_menu.ogg")
|
||||||
pygame.mixer.music.play(-1)
|
pygame.mixer.music.set_volume(0.75)
|
||||||
|
pygame.mixer.music.play(-1)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
i = 0
|
i = 0
|
||||||
# j keeps track of last spoken index so it isn't voiced on key up.
|
# j keeps track of last spoken index so it isn't voiced on key up.
|
||||||
j = -1
|
j = -1
|
||||||
|
Loading…
Reference in New Issue
Block a user