def __init__(self, x, y): # We start by calling the superconstructor. powerup.Powerup.__init__(self, x, y, Multiball.width, Multiball.height) # Load the image file. self.image = Multiball.image.copy() # Create a shadow. self.shadow = shadow.Shadow(self)
def set_size(self, new_width, new_height): # Set the actual width and height to the new width and height. self.actual_width = new_width self.actual_height = new_height # Temporarily store the old width and height, used for positioning the paddle later. old_width = self.rect.width old_height = self.rect.height # Change the rect width. if self.actual_width > self.max_width: self.rect.width = self.max_width elif self.actual_width < self.min_width: self.rect.width = self.min_width else: self.rect.width = self.actual_width # Change the rect height. if self.actual_height > self.max_height: self.rect.height = self.max_height elif self.actual_height < self.min_height: self.rect.height = self.min_height else: self.rect.height = self.actual_height # Make sure the position of the paddle isn't changed. self.x += (old_width - self.rect.width) / 2.0 self.y += (old_height - self.rect.height) / 2.0 if hasattr(self, 'image'): # Resize the current image. self.image = pygame.transform.scale(self.image, (self.rect.width, self.rect.height)) else: # Create the image attribute that is drawn to the surface. self.image = pygame.Surface((self.rect.width, self.rect.height), pygame.locals.SRCALPHA) # Blit the top part. self.image.blit(Paddle.top_image, (0, 0)) # Blit the middle parts. for i in range(Paddle.top_image.get_height(), self.rect.height - Paddle.bottom_image.get_height()): self.image.blit(Paddle.middle_image, (0, i)) # Blit the bottom part. self.image.blit(Paddle.bottom_image, (0, self.rect.height - Paddle.bottom_image.get_height())) useful.colorize_image(self.image, copy.copy(self.owner.color), False, False) # If the shadow already exists, kill it first. if hasattr(self, 'shadow'): self.shadow.kill() # Then, create a (new) shadow. self.shadow = shadow.Shadow(self)
def __init__(self, x, y, angle, owner, target): # 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, self.__class__.width, self.__class__.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 # We store the given angle of the Missile. self.angle = angle # We store the given speed of the Missile. self.speed = self.__class__.speed # Store the given acceleration. self.acceleration = self.__class__.acceleration # If this is set to anything higher than 0, this missile will not "fire" until this reaches 0. self.delay = 0 # Store the owner. self.owner = owner # Store the target. self.target = target # When this reaches particle_spawn_rate, a particle is spawned. self.particle_spawn_time = 0 # Load the image file. self.image = self.__class__.image.copy() # Store the original, unrotated version of the image. self.original_image = self.image.copy() # Store the angle to rotate the image separately. self.image_angle = self.angle # Create a shadow. self.shadow = shadow.Shadow(self) # Rotate it to the given angle. self.rotate_image(self.image_angle * (180 / math.pi)) # Add self to the projectile group. groups.Groups.projectile_group.add(self) # If we want, we can connect powerups to this effect that is killed when this missile is killed. Primarily used to # connect the powerups that are displayed on the player. self.displayed_powerups = []
def __init__(self, x, y): # We start by calling the superconstructor. powerup.Powerup.__init__(self, x, y, Fire.width, Fire.height) # When this reaches particle_spawn_rate, a particle is spawned. self.particle_spawn_time = 0 # Load the image file. self.image = Fire.image.copy() # Create a shadow. self.shadow = shadow.Shadow(self)
def __init__(self, x, y, width, height, angle, speed, retardation, color, alpha_step=0): # We start by calling the superconstructor. pygame.sprite.Sprite.__init__(self) # Create the rect used for drawing the particle. self.rect = pygame.rect.Rect(x, y, width, height) # This can be set if you spawn particles outside the game. self.kill_outside_level = True self.kill_when_speed_reaches_zero = True # 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 # Setup speed, angle and retardation values, used when moving the particle. self.angle = angle self.speed = speed self.retardation = retardation self.gravity = 0 self.velocity_y = 0 # Setup alpha values. self.alpha_step = alpha_step self.alpha = 255 # Setup the color values, used for drawing the particle. self.color = copy.copy(color) # Since we're using fill, we create a surface with SRCALPHA to handle alpha. self.surface = pygame.Surface((self.rect.width, self.rect.height), SRCALPHA) # Setup shadow color value, used for coloring the shadow. self.shadow_color = useful.blend_colors(self.color, Particle.shadow_blend_color) # Create a shadow. self.shadow = shadow.Shadow(self, self.shadow_color, True, True) # Add self to the main particle_group. groups.Groups.particle_group.add(self)
def __init__(self, x, y): # We start by calling the superconstructor. powerup.Powerup.__init__(self, x, y, Frost.frame_width, Frost.frame_height) # When this reaches particle_spawn_rate, a particle is spawned. self.particle_spawn_time = 0 # Generate the animation frames. self.frames = useful.create_frames_from_sheet(Frost.image_sheet, Frost.frame_width, Frost.frame_height) self.image = self.frames[1] # This affects how far the powerup must be from it's center y to change frames. self.center_y_grace = 0.2 * settings.GAME_SCALE # Create a shadow. self.shadow = shadow.Shadow(self)
def __init__(self, x, y, owner): # We start by calling the superconstructor. block.Block.__init__(self, owner, x, y, StrongBlock.width, StrongBlock.height, StrongBlock.health) # Create the image attribute that is drawn to the surface. self.image = StrongBlock.image.copy() # Colorize the block. self.color = self.owner.color useful.colorize_image(self.image, self.color) # Create the image that is drawn when health is half or less. self.half_health_image = StrongBlock.half_health_image.copy() # Colorize that image. self.half_health_color = useful.blend_colors( self.owner.color, block.Block.half_health_blend_color) useful.colorize_image(self.half_health_image, self.half_health_color) # Create a shadow. self.shadow = shadow.Shadow(self)
def __init__(self, x, y, angle, owner): # 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, Ball.width, Ball.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 # Keep track of the balls position in the previous frame, used for collision handling. self.previous = pygame.rect.Rect(self.x, self.y, Ball.width, Ball.height) # Set the angle variable. self.angle = angle # Set maximum speed of the ball. self.max_speed = Ball.max_speed # Set the speed variable. self.speed = Ball.speed self.tick_speed = self.speed # Store the current level of smash stack. self.smash_stack = 0 # Store the owner. self.owner = owner # Create one image attribute per player. self.player_images = {} for player in groups.Groups.player_group: player_image = Ball.image.copy() # Colorize the image to the color of the player. useful.colorize_image(player_image, player.color) # Finally, add this image to the list of player images. self.player_images[player] = player_image # Create the image attribute that is drawn to the surface. self.image = self.player_images[self.owner] # We save a reference to the parents color in our own variable, so that classes and modules # that want to use our color do not have to call us.owner.color. self.color = self.owner.color # If collided is True, the ball sound is played. self.collided = False # Setup the trace time keeping variable. self.trace_spawn_time = 0 # Create a shadow. self.shadow = shadow.Shadow(self) # Store the ball in the owners ball_group and the main ball_group. self.owner.ball_group.add(self) groups.Groups.ball_group.add(self) # Create an effect group to handle effects on this ball. self.effect_group = pygame.sprite.Group()