-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfountainParticles.py
More file actions
48 lines (45 loc) · 1.87 KB
/
Copy pathfountainParticles.py
File metadata and controls
48 lines (45 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
from utility import *
import pygame,random
vec = pygame.math.Vector2
from particle import *
class FountainParticle(Particle):
def __init__(self,main,x,y,col):
self.main = main
self.position = vec(x,y)
#random initial angle and velocity
self.angle = random.randint(-1,1)
self.mag = random.randint(-500,-400)
self.velocity = vec(0,self.mag).rotate(0)
self.acceleration = vec(0,0)
self.birthTime = pygame.time.get_ticks()
self.size_counter_time = pygame.time.get_ticks()
#random lifespan
self.activeDuration = random.choice([3000,4000,5000,6000])
self.colorCollection = col
self.size = 3
#posDir is a check for postive direction, half the particles will have positive x velocity half will have negetive
self.posDir = False
randInt = random.choice([0,1])
if randInt == 1:
self.posDir = True
self.XVelOffset = random.randint(0,70)
def draw(self):
#select random color and draw
choice = random.choice(self.colorCollection)
pygame.draw.circle(self.main.screen,choice,(int(self.position.x),int(self.position.y)),self.size)
def update(self):
#die when lifespan over
now = pygame.time.get_ticks()
if now-self.birthTime > self.activeDuration:
self.main.FountainParticles.remove(self)
#decrease size after set interval (JUST AS A TEST)
if now - self.size_counter_time > 200:
self.size_counter_time = now
self.size-= 1
if self.size < 2 :
self.size = 2
if self.posDir:
self.position.x += self.XVelOffset*self.main.dt
if not self.posDir:
self.position.x -= self.XVelOffset*self.main.dt
self.update_position() #From Particle class