Exemplo n.º 1
0
    def hit_paddle(self, paddle):
        # Spawn a few particles.
        self.spawn_particles()

        # Calculate the spin.
        self.calculate_smash(paddle)

        # Tell ourselves that we have been hit.
        self.on_hit()

        # Tell the paddle that it has been hit.
        paddle.on_hit(self)

        # Tell all the effects that we've just hit a paddle.
        for effect in self.effect_group:
            effect.on_hit_paddle(paddle)

        # Attach a new flash effect to the ball.
        self.effect_group.add(
            flash.Flash(self, copy.copy(Ball.smash_effect_start_color),
                        copy.copy(Ball.smash_effect_final_color),
                        Ball.smash_effect_tick_amount))

        # Change the owner of the ball to the owner of the paddle.
        self.change_owner(paddle.owner)

        # We hit a paddle, so...
        self.collided = True
Exemplo n.º 2
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)
Exemplo n.º 3
0
	def on_hit(self, entity):
		# If hit by an enemy ball, we increase our owners energy.
		if entity.owner != self.owner:
			if self.owner.energy + self.owner.energy_increase_on_hit < self.owner.max_energy:
				self.owner.energy += self.owner.energy_increase_on_hit
			else:
				self.owner.energy = self.owner.max_energy
		else:
			if self.owner.energy + self.owner.energy_increase_on_hit < self.owner.max_energy:
				self.owner.energy += self.owner.energy_increase_on_hit / 2.0
			else:
				self.owner.energy = self.owner.max_energy

		# Create a new on hit effect.
		self.effect_group.add(flash.Flash(self, copy.copy(Paddle.hit_effect_start_color), copy.copy(Paddle.hit_effect_final_color), Paddle.hit_effect_tick_amount))
Exemplo n.º 4
0
    def __init__(self, x, y, width, height):
        # We start by calling the superconstructor.
        pygame.sprite.Sprite.__init__(self)

        # Create the rect used for collision detection, position etc.
        self.rect = pygame.rect.Rect(x, y, width, height)

        # Keep track of x and y as floats, for preciseness sake (rect keeps track of x,y as ints)
        self.x = x
        self.y = y
        self.center_y = self.y

        # Keep track of whether or not this is a "display" powerup.
        self.is_display = False

        # Keep track of whether or not this powerup should bob.
        self.bob = True
        self.start_time = pygame.time.get_ticks()
        self.passed_time = 0

        # Store self in the main powerup_group.
        groups.Groups.powerup_group.add(self)

        # We also create an effect_group ourselves, in case anyone wants to add any sort of effect to us.
        self.effect_group = pygame.sprite.Group()

        # We create a flash effect as a sort of spawn effect.
        self.effect_group.add(
            flash.Flash(self, copy.copy(Powerup.spawn_effect_start_color),
                        copy.copy(Powerup.spawn_effect_final_color),
                        Powerup.spawn_effect_tick_amount))

        # Play a random sound from the sound_effects list.
        sound = Powerup.sound_effects[random.randrange(
            0, len(Powerup.sound_effects))].play()
        if not sound is None:
            sound.set_volume(settings.SOUND_VOLUME)
Exemplo n.º 5
0
 def add_flash(self, start_color, final_color, tick_amount):
     self.effect_group.add(
         flash.Flash(self, start_color, final_color, tick_amount))