-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuttonClass.py
More file actions
38 lines (34 loc) · 1.24 KB
/
Copy pathbuttonClass.py
File metadata and controls
38 lines (34 loc) · 1.24 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
import pygame
class Button():
def __init__(self,x,y,w,h,img = None, isUsed=False):
self.x = x
self.y = y
self.w = w
self.h = h
self.img = img
self.box = pygame.Rect(x,y,w,h)
self.clr = (40,40,45)
self.isUsed = isUsed
def draw_button(self,screen, txt = ''):
font = pygame.font.SysFont("Arial Black", 13)
pygame.draw.rect(screen,self.clr,self.box)
# if there is an img, blit img
if self.img:
screen.blit(self.img,(self.x,self.y))
# if there is txt, blit txt
if txt != '':
text = font.render(txt, 1, (255,255,255))
screen.blit(text,(self.x+5,self.y+2))
def click_button(self,mx,my, ownLogic = ''):
# if click button, button is used and change button colour
if self.box.collidepoint(mx,my):
if ownLogic == '':
self.clr = (90,90,95)
self.isUsed = True
return True
def deactivate_others(self, listOfButtons):
#make booleans of other buttons false and reset colour
for button in listOfButtons:
if button != self and button.isUsed:
button.clr = (40,40,45)
button.isUsed = False