예제 #1
0
    def update(self, main_clock):
        # We make sure to call the supermethod.
        powerup.Powerup.update(self, main_clock)

        # If it's time, spawn particles.
        self.particle_spawn_time += main_clock.get_time()
        if self.particle_spawn_time >= Fire.particle_spawn_rate:
            # Reset the particle spawn time.
            self.particle_spawn_time = 0

            # Spawn a random amount of particles.
            for _ in range(
                    0,
                    random.randrange(Fire.particle_least_spawn_amount,
                                     Fire.particle_maximum_spawn_amount)):
                width = random.uniform(self.rect.width / 8.0,
                                       self.rect.width / 5.0)
                angle = random.uniform(0, 2 * math.pi)
                speed = random.uniform(
                    0.75 * settings.GAME_FPS * settings.GAME_SCALE,
                    0.9 * settings.GAME_FPS * settings.GAME_SCALE)
                retardation = speed / 24.0
                if random.random() > 0.1:
                    color = pygame.Color(random.randint(200, 255),
                                         random.randint(0, 255), 0)
                else:
                    a_color = random.randint(0, 255)
                    color = pygame.Color(a_color, a_color, a_color)
                particle.Particle(self.x + self.rect.width / 2,
                                  self.y + self.rect.height / 2, width, width,
                                  angle, speed, retardation, color,
                                  5 * settings.GAME_FPS)
예제 #2
0
    def destroy(self):
        self.kill()

        for _ in range(64):
            width = random.uniform(1 * settings.GAME_SCALE,
                                   2.5 * settings.GAME_SCALE)
            angle = random.uniform(0, 2 * math.pi)
            speed = random.uniform(
                1.0 * settings.GAME_FPS * settings.GAME_SCALE,
                2.25 * settings.GAME_FPS * settings.GAME_SCALE)
            retardation = 0.1 * settings.GAME_FPS
            color = pygame.Color(255, 0, 0)
            color.hsla = (random.uniform(0, 360), color.hsla[1], color.hsla[2],
                          color.hsla[3])
            a_particle = particle.Particle(self.x + self.rect.width / 2.0,
                                           self.y + self.rect.height / 2.0,
                                           width, width, angle, speed,
                                           retardation, color,
                                           5 * settings.GAME_FPS)
            a_particle.kill_outside_level = False
            a_particle.kill_when_speed_reaches_zero = False
            a_particle.gravity = 0.05 * settings.GAME_SCALE

        # Play a random sound from the sound_effects list.
        sound = Firework.sound_effects[random.randrange(
            0, len(Firework.sound_effects))].play()
        if not sound is None:
            sound.set_volume(settings.SOUND_VOLUME / 8.0)
예제 #3
0
    def update(self, main_clock):
        # We make sure that our size matches the parent.
        if self.parent.__class__ == paddle.Paddle:
            if self.parent.rect.width != self.image.get_width(
            ) or self.parent.rect.height != self.image.get_height():
                self.image = pygame.transform.scale(
                    self.image,
                    (self.parent.rect.width, self.parent.rect.height))
                self.create_final_image()

        # We make sure to call the supermethod.
        effect.Effect.update(self, main_clock)

        # If it's time, spawn particles.
        self.particle_spawn_time += main_clock.get_time()
        if self.particle_spawn_time >= Stun.particle_spawn_rate:
            # Reset the particle spawn time.
            self.particle_spawn_time = 0

            # Spawn a random amount of particles.
            for _ in range(0, random.randrange(2, Stun.particle_spawn_amount)):
                angle = random.uniform(0, 2 * math.pi)
                speed = random.uniform(
                    0.6 * settings.GAME_FPS * settings.GAME_SCALE,
                    0.35 * settings.GAME_FPS * settings.GAME_SCALE)
                retardation = speed / 25.0
                color_value = random.randint(100, 250)
                color = pygame.Color(color_value, color_value, color_value)
                particle.Particle(self.parent.x + self.parent.rect.width / 3,
                                  self.parent.y + self.parent.rect.height / 3,
                                  self.parent.rect.width / 3,
                                  self.parent.rect.width / 3, angle, speed,
                                  retardation, color, 1 * settings.GAME_FPS)
예제 #4
0
    def update(self, main_clock):
        # We make sure to call the supermethod.
        powerup.Powerup.update(self, main_clock)

        # If it's time, spawn particles.
        self.particle_spawn_time += main_clock.get_time()
        if self.particle_spawn_time >= Electricity.particle_spawn_rate:
            # Reset the particle spawn time.
            self.particle_spawn_time = 0

            # Spawn a random amount of particles.
            for _ in range(
                    0, random.randrange(2, Electricity.particle_spawn_amount)):
                angle = random.uniform(0, 2 * math.pi)
                speed = random.uniform(
                    0.9 * settings.GAME_FPS * settings.GAME_SCALE,
                    1.4 * settings.GAME_FPS * settings.GAME_SCALE)
                retardation = speed / 46.0
                random_value = random.randint(225, 255)
                color = pygame.Color(random_value, random_value,
                                     random.randint(0, 100))
                random_size = random.randint(self.rect.width / 8,
                                             self.rect.width / 6)
                particle.Particle(self.x + self.rect.width / 2,
                                  self.y + self.rect.height / 2, random_size,
                                  random_size, angle, speed, retardation,
                                  color, 20 * settings.GAME_FPS)
예제 #5
0
    def update(self, main_clock):
        # We make sure to call the supermethod.
        powerup.Powerup.update(self, main_clock)

        # Update the current image.
        if self.y < self.center_y - self.center_y_grace:
            self.image = self.frames[0]
        elif self.y > self.center_y + self.center_y_grace:
            self.image = self.frames[2]
        else:
            self.image = self.frames[1]

        # If it's time, spawn particles.
        self.particle_spawn_time += main_clock.get_time()
        if self.particle_spawn_time >= Frost.particle_spawn_rate:
            # Reset the particle spawn time.
            self.particle_spawn_time = 0

            # Spawn a random amount of particles.
            for _ in range(0, random.randrange(0,
                                               Frost.particle_spawn_amount)):
                angle = random.uniform(0, 2 * math.pi)
                speed = random.uniform(
                    0.2 * settings.GAME_FPS * settings.GAME_SCALE,
                    0.35 * settings.GAME_FPS * settings.GAME_SCALE)
                retardation = speed / 76.0
                color = pygame.Color(random.randint(0, 50),
                                     random.randint(125, 255),
                                     random.randint(220, 255))
                particle.Particle(self.x + self.rect.width / 2,
                                  self.y + self.rect.height / 2,
                                  self.rect.width / 4, self.rect.width / 4,
                                  angle, speed, retardation, color,
                                  3 * settings.GAME_FPS)
예제 #6
0
	def on_hit(self, damage):
		# Damage self.
		self.hurt(damage)

		# Create a new on hit effect.
		self.effect_group.add(flash.Flash(self, copy.copy(Block.hit_effect_start_color), copy.copy(Block.hit_effect_final_color), Block.hit_effect_tick_amount))

		# Spawn some particles.
		for _ in range(0, Block.particle_spawn_amount):
			angle = random.uniform(0, 2 * math.pi)
			speed = 5 * settings.GAME_FPS
			retardation = 0.25 * settings.GAME_FPS
			alpha_step = 5 * settings.GAME_FPS
			particle.Particle(self.x + self.rect.width / 2, self.y + self.rect.height / 2, Block.particle_size, Block.particle_size, angle, speed, retardation, self.color, alpha_step)
예제 #7
0
 def spawn_particles(self):
     # Spawn a slightly random amount of particles.
     for _ in range(0, Ball.particle_spawn_amount):
         width = random.uniform(self.rect.width / 4.0,
                                self.rect.width / 3.0)
         angle = self.angle + random.uniform(-0.20, 0.20)
         max_speed = min(self.speed, self.max_speed / 2.0)
         speed = random.uniform(max_speed - max_speed / 7.0,
                                max_speed + max_speed / 7.0)
         retardation = self.speed / 24.0
         alpha_step = 5 * settings.GAME_FPS
         particle.Particle(self.x + self.rect.width / 2,
                           self.y + self.rect.height / 2, width, width,
                           angle, speed, retardation, self.color,
                           alpha_step)
예제 #8
0
 def spawn_particles(self, entity):
     # Spawns a few particles with random color, angle, speed and so on.
     for _ in range(0, random.randrange(2, Charged.particle_spawn_amount)):
         angle = random.uniform(0, 2 * math.pi)
         speed = random.uniform(
             0.9 * settings.GAME_FPS * settings.GAME_SCALE,
             1.4 * settings.GAME_FPS * settings.GAME_SCALE)
         retardation = speed / 46.0
         random_value = random.randint(225, 255)
         color = pygame.Color(random_value, random_value,
                              random.randint(0, 100))
         random_size = random.randint(self.rect.width / 4,
                                      self.rect.width / 3)
         particle.Particle(self.rect.x + self.rect.width / 2,
                           self.rect.y + self.rect.height / 2, random_size,
                           random_size, angle, speed, retardation, color,
                           20 * settings.GAME_FPS)
예제 #9
0
    def update(self, main_clock):
        # We make sure to call the supermethod.
        effect.Effect.update(self, main_clock)

        if self.parent.owner == self.real_owner:
            # If the parent has health, deal damage to it.
            if hasattr(self.parent, "health"):
                self.parent.hurt(Burning.damage_per_second *
                                 main_clock.delta_time)

            # If it's time, spawn particles.
            self.particle_spawn_time += main_clock.get_time()
            if self.particle_spawn_time >= Burning.particle_spawn_rate:
                # Reset the particle spawn time.
                self.particle_spawn_time = 0

                # Spawn a random amount of particles.
                for _ in range(
                        0,
                        random.randrange(
                            Burning.particle_least_spawn_amount,
                            Burning.particle_maximum_spawn_amount)):
                    width = random.uniform(self.parent.rect.width / 4.0,
                                           self.parent.rect.width / 2.0)
                    if hasattr(self.parent, "angle"):
                        angle = self.parent.angle + random.uniform(
                            -math.pi / 5.0, math.pi / 5.0)
                    else:
                        angle = random.uniform(0, 2 * math.pi)
                    speed = random.uniform(
                        0.5 * settings.GAME_FPS * settings.GAME_SCALE,
                        0.9 * settings.GAME_FPS * settings.GAME_SCALE)
                    retardation = speed / 24.0
                    if random.random() > 0.1:
                        color = pygame.Color(random.randint(200, 255),
                                             random.randint(0, 255), 0)
                    else:
                        a_color = random.randint(0, 255)
                        color = pygame.Color(a_color, a_color, a_color)
                    particle.Particle(
                        self.parent.x + self.parent.rect.width / 2,
                        self.parent.y + self.parent.rect.height / 2, width,
                        width, angle, speed, retardation, color,
                        5 * settings.GAME_FPS)
예제 #10
0
 def spawn_destroy_particles(self):
     # Spawn a random amount of particles.
     for _ in range(
             0,
             random.randrange(self.__class__.hit_particle_min_amount,
                              self.__class__.hit_particle_max_amount)):
         width = random.uniform(self.__class__.width / 4.5,
                                self.__class__.width / 3.25)
         angle = self.angle + math.pi
         angle += random.uniform(math.pi - (math.pi / 16.0),
                                 math.pi + (math.pi / 16.0))
         speed = min(
             max(self.speed, self.__class__.hit_particle_min_speed),
             self.__class__.hit_particle_max_speed) * random.uniform(
                 0.75, 1.25)
         retardation = speed / 21.0
         color = pygame.Color(random.randint(200, 255),
                              random.randint(0, 255), 0)
         particle.Particle(self.x + self.rect.width / 2,
                           self.y + self.rect.height / 2, width, width,
                           angle, speed, retardation, color, 5)
예제 #11
0
    def update(self, main_clock):
        # We make sure that our size matches the parent.
        if self.parent_is_paddle:
            if self.parent.rect.width != self.image.get_width(
            ) or self.parent.rect.height != self.image.get_height():
                self.image = pygame.transform.scale(
                    self.image,
                    (self.parent.rect.width, self.parent.rect.height))
                self.create_final_image()

        # We make sure to call the supermethod.
        effect.Effect.update(self, main_clock)

        if self.parent.owner == self.real_owner:
            # If it's time, spawn particles.
            self.particle_spawn_time += main_clock.get_time()
            if self.particle_spawn_time >= Freezing.particle_spawn_rate:
                # Reset the particle spawn time.
                self.particle_spawn_time = 0

                # Spawn a random amount of particles.
                for _ in range(
                        0, random.randrange(0,
                                            Freezing.particle_spawn_amount)):
                    angle = random.uniform(0, 2 * math.pi)
                    speed = random.uniform(
                        0.2 * settings.GAME_FPS * settings.GAME_SCALE,
                        0.35 * settings.GAME_FPS * settings.GAME_SCALE)
                    retardation = speed / 76.0
                    color = pygame.Color(random.randint(0, 50),
                                         random.randint(125, 255),
                                         random.randint(220, 255))
                    particle.Particle(
                        self.parent.x + self.parent.rect.width / 2,
                        self.parent.y + self.parent.rect.height / 2,
                        self.parent.rect.width / 2, self.parent.rect.width / 2,
                        angle, speed, retardation, color,
                        3 * settings.GAME_FPS)
예제 #12
0
    def update(self, main_clock):
        # Check if we have collided with the target block.
        blocks_collide_list = pygame.sprite.spritecollide(
            self, self.target.owner.block_group, False)
        for block in blocks_collide_list:
            if block == self.target:
                self.on_hit_block(block)

        # Check if we have collided with any paddle.
        paddle_collide_list = pygame.sprite.spritecollide(
            self, self.target.owner.paddle_group, False)
        for paddle in paddle_collide_list:
            self.on_hit_paddle(paddle)

        # If the target is already destroyed, choose a new target.
        if self.target.health <= 0 or self.target == None:
            # Create a list of all available blocks to target.
            block_list = []
            for player in groups.Groups.player_group:
                if player != self.owner:
                    block_list = player.block_group.sprites()

            # If the list is not empty, set a random block as the target.
            if block_list:
                self.target = random.choice(block_list)
            else:
                # If the list is empty, simply destroy ourselves.
                self.destroy()
                self.spawn_destroy_particles()
                # Create a dummy and attach an explosion effect to it.
                a_dummy = dummy.Dummy(
                    1000,
                    self.rect.centerx - explosion.Explosion.frame_width / 2.0,
                    self.rect.centery - explosion.Explosion.frame_height / 2.0,
                    explosion.Explosion.frame_width,
                    explosion.Explosion.frame_height)
                a_dummy.effect_group.add(explosion.Explosion(a_dummy))

        # Keep angle between pi and -pi.
        if self.angle > math.pi:
            self.angle -= math.pi * 2
        elif self.angle < -math.pi:
            self.angle += math.pi * 2

        # Figure out the angle to the target
        delta_x = self.target.rect.centerx - self.rect.centerx
        delta_y = self.target.rect.centery - self.rect.centery
        angle_to_target = math.atan2(delta_y, delta_x)

        # Calculate the relative angle to target.
        relative_angle_to_target = angle_to_target - self.angle

        # Map relative angle to -pi <= angle <= +pi.
        if relative_angle_to_target > math.pi:
            relative_angle_to_target -= math.pi * 2
        elif relative_angle_to_target < -math.pi:
            relative_angle_to_target += math.pi * 2

        # Correct our own angle so it's closer to the target.
        self.angle += relative_angle_to_target * self.angle_correction * main_clock.delta_time

        # Update the speed according to the acceleration.
        self.speed += self.acceleration * main_clock.time_scale

        # Make sure speed doesn't go over max speed.
        if self.speed > self.max_speed:
            self.speed = self.max_speed

        # Move the missile with speed in consideration.
        self.x = self.x + (math.cos(self.angle) * self.speed *
                           main_clock.delta_time)
        self.y = self.y + (math.sin(self.angle) * self.speed *
                           main_clock.delta_time)
        self.rect.x = self.x
        self.rect.y = self.y

        # Convert the angle to degrees.
        if self.angle < 0:
            self.image_angle = self.angle * (180 / math.pi) + 360
        else:
            self.image_angle = self.angle * (180 / math.pi)
        self.image_angle += 90

        # Rotate the image to the angle, in degrees.
        self.rotate_image(-self.image_angle)

        # Improve the angle correction.
        self.angle_correction += self.angle_correction_rate * main_clock.delta_time

        # If it's time, spawn particles.
        self.particle_spawn_time += main_clock.get_time()
        if self.particle_spawn_time >= self.__class__.particle_spawn_rate:
            # Reset the particle spawn time.
            self.particle_spawn_time = 0

            # Spawn a random amount of particles.
            for _ in range(
                    0, random.randrange(1,
                                        self.__class__.particle_spawn_amount)):
                width = random.uniform(self.__class__.width / 5.0,
                                       self.__class__.width / 4.0)
                angle = self.angle + random.uniform(math.pi -
                                                    (math.pi / 24.0), math.pi +
                                                    (math.pi / 24.0))
                speed = random.uniform(
                    0.65 * settings.GAME_FPS * settings.GAME_SCALE,
                    1.1 * settings.GAME_FPS * settings.GAME_SCALE)
                retardation = speed / 24.0
                color = pygame.Color(random.randint(200, 255),
                                     random.randint(0, 255), 0)
                particle.Particle(self.x + self.rect.width / 2,
                                  self.y + self.rect.height / 2, width, width,
                                  angle, speed, retardation, color, 5)