Made Test Program
This commit is contained in:
parent
2058989c85
commit
345478e6e9
69
main.py
69
main.py
@ -0,0 +1,69 @@
|
|||||||
|
import pygame
|
||||||
|
import random
|
||||||
|
from particle import Particle
|
||||||
|
|
||||||
|
pygame.init()
|
||||||
|
|
||||||
|
# Set up display and clock.
|
||||||
|
screen = pygame.display.set_mode((800, 600))
|
||||||
|
pygame.display.set_caption("Particle Test")
|
||||||
|
clock = pygame.time.Clock()
|
||||||
|
|
||||||
|
particles = []
|
||||||
|
|
||||||
|
running = True
|
||||||
|
while running:
|
||||||
|
dt = clock.tick(60) / 1000.0 # Delta time in seconds.
|
||||||
|
|
||||||
|
# Event loop: quit on window close or spawn new particles on mouse click.
|
||||||
|
for event in pygame.event.get():
|
||||||
|
if event.type == pygame.QUIT:
|
||||||
|
running = False
|
||||||
|
elif event.type == pygame.MOUSEBUTTONDOWN:
|
||||||
|
# Create several particles at the mouse position.
|
||||||
|
for _ in range(10):
|
||||||
|
pos = pygame.mouse.get_pos()
|
||||||
|
vel = (random.uniform(-100, 100), random.uniform(-100, 100))
|
||||||
|
p = Particle(
|
||||||
|
pos=pos,
|
||||||
|
vel=vel,
|
||||||
|
acceleration=(0, 0),
|
||||||
|
lifetime=2.0,
|
||||||
|
decay_rate=1,
|
||||||
|
color=(
|
||||||
|
random.randint(100, 255),
|
||||||
|
random.randint(100, 255),
|
||||||
|
random.randint(100, 255)
|
||||||
|
),
|
||||||
|
size=5,
|
||||||
|
size_decay=2,
|
||||||
|
glow=True,
|
||||||
|
glow_intensity=1.0,
|
||||||
|
friction=0.1,
|
||||||
|
gravity=50,
|
||||||
|
bounce=True,
|
||||||
|
bounce_damping=0.7,
|
||||||
|
random_spread=10,
|
||||||
|
spin=0,
|
||||||
|
spin_rate=random.uniform(-180, 180),
|
||||||
|
spin_decay=0.5,
|
||||||
|
trail=True,
|
||||||
|
trail_length=15,
|
||||||
|
fade=True,
|
||||||
|
shape='circle'
|
||||||
|
)
|
||||||
|
particles.append(p)
|
||||||
|
|
||||||
|
# Clear the screen.
|
||||||
|
screen.fill((0, 0, 0))
|
||||||
|
|
||||||
|
# Update and draw each particle.
|
||||||
|
for particle in particles[:]:
|
||||||
|
particle.update(dt, screen.get_rect())
|
||||||
|
particle.draw(screen)
|
||||||
|
if particle.is_dead():
|
||||||
|
particles.remove(particle)
|
||||||
|
|
||||||
|
pygame.display.flip()
|
||||||
|
|
||||||
|
pygame.quit()
|
Loading…
Reference in New Issue
Block a user