Exemple #1
0
    def fire(self, rate, target=None):
        if self.fire_rate > 0:
            self.fire_rate -= 1
            return
        self.fire_rate = rate

        shot = Shot(self.screen, self.x, self.y + 40, self, target)

        player = self.screen.player

        dx = player.x - self.x
        dy = player.y - self.y - 15

        total = sqrt(dx ** 2 + dy ** 2)
        shot.xvel = dx / total * 15
        shot.yvel = dy / total * 15

        shot.range = 100
    def doctor_attack_loop(self):
        speed = 6
        self.feeling = 'walking'
        g = self.g

        if self.health <= 0:
            #destoryed walking too 813
            targntx = self.rect.x
            if targntx > 813 + speed * 2: # walked too far left left
                self.dx -= .5
                if self.dx < -speed:
                    self.dx = -speed
                self.rect.x += int(self.dx)
                self.timer = self.timer % 10
            elif targntx < 813 - speed * 2:# walked too far right
                self.dx += .5
                if self.dx > speed:
                    self.dx = speed
                self.rect.x += int(self.dx)
                self.timer = self.timer % 10
            else:
                if self.spawnedspecialnurse == 0:
                    print 'spawn special nurse'
                    self.spawnedspecialnurse = 1
                    s = Shot(self.g, self.direction, (self.rect.x + 128, self.rect.y + 80 ), 'shot6', 'enemy')
                    s.callback = self.create_nurse_character
                    s.xvel = 0
            if self.timer < 70:
                if self.timer % 3 == 0:
                    # flash on and off
                    self.image = pygame.Surface((1, 1), SRCALPHA)
                else:
                    x = random.randint(0, 256)
                    y = random.randint(0, 256)
                    Effect(self.g, 'explosion', (self.rect.x + x, self.rect.y + y))
            return
        #self.timer += 1
        dx = (self.rect.x + self.rect.width/2) - g.player.rect.x
        dy = (self.rect.y + self.rect.height) - g.player.rect.y
        pdrect = 100
        if self.timer % 1000 > 400:
            pdrect = 400
            if self.dx < 0 and self.dx > -speed:
                self.dx += -.5
            if self.dx > 0 and self.dx < speed:
                self.dx += .5
        if dx > pdrect: # walked too far left left
            self.dx -= .5
            if self.dx < -speed:
                self.dx = -speed
        elif dx < -pdrect:# walked too far right
            self.dx += .5
            if self.dx > speed:
                self.dx = speed

        # attck with arms
        if dx > 70 and dx < 140:
            if dy <50 and dy > 0:
                if self.attackleft == 0:
                    self.attackleft = 1
                if self.attackleft == 5:
                    g.player.touch(self)
        # attack with the right arm
        if dx < -70 and dx > -140:
            if dy <50 and dy > 0:
                if self.attackright == 0:
                    self.attackright = 1
                if self.attackright == 5:
                    g.player.touch(self)
        # scratching self to stop continius shooting
        if self.timer % 1000 > 600:
            self.attackright = 10
        # tracks hittin the player
        #if dx > -40 and dx < 40:
        #    if dy < 40 and dy > 0:
        #        g.player.touch(self)
        # like the monotane, it shits out little babies
        if self.timer % 20 == 1:
            if self.timer % 400 < 200:
                c = random.randint(0, 20)
                s = Shot(self.g, self.direction, (self.rect.x + 128, self.rect.y + 80 + c), 'shot6', 'enemy')
                s.callback = self.create_nurse_monster
                self.squirt.play()


        self.rect.x += int(self.dx)
        self.draw_health_meter()