You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
654 B
Python
29 lines
654 B
Python
# Imports
|
|
import pygame
|
|
|
|
# Buton
|
|
class Button():
|
|
|
|
# Constructor Method
|
|
def __init__(self, image, x, y):
|
|
self.image = image
|
|
self.rect = self.image.get_rect()
|
|
self.rect.x = x
|
|
self.rect.y = y
|
|
self.clicked = False
|
|
|
|
# Draw
|
|
def draw(self, screen):
|
|
# Action
|
|
action = False
|
|
# Click
|
|
if self.rect.collidepoint(pygame.mouse.get_pos()):
|
|
if pygame.mouse.get_pressed()[0] == 1 and self.clicked == False:
|
|
self.clicked = True
|
|
if pygame.mouse.get_pressed()[0] == 0 and self.clicked == True:
|
|
self.clicked = False
|
|
action = True
|
|
# Draw Button
|
|
screen.blit(self.image, self.rect)
|
|
# Return Action
|
|
return action |