""" ---------------------------------------- Project: Platformer Shooter = Standard: 91883 (AS1.7) v.1 School: = Tauranga Boys' College = Author: Sam Coley = Date: June 2024 = Python: 3.12 = ---------------------------------------- """ import pygame import pygame # Import the Pygame module for game development # Button class class Button(): def __init__(self, x, y, image, scale): width = image.get_width() # Get the width of the image height = image.get_height() # Get the height of the image self.image = pygame.transform.scale(image, (int(width * scale), int(height * scale))) # Scale the image self.rect = self.image.get_rect() # Get the rectangle object for the image self.rect.topleft = (x, y) # Set the top-left corner of the rectangle self.clicked = False # Initialize the clicked flag def draw(self, surface): action = False # Initialize the action flag # Get mouse position pos = pygame.mouse.get_pos() # Get the current mouse position # Check mouseover and clicked conditions if self.rect.collidepoint(pos): # Check if the mouse is over the button if pygame.mouse.get_pressed()[0] == 1 and self.clicked == False: # Check if the left mouse button is clicked action = True # Set the action flag to True self.clicked = True # Set the clicked flag to True if pygame.mouse.get_pressed()[0] == 0: # Check if the left mouse button is released self.clicked = False # Reset the clicked flag # Draw button surface.blit(self.image, (self.rect.x, self.rect.y)) # Draw the button on the surface return action # Return the action flag