/
Dragon925
/
Python-Graphics
Обзор
Документация
Войти
/
Dragon925
/
Python-Graphics
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
lesson_30
petard.py
32 строки
1 KB
Alexandr Romanov
Пример решения
15 май 2025, 18:44
15 май 2025, 18:44
d4a813e
Код
Авторство
О чём код?
from pygame import Rect, Surface, Color, draw from confetti import Confetti from random import randint class Petard: def __init__(self, x: int, y: int, width: int, height: int, confetti_count: int): self.rect = Rect(x, y, width, height) self.color = Color(randint(0, 255), randint(0, 255), randint(0, 255)) self.confetti = self._create_confetti(confetti_count) def _create_confetti(self, confetti_count: int) -> list[Confetti]: confetti = [] x, y = self.rect.topleft for _ in range(confetti_count): speed_x = randint(-20, 20) speed_y = randint(-50, -10) dy = randint(1, 5) width = randint(10, 30) height = randint(10, 30) confetti.append(Confetti(x, y, speed_x, speed_y, dy, width, height)) return confetti def draw(self, screen: Surface): for confetti in self.confetti: confetti.draw(screen) draw.rect(screen, self.color, self.rect) def move(self, height: int): for confetti in self.confetti: confetti.move(height)