def produce_particles(self): if not self.particle_system._executing: return remove = [] for p in self.points: p.life += 1 if not p.death_timer == None and p.life == p.death_timer: remove.append(p) continue if p.stop_producing_particles: continue if not p.wait_rate == None: if p.wait < p.wait_rate: p.wait += 1 continue p.wait = 0 for i in range(self.rate if p.rate == None else p.rate): angle = random.randrange(p.angle_from, p.angle_to) pos = p.pos if self.shift_pos > 0: pos = Game.move_forward(pos, random.randrange(0, self.shift_pos), angle) self.particles.add(Particle(pos, 0.0, angle, 0)) for p in remove: self.points.remove(p)
def update_and_draw_particles(self): glPushMatrix() glEnable(GL_POINT_SPRITE) glTexEnvf(GL_POINT_SPRITE, GL_COORD_REPLACE, GL_TRUE) glEnable(GL_TEXTURE_2D) glBindTexture(GL_TEXTURE_2D, self.texture.surface) Game.engine['gfx'].last_image = self.texture.surface glBlendFunc(GL_SRC_ALPHA, GL_ONE) glPointSize(self.texture.width * self.size) glBegin(GL_POINTS) to_remove = [] for x in self.particles: if self.particle_system._executing: x.pos = Game.move_forward(x.pos, self.speed, x.angle) if self.spin_speed: x.angle += self.spin_speed if x.alpha > 0.0: glColor4f(self.colour[0],self.colour[1],self.colour[2],x.alpha) glVertex2f(x.pos[0], x.pos[1]) if self.particle_system._executing: if x.mode == 0: x.alpha += self.fade_in_speed if x.alpha >= 0.5: x.mode = 1 else: x.alpha -= self.fade_out_speed if x.alpha <= 0.0: to_remove.append(x) for x in to_remove: self.particles.remove(x) glEnd() glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) glDisable(GL_POINT_SPRITE) glPopMatrix()
def test_returns_correct_value_for_non_normalised_angle(self): result = Game.move_forward((4, 5), 10.0, 380) self.assertAlmostEquals(13.397, result[0], 3) self.assertAlmostEquals(8.420, result[1], 3)
def test_returns_correct_value_for_negative_distance(self): result = Game.move_forward((4, 5), -10.0, 20) self.assertAlmostEquals(-5.397, result[0], 3) self.assertAlmostEquals(1.580, result[1], 3)
def test_returns_correct_value_for_zero_distance(self): result = Game.move_forward((4, 5), 0, 20) self.assertEquals((4, 5), tuple(result))
def test_returns_correct_value_for_quadrant_4(self): result = Game.move_forward((4, 5), 10.0, 20 - 90) self.assertAlmostEquals(7.420, result[0], 3) self.assertAlmostEquals(-4.397, result[1], 3)
def test_returns_correct_value_for_quadrant_3(self): result = Game.move_forward((4, 5), 10.0, 20 + 180) self.assertAlmostEquals(-5.397, result[0], 3) self.assertAlmostEquals(1.580, result[1], 3)