def __init__( self, game, alien ): Object.__init__( self, game ) self.image = pygame.image.load( "img/missile_alien.png" ).convert() add_noise(self.image) self.image.set_colorkey(Color.KEY) self.rect = self.image.get_rect() self.rect.centerx = alien.rect.centerx + random.randint( -8, 8 ) self.rect.centery = alien.rect.centery + alien.rect.height
def __init__( self, game ): Object.__init__( self, game ) self.image = pygame.image.load( "img/missile_player.png" ).convert() add_noise(self.image) self.image.set_colorkey(Color.KEY) self.rect = self.image.get_rect() self.rect.centerx = self.game.player.rect.centerx self.rect.centery = self.game.player.rect.centery - self.game.player.rect.height
def __init__(self, width, height, title): """Create pygame window with specified geometry and title""" self.width = width self.height = height self.surface = pygame.display.set_mode((width, height)) self.noise = pygame.Surface.copy(self.surface) self.noise.fill(Color.BG) add_noise(self.noise) pygame.display.set_caption(title) try: pygame.display.set_icon(pygame.image.load(Conf.WINDOW_ICON)) except: pass
def Draw(self, surface): image = self.font.render(self.text, False, self.color, Color.KEY) image = image.convert(24) add_noise(image) image.set_colorkey(Color.KEY) rect = image.get_rect() if self.center: rect.centerx = self.x rect.centery = self.y else: rect.left = self.x rect.top = self.y surface.blit(image, rect)
def __init__( self, game, fname, fname2 ): """ Pass filenames of 2 images that animation will alternate. """ Object.__init__( self, game ) self.image = pygame.image.load( fname ).convert() self.image2 = pygame.image.load( fname2 ).convert() self.imageHit = pygame.image.load( "img/explosion.png" ).convert() add_noise(self.image) add_noise(self.image2) add_noise(self.imageHit) self.image.set_colorkey(Color.KEY) self.image2.set_colorkey(Color.KEY) self.imageHit.set_colorkey(Color.KEY) self.rect = self.image.get_rect()
def __init__( self, game ): Object.__init__( self, game ) self.game = game self.image = pygame.image.load( "img/player.png" ).convert() self.image2 = pygame.image.load( "img/playerb.png" ).convert() self.imageHit = pygame.image.load( "img/explosion.png" ).convert() add_noise(self.image) add_noise(self.image2) add_noise(self.imageHit) self.image.set_colorkey(Color.KEY) self.image2.set_colorkey(Color.KEY) self.imageHit.set_colorkey(Color.KEY) self.rect = self.image.get_rect() self.imageFlip = False self.step = 3 * self.game.stride self.fire = False self.fireLatency = 3 self.salvo = 3 self.livesReset = Conf.PLAYER_LIVES self.lives = Conf.PLAYER_LIVES # Reset() does the rest. self.Reset( self.livesReset )