@anonsik

Как сделать так чтобы фейерверки не исчезали?

задача в том что, нужно сделать так чтобы эти фейерверки не исчезали вообще, тоесть чтоб при каждом клике он не исчезал

import random, math
import pygame as pg
WINSIZE = [640, 480]
WINCENTER = [320, 240]
NUMSTARS = 150

def init_star():
dir = random.randrange(100000)
velmult = random.random() * 0.6 + 0.4
vel = [math.sin(dir) * velmult, math.cos(dir) * velmult]
return vel, WINCENTER[:]

def initilalize_stars():
stars = []
for x in range(NUMSTARS):
star = init_star()
vel, pos = star
steps = random.randint(0, WINCENTER[0])
pos[0] = pos[0] + (vel[0] * steps)
pos[1] = pos[1] + (vel[1] * steps)
vel[0] = vel[0] + (steps * 0.09)
vel[1] = vel[1] + (steps * 0.09)
stars.append(star)
move_star(stars)
return stars

def draw_star(surface, stars, color):
for vel, pos in stars:
pos = (int(pos[0]), int(pos[1]))
surface.set_at(pos, color)

def move_star(stars):
for vel, pos in stars:
pos[0] = pos[0] + vel[0]
pos[1] = pos[1] + vel[1]
if not 0 <= pos[0] <= WINSIZE[0] or not 0 <= pos[1] <= WINSIZE[1]:
vel[:], pos[:] = init_star()
else:
vel[0] = vel[0] * 1.05
vel[1] = vel[1] * 1.05

def main():
random.seed()
stars = initilalize_stars()
clock = pg.time.Clock()
pg.init()
screen = pg.display.set_mode(WINSIZE)
pg.display.set_caption('Анимация с звёздами')
white = 255, 240, 200
black = 20, 20, 40

screen.fill(black)
fps = 60
done = 0
pg.mixer.music.load('sound/feirverk.mp3')
pg.mixer.music.play(-1, 0.0)
r, g, b = 255, 255, 255
while not done:

draw_star(screen, stars, black)
move_star(stars)
draw_star(screen, stars, (r, g, b))
pg.display.update()

for e in pg.event.get():
if e.type == pg.QUIT or (e.type == pg.KEYUP and e.key == pg.K_ESCAPE):
done = 1
break
elif e.type == pg.MOUSEBUTTONDOWN and e.button == 1:
r, g, b = random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)
pg.mixer.music.play(-1, 0.0)
WINCENTER[:] = list(e.pos)

clock.tick(fps)

if __name__ == "__main__":
main()
  • Вопрос задан
  • 72 просмотра
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы