Untitled
Anonymous
plain_text
02/12/2026 7:15 PM
2.8 KB
10
Indexable
import pygame
pygame.init()
FPS = 60
WINDOW_HEIGHT = 500
WINDOW_WEIDTH = 500
BACKGROUND_COLOR = (0, 150, 160)
window = pygame.display.set_mode((WINDOW_WEIDTH, WINDOW_HEIGHT))
class Area():
def __init__(self, x=0, y=0, width=10, height=10, color=None):
self.rect = pygame.Rect(x, y, width, height)
self.fill_color = color
def color(self, new_color): #встановлюємо колір
self.fill_color = new_color
def fill(self): #відмальовуємо прямокутник на екрані
pygame.draw.rect(window, self.fill_color, self.rect)
def colliderect(self, collider):
return self.rect.colliderect(collider.rect)
def collidepoint(self, x, y):
return self.rect.collidepoint(x, y)
class Picture(Area):
def __init__(self,x, y, width, height, color, filename):
super().__init__(x, y, width, height, color)
self.image = pygame.image.load(filename)
def draw(self):
window.blit(self.image, (self.rect.x, self.rect.y))
cells = []
size = 100
for row in range(3):
for col in range(3):
cell = Area(col * size, row * size, size, size, (100,200,100))
cells.append(cell)
pictures = []
game_over = False
clock = pygame.time.Clock()
BLACK = (0,0,0)
while not game_over:
for event in pygame.event.get():
if event.type == pygame.MOUSEBUTTONDOWN:
x, y = event.pos
for c in cells:
if c.collidepoint(x,y):
print("click")
pic = Picture(c.rect.x, c.rect.y, size,size, None,"ball.png")
pictures.append(pic)
for c in cells:
c.fill()
pygame.draw.line(window, BLACK, (100, 0), (100, 300), 3)
pygame.draw.line(window, BLACK, (200, 0), (200, 300), 3)
pygame.draw.line(window, BLACK, (0, 100), (300, 100), 3)
pygame.draw.line(window, BLACK, (0, 200), (300, 200), 3)
for p in pictures:
p.draw()
clock.tick(FPS)
pygame.display.update()
#РусланEditor is loading...
Leave a Comment