Untitled
Anonymous
plain_text
02/12/2026 7:13 PM
2.2 KB
13
Indexable
import pygame
import random
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(mw, 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))
rabbits = []
for i in range(20):
rabbit = Picture(random.randint(60, WINDOW_WEIDTH-60), random.randint(60, WINDOW_HEIGHT-60), 60,60, None, "rabbit.png")
rabbits.append(rabbit)
game_over = False
clock = pygame.time.Clock()
while not game_over:
window.fill(BACKGROUND_COLOR)
for e in pygame.event.get():
if e.type == pygame.MOUSEBUTTONDOWN:
x,y = e.pos
for r in rabbits:
if r.collidepoint(x,y):
rabbits.remove(r)
for r in rabbits:
r.draw()
clock.tick(FPS)
pygame.display.update()Editor is loading...
Leave a Comment