烟花代码
肝了三小时,只求点赞。 如有不对请大佬改正
import pygame
from random import randint, uniform, choice
import math
vector = pygame.math.Vector2
gravity = vector(0, 0.3)
DISPLAY_WIDTH = DISPLAY_HEIGHT = 800
trail_colours = [(45, 45, 45), (60, 60, 60), (75, 75, 75),
(125, 125, 125), (150, 150, 150)]
dynamic_offset = 1
static_offset = 5
class Firework:
def __init__(self):
self.colour = (randint(0, 255), randint(0, 255), randint(0, 255))
self.colours = (
(randint(0, 255), randint(0, 255), randint(0, 255)
), (randint(0, 255), randint(0, 255), randint(0, 255)),
(randint(0, 255), randint(0, 255), randint(0, 255)))
self.firework = Particle(randint(0, DISPLAY_WIDTH), DISPLAY_HEIGHT, True,
self.colour) # Creates the firework particle
self.exploded = False
self.particles = []
self.min_max_particles = vector(100, 225)
def update(self, win): # called every frame
if not self.explod