Added back the power bars that somehow got lost in one of the previous updates.
This commit is contained in:
		
							
								
								
									
										11
									
								
								__init__.py
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								__init__.py
									
									
									
									
									
								
							@@ -62,9 +62,13 @@ from .utils import (
 | 
			
		||||
    sanitize_filename,
 | 
			
		||||
    lerp,
 | 
			
		||||
    smooth_step,
 | 
			
		||||
    distance_2d
 | 
			
		||||
    distance_2d,
 | 
			
		||||
    x_powerbar,
 | 
			
		||||
    y_powerbar,
 | 
			
		||||
    generate_tone
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
__version__ = '2.0.0'
 | 
			
		||||
 | 
			
		||||
# Make all symbols available at the package level
 | 
			
		||||
@@ -111,8 +115,9 @@ __all__ = [
 | 
			
		||||
    'Game',
 | 
			
		||||
    
 | 
			
		||||
    # Utils
 | 
			
		||||
    'check_for_updates', 'get_version_tuple', 'check_compatibility',
 | 
			
		||||
    'sanitize_filename', 'lerp', 'smooth_step', 'distance_2d',
 | 
			
		||||
'check_for_updates', 'get_version_tuple', 'check_compatibility',
 | 
			
		||||
'sanitize_filename', 'lerp', 'smooth_step', 'distance_2d',
 | 
			
		||||
'x_powerbar', 'y_powerbar', 'generate_tone',
 | 
			
		||||
    
 | 
			
		||||
    # Re-exported functions from pygame, math, random
 | 
			
		||||
    'get_ticks', 'delay', 'wait',
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										104
									
								
								utils.py
									
									
									
									
									
								
							
							
						
						
									
										104
									
								
								utils.py
									
									
									
									
									
								
							@@ -16,6 +16,7 @@ import time
 | 
			
		||||
import re
 | 
			
		||||
import requests
 | 
			
		||||
import os
 | 
			
		||||
from .input import check_for_exit
 | 
			
		||||
from setproctitle import setproctitle
 | 
			
		||||
 | 
			
		||||
from .services import PathService, ConfigService, VolumeService
 | 
			
		||||
@@ -348,3 +349,106 @@ def distance_2d(x1, y1, x2, y2):
 | 
			
		||||
        float: Distance between points
 | 
			
		||||
    """
 | 
			
		||||
    return math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)
 | 
			
		||||
 | 
			
		||||
def generate_tone(frequency, duration=0.1, sample_rate=44100, volume=0.2):
 | 
			
		||||
    """Generate a tone at the specified frequency.
 | 
			
		||||
    
 | 
			
		||||
    Args:
 | 
			
		||||
        frequency (float): Frequency in Hz
 | 
			
		||||
        duration (float): Duration in seconds (default: 0.1)
 | 
			
		||||
        sample_rate (int): Sample rate in Hz (default: 44100)
 | 
			
		||||
        volume (float): Volume from 0.0 to 1.0 (default: 0.2)
 | 
			
		||||
        
 | 
			
		||||
    Returns:
 | 
			
		||||
        pygame.mixer.Sound: Sound object with the generated tone
 | 
			
		||||
    """
 | 
			
		||||
    
 | 
			
		||||
    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 * 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():
 | 
			
		||||
    """Sound based horizontal power bar
 | 
			
		||||
    
 | 
			
		||||
    Returns:
 | 
			
		||||
        int: Selected position between -50 and 50
 | 
			
		||||
    """
 | 
			
		||||
    
 | 
			
		||||
    clock = pygame.time.Clock()
 | 
			
		||||
    screen = pygame.display.get_surface()
 | 
			
		||||
    position = -50  # Start from the leftmost position
 | 
			
		||||
    direction = 1   # Move right initially
 | 
			
		||||
    barHeight = 20
 | 
			
		||||
    
 | 
			
		||||
    while True:
 | 
			
		||||
        frequency = 440  # A4 note
 | 
			
		||||
        leftVolume = (50 - position) / 100
 | 
			
		||||
        rightVolume = (position + 50) / 100
 | 
			
		||||
        tone = generate_tone(frequency)
 | 
			
		||||
        channel = tone.play()
 | 
			
		||||
        channel.set_volume(leftVolume, rightVolume)
 | 
			
		||||
        
 | 
			
		||||
        # Visual representation
 | 
			
		||||
        screen.fill((0, 0, 0))
 | 
			
		||||
        barWidth = screen.get_width() - 40  # Leave 20px margin on each side
 | 
			
		||||
        pygame.draw.rect(screen, (100, 100, 100), (20, screen.get_height() // 2 - barHeight // 2, barWidth, barHeight))
 | 
			
		||||
        markerPos = int(20 + (position + 50) / 100 * barWidth)
 | 
			
		||||
        pygame.draw.rect(screen, (255, 0, 0), (markerPos - 5, screen.get_height() // 2 - barHeight, 10, barHeight * 2))
 | 
			
		||||
        pygame.display.flip()
 | 
			
		||||
        
 | 
			
		||||
        for event in pygame.event.get():
 | 
			
		||||
            check_for_exit()
 | 
			
		||||
            if event.type == pygame.KEYDOWN and event.key == pygame.K_SPACE:
 | 
			
		||||
                channel.stop()
 | 
			
		||||
                return position  # This will return a value between -50 and 50
 | 
			
		||||
                
 | 
			
		||||
        position += direction
 | 
			
		||||
        if position > 50:
 | 
			
		||||
            position = 50
 | 
			
		||||
            direction = -1
 | 
			
		||||
        elif position < -50:
 | 
			
		||||
            position = -50
 | 
			
		||||
            direction = 1
 | 
			
		||||
            
 | 
			
		||||
        clock.tick(40) # Speed of bar
 | 
			
		||||
 | 
			
		||||
def y_powerbar():
 | 
			
		||||
    """Sound based vertical power bar
 | 
			
		||||
    
 | 
			
		||||
    Returns:
 | 
			
		||||
        int: Selected power level between 0 and 100
 | 
			
		||||
    """
 | 
			
		||||
    
 | 
			
		||||
    clock = pygame.time.Clock()
 | 
			
		||||
    screen = pygame.display.get_surface()
 | 
			
		||||
    power = 0
 | 
			
		||||
    direction = 1  # 1 for increasing, -1 for decreasing
 | 
			
		||||
    barWidth = 20
 | 
			
		||||
    
 | 
			
		||||
    while True:
 | 
			
		||||
        frequency = 220 + (power * 5)  # Adjust these values to change the pitch range
 | 
			
		||||
        tone = generate_tone(frequency)
 | 
			
		||||
        channel = tone.play()
 | 
			
		||||
        
 | 
			
		||||
        # Visual representation
 | 
			
		||||
        screen.fill((0, 0, 0))
 | 
			
		||||
        barHeight = screen.get_height() - 40  # Leave 20px margin on top and bottom
 | 
			
		||||
        pygame.draw.rect(screen, (100, 100, 100), (screen.get_width() // 2 - barWidth // 2, 20, barWidth, barHeight))
 | 
			
		||||
        markerPos = int(20 + (100 - power) / 100 * barHeight)
 | 
			
		||||
        pygame.draw.rect(screen, (255, 0, 0), (screen.get_width() // 2 - barWidth, markerPos - 5, barWidth * 2, 10))
 | 
			
		||||
        pygame.display.flip()
 | 
			
		||||
        
 | 
			
		||||
        for event in pygame.event.get():
 | 
			
		||||
            check_for_exit()
 | 
			
		||||
            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(40)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user