-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththrust.py
More file actions
37 lines (34 loc) · 1.41 KB
/
Copy paththrust.py
File metadata and controls
37 lines (34 loc) · 1.41 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
from utility import *
import pygame,random
vec = pygame.math.Vector2
from particle import *
class ThrustNode(Particle):
""" Thrust of rocket """
def __init__(self,main,v,x,y,col):
self.main = main
#X-offset at place of origin
self.xoffset = random.randint(-2,2)
self.position = vec(x,y)
#adding x offset to spwan position
self.position.x += self.xoffset
#random magnitude of initial velocity and angle
self.angle = random.randint(-5,5)
self.magVel = random.randint(100,500)
self.velocity = v
self.velocity += vec(0,self.magVel).rotate(self.angle)
self.acceleration = vec(0,0)
#time of spwan
self.birthTime = pygame.time.get_ticks()
self.activeDuration = 10
self.colorCollection = ORANGEFUN
self.size = 2
def draw(self):
#selecting a random colour from colorCollection array and drawing a circle at the calculated position
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):
#if survived more than lifespan then kill
now = pygame.time.get_ticks()
if now-self.birthTime > self.activeDuration:
self.main.ThrustContainer.remove(self)
self.update_position() #defined in Particle class