This repository was archived by the owner on May 5, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathControlBox.py
More file actions
40 lines (34 loc) · 1.28 KB
/
ControlBox.py
File metadata and controls
40 lines (34 loc) · 1.28 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
29
30
31
32
33
34
35
36
37
38
39
40
import pygame
from pygame.locals import *
def check_keys(name, key):
if len(name) > 0:
if key == K_BACKSPACE:
return name[:len(name)-1]
if len(name) < 12:
if len(pygame.key.name(key)) == 1:
return (name + pygame.key.name(key)).upper()
return name.upper()
class ControlBox(pygame.sprite.Sprite):
def __init__(self, image, selected_image, pos, scale, selected=False):
pygame.sprite.Sprite.__init__(self)
self.image = pygame.image.load(image)
self.selected_image = None
if selected_image is not None:
self.selected_image = pygame.image.load(selected_image)
if scale is not None:
self.image = pygame.transform.scale(self.image, scale)
if selected_image is not None:
self.selected_image = pygame.transform.scale(self.selected_image, scale)
self.rect = self.image.get_rect()
self.rect.center = pos
self.selected = selected
def is_mouse_selection(self, (pos_x, pos_y)):
if self.rect.collidepoint(pos_x, pos_y):
self.selected = True
return True
return False
def get_image(self):
if self.selected:
return self.selected_image
else:
return self.image