def __init__(self,pos,lvl): self.anim = Animation(data.Camera.anim,True) AnimatedSprite.__init__(self) self.rect.center = pos if lvl: lvl.all.add(self) lvl.cameras.add(self) self.image.set_colorkey(self.image.get_at((0,0))) self.anim.index = random.randint(0,len(self.anim.seq)) self.direction = 'right' self.level = None
def update(self,level=None): self.level = level AnimatedSprite.update(self) if self.anim.index < 35 or self.anim.index > 205: self.direction = 'right' elif 138 > self.anim.index > 103: self.direction = 'left' else: self.direction = 'center' self.image.set_colorkey(self.image.get_at((0,0))) if self.level.player.rect.centery > self.rect.bottom \ and self._dist(self.level.player.rect) < 500: if self.direction == 'left' and \ self.level.player.rect.right < self.rect.left and \ 200 > self._dist(self.level.player.rect.right,self.rect.left) > 20: eventnet.driver.post('alarm',pos=self.rect.center) elif self.direction == 'right' and \ self.level.player.rect.left > self.rect.right and \ 200 > self._dist(self.level.player.rect.left,self.rect.right) > 20: eventnet.driver.post('alarm',pos=self.rect.center)
def __init__(self,level): #for name in ['walk_left', # 'walk_right', # 'die_back_left', # 'die_back_right', # 'die_forward_left', # 'die_forward_right']: # anim = getattr(self.animation_set,name) # setattr(self.animation_set,name,Animation(anim,True)) self.audio = Audio() self.audio.volume = 0.5 self.anim = self.animation_set.walk_right AnimatedSprite.__init__(self) self.level = level self.vy = 3 self.vx = 0 self.capture() self.image.set_colorkey(self.image.get_at((0,0))) self.punching = False self.kicking = False self.dying = False self.direction = 'right' self.enemies = []
def update(self,level): self.level = level self.level.enemies.sprites() if self.anim in [self.animation_set.walk_left, self.animation_set.punch_left, self.animation_set.die_forward_left, self.animation_set.die_back_left]: self.direction = 'left' else: self.direction = 'right' self.level = level self.image = self.anim.seq[0] old = self.rect.center self.rect.centery += self.vy if self.vy: self.vy += 0.1 if pygame.sprite.spritecollideany(self,self.level.floors) or \ pygame.sprite.spritecollideany(self,self.level.walls): self.rect.center = old self.vy = 0.1 old = self.rect.center self.rect.centerx += self.vx if pygame.sprite.spritecollideany(self,self.level.floors) or \ pygame.sprite.spritecollideany(self,self.level.walls): self.rect.center = old if self.flying: self.audio.play(random.choice(data.punch)) if self.punching or self.kicking: if self.anim.index == len(self.anim.seq)-1: self.recover() else: AnimatedSprite.update(self) elif self.dying: if self.anim.index < len(self.anim.seq)-1: AnimatedSprite.update(self) self.rect.centery += 0.5 if self.anim in [self.animation_set.die_back_left, self.animation_set.die_back_right]: if self.direction == 'right': self.rect.centerx -= 2 else: self.rect.centerx += 2 else: if self.direction == 'right': self.rect.centerx += 2 else: self.rect.centerx -= 2 elif self.vx > 0: i = self.anim.index self.anim = self.animation_set.walk_right self.anim.index = i AnimatedSprite.update(self) elif self.vx < 0: i = self.anim.index self.anim = self.animation_set.walk_left self.anim.index = i AnimatedSprite.update(self) self.image.set_colorkey(self.image.get_at((0,0)))
def kill(self): self.release() AnimatedSprite.kill(self)