#handles the smoke present at the screen at this time
import random 
import common_pygame
import load_resources

single_sprites=load_resources.single_sprites
pygame = common_pygame.pygame
screen= common_pygame.screen

class Smoke():
	def __init__(self, x, y, life, size):
		self.x = x
		self.y = y
		self.life = life
		self.size = size

	def getBlitCoords(self):
		return (self.x-(25-self.size),self.y-(25-self.size))

	def getSizeTuple(self):
		return (self.size, self.size)
		
smokes = list()

#size : 1 : asteroids, 2: ships, 3: boss
def addSmoke ( x, y, size):
	smokes.append(Smoke(x, y, 256, size))
	



def blitAndUpdate():
	for i in smokes:
		#delete the particles that are too old
		smokes[:]=[s for s in smokes if s.life > 0]
		for (index, smoke) in enumerate(smokes):
			#blit the concerned particle
			smoke.life -= 1

			if smoke.size > 0 and smoke.life%8==0:
				smoke.size -= 1
				
			toblit =  pygame.transform.scale(single_sprites['smoke.png'],smoke.getSizeTuple())
			screen.blit(toblit, smoke.getBlitCoords())
		
			smokes[index]=smoke
			
