Untitled

Anonymous
Plain Text
11/04/2025 6:20 PM
1.3 KB
39
Indexable
Never
import pygame
pygame.init()

fps = 60

WINDOW_HEIGHT = 500
WINDOW_WIDTH = 500

YELLOW = (217, 243, 156)
BLACK = (0,0,0)
PINK = (255, 159, 239)

window = pygame.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT))
window.fill(YELLOW)

clock = pygame.time.Clock()

class Area:
    def __init__ (self, x, y, width, height, color = None):
        self.rect = pygame.Rect(x, y, width, height)
        self.new_color = color
    
    def change_color(self, color):
        self.new_color = color
    
    def fill(self):
        pygame.draw.rect(window, self.new_color, self.rect)


class Label(Area):
    def set_text(self, text, fsize = 48, text_color = BLACK):
        self.image = pygame.font.SysFont("Arial", fsize).render(text, True, text_color)
    def draw(self, shift_x = 0, shift_y = 0):
        #self.fill()
        window.blit(self.image, (self.rect.x + shift_x, self.rect.y + shift_y))

num_of_cards = 4
cards = []

start_x = 30
start_y = 170

for i in range(num_of_cards):
    card = Label(start_x, start_y, 70, 100, PINK)
    card.set_text("CLICK", 32)
    cards.append(card)
    start_x = start_x + 100


while True:
    #window.fill(YELLOW)

    for c in cards:
        c.fill()
        c.draw(5, 35)
    
    pygame.display.update()
    clock.tick(fps)


Editor is loading...
Leave a Comment