# exhaust trails class import pygame from pygame.locals import * import game, gfx, math from random import randrange import gameinit SIZE = [1,1] # pixels DELAY = 3 LIFE = 50 / DELAY YELLOW = [249,229,9] BLACK = [20, 20, 40] WHITE = [255, 255, 255] LIGHTGRAY = [180, 180, 180] DARKGRAY = [120, 120, 120] class ExhaustParticle: def __init__(self,x,y,image): self.image = image self.rect = self.image.get_rect().move(x,y) self.lastrect = self.rect self.life = LIFE self.dx = -game.groundspeed * DELAY class Exhaust: def __init__(self, activerect=None): self.blit = gfx.surface.blit self.dirty = gfx.dirty self.counter = 0 # build image color = YELLOW self.image = pygame.Surface(SIZE).convert(gfx.surface) self.image.fill(color) if activerect == None: # whole screen self.rect = gfx.rect else: self.rect = activerect self.particles = [] self.lastparticles = self.particles self.timer = 0 def add_particle(self,x,y): self.particles.append(ExhaustParticle(x,y,self.image)) def erase_and_check_life(self,particle): self.dirty(self.background(particle.lastrect)) particle.life += -1 if particle.life > 0: return particle else: return None def tick_and_draw(self,particle): particle.rect.left = (particle.rect.left + particle.dx * self.speedadjust) self.dirty(self.blit(particle.image, particle.rect)) particle.lastrect = particle.rect def erase_tick_draw(self, background, gfx,speedadjust): self.timer += 1 if self.timer % DELAY !=0: return self.speedadjust = speedadjust self.background = background # erase & check life, make list of new particles self.particles = map(self.erase_and_check_life,self.lastparticles) # remove extra Nones from the list self.particles = filter(lambda x: x != None,self.particles) # tick, draw map(self.tick_and_draw,self.particles) self.lastparticles = self.particles