Power bars are now visual as well as audio.
This commit is contained in:
		
							
								
								
									
										27
									
								
								__init__.py
									
									
									
									
									
								
							
							
						
						
									
										27
									
								
								__init__.py
									
									
									
									
									
								
							| @@ -205,16 +205,26 @@ def generate_tone(frequency, duration=0.1, sample_rate=44100, volume = 0.2): | |||||||
|  |  | ||||||
| def x_powerbar(): | def x_powerbar(): | ||||||
|     clock = pygame.time.Clock() |     clock = pygame.time.Clock() | ||||||
|  |     screen = pygame.display.get_surface() | ||||||
|     position = -50  # Start from the leftmost position |     position = -50  # Start from the leftmost position | ||||||
|     direction = 1   # Move right initially |     direction = 1   # Move right initially | ||||||
|  |     barHeight = 20 | ||||||
|     while True: |     while True: | ||||||
|         frequency = 440  # A4 note |         frequency = 440  # A4 note | ||||||
|         left_volume = (50 - position) / 100 |         leftVolume = (50 - position) / 100 | ||||||
|         right_volume = (position + 50) / 100 |         rightVolume = (position + 50) / 100 | ||||||
|         tone = generate_tone(frequency) |         tone = generate_tone(frequency) | ||||||
|         channel = tone.play() |         channel = tone.play() | ||||||
|         channel.set_volume(left_volume, right_volume) |         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(): |         for event in pygame.event.get(): | ||||||
|  |             check_for_exit() | ||||||
|             if event.type == pygame.KEYDOWN and event.key == pygame.K_SPACE: |             if event.type == pygame.KEYDOWN and event.key == pygame.K_SPACE: | ||||||
|                 channel.stop() |                 channel.stop() | ||||||
|                 return position  # This will return a value between -50 and 50 |                 return position  # This will return a value between -50 and 50 | ||||||
| @@ -229,20 +239,29 @@ def x_powerbar(): | |||||||
|  |  | ||||||
| def y_powerbar(): | def y_powerbar(): | ||||||
|     clock = pygame.time.Clock() |     clock = pygame.time.Clock() | ||||||
|  |     screen = pygame.display.get_surface() | ||||||
|     power = 0 |     power = 0 | ||||||
|     direction = 1  # 1 for increasing, -1 for decreasing |     direction = 1  # 1 for increasing, -1 for decreasing | ||||||
|  |     barWidth = 20 | ||||||
|     while True: |     while True: | ||||||
|         frequency = 220 + (power * 5)  # Adjust these values to change the pitch range |         frequency = 220 + (power * 5)  # Adjust these values to change the pitch range | ||||||
|         tone = generate_tone(frequency) |         tone = generate_tone(frequency) | ||||||
|         channel = tone.play() |         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(): |         for event in pygame.event.get(): | ||||||
|  |             check_for_exit() | ||||||
|             if event.type == pygame.KEYDOWN and event.key == pygame.K_SPACE: |             if event.type == pygame.KEYDOWN and event.key == pygame.K_SPACE: | ||||||
|                 channel.stop() |                 channel.stop() | ||||||
|                 return power |                 return power | ||||||
|         power += direction |         power += direction | ||||||
|         if power >= 100 or power <= 0: |         if power >= 100 or power <= 0: | ||||||
|             direction *= -1  # Reverse direction at limits |             direction *= -1  # Reverse direction at limits | ||||||
|         check_for_exit() |  | ||||||
|         clock.tick(40) |         clock.tick(40) | ||||||
|  |  | ||||||
| def cut_scene(sounds, soundName): | def cut_scene(sounds, soundName): | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user