-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
28 lines (23 loc) · 1.1 KB
/
utils.py
File metadata and controls
28 lines (23 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import pygame
def discretize_state(value, min_value, max_value, num_bins):
bin_size = (max_value - min_value) / num_bins
return min(num_bins - 1, max(0, int((value - min_value) / bin_size)))
def draw_actions(surface, action):
key_surface = pygame.Surface((160, 160))
key_surface.set_alpha(128)
key_surface.fill((50, 50, 50))
keys = [
((0, 40, 40, 80), [(10, 80), (30, 70), (30, 90)]), # Left
((120, 40, 40, 80), [(150, 80), (130, 70), (130, 90)]), # Right
((40, 0, 80, 40), [(80, 10), (70, 30), (90, 30)]), # Up
((40, 120, 80, 40), [(80, 150), (70, 130), (90, 130)]) # Down
]
for i, (rect, arrow) in enumerate(keys):
color = (255, 255, 255) if action == i else (100, 100, 100)
pygame.draw.rect(key_surface, color, rect, border_radius=5) # Rounded rectangles for key shape
pygame.draw.polygon(key_surface, (0, 0, 0), arrow)
if action == 4:
pygame.draw.circle(key_surface, (255, 255, 255), (80, 80), 20)
else:
pygame.draw.circle(key_surface, (100, 100, 100), (80, 80), 20)
return key_surface