Esempio n. 1
0
    def mushroom_attack_loop(self):
        g = self.g
        if self.health <= 0:
            if self.feeling != 'dead':
                self.feeling = 'dead'
                self.timer = 0
                
        if self.feeling == 'dead':
            if self.timer > 70:
                self.image = pygame.Surface((1, 1), SRCALPHA)
                self.dead = 1
                return
            if self.timer % 10 == 0:
                self.exp2.play()
            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)
                e = Effect(self.g, 'explosion', (self.rect.x + x, self.rect.y + y))
            return


        if self.timer % 20 == 1:
            if self.timer % 200 < 100:
                c = random.randint(0, 20)
                s = Shot(self.g, self.direction, (self.rect.x + 128, self.rect.y + 128 + c), 'shot5', 'enemy')
                s.callback = self.create_slime_monster
                self.squirt2.play()

        s = Rect(self.rect)
        s.x += 80
        s.width -= 100
        s.y += 100
        s.height -= 180
        if s.colliderect (g.player.rect):
            g.player.touch(self)

        for b in g.bullets:
            if b.owner == 'player':
                drect = (b.rect.x + 30, b.rect.y )
                if s.collidepoint(drect):
                    b.destroy()
                    self.health -= b.get_damage()
                    e = Effect(self.g, 'health', (self.rect.x, self.rect.y))
                    e.healthchange = -b.get_damage()
                    tmp = pygame.Surface((256, 256), SRCALPHA)
                    tmp.blit(self.image, (0,0))
                    tmp.blit(self.secondImage, (0,0))
                    self.image = tmp
                    self.hitme.play()
                    
        speed = 2
        self.rect.x += (1 - (self.direction * 2)) * speed
        self.draw_health_meter()
Esempio n. 2
0
    def fox_attack_loop(self):
        g = self.g

        if self.health <= 0:
            self.feeling = 'sad'
            self.health = 0
            if self.attacking == 3:
                self.feeling = 'dead'
                self.rect.y += 3
            else:
                self.attacking = 0
            self.walking = 0
            self.jumping = 0
            self.walktopos = (self.rect.x, self.rect.y)
            return
        
        self.timer += 1

        if self.jumping == 1:
            self.rect.y += self.jumpvec
            self.jumpvec += 1

        # if timer is in the minus, you're firing for a while
        if self.timer < 0:
            self.walking = 0
            if self.timer < -10:
                self.feeling = 'shooting'
                if self.attacking == 1:# first battle
                    if self.timer % 2 == 0:
                        s = Shot(g, self.direction, (self.rect.x + 44, self.rect.y + 35), 'shot3', 'enemy')
                elif self.attacking == 2: # second battle
                    if self.timer % 4 == 0:
                        s = Shot(g, self.direction, (self.rect.x + 44, self.rect.y + 35), 'shot3', 'enemy')
                        s.keep_alive = 6
                elif self.attacking == 3: # last
                    if self.timer % 10 == 0:
                        s = Shot(g, self.direction, (self.rect.x + 44, self.rect.y + 35), 'shot8', 'enemy')
        else:
            self.feeling = 'normal'
            speed = 4
            if self.attacking == 2:
                speed = 5
            self.rect.x += (1 - (self.direction * 2)) * speed
            self.rect.y += 2 # gravity
            if self.walktopos == (self.rect.x, self.rect.y) : # walking into something
                self.jumping = 1
                self.jumpvec = -10
            if self.attacking == 1: # first battle with fox
                if self.timer == 2:
                    self.jumping = 1
                    self.jumpvec = -10
                # shooting every random interval
                if random.randint(0, 70) == 0 and self.framecount > 10:
                    self.timer = -30
            if self.attacking == 2 or self.attacking == 3: # second battle with Fox
                dv = self.rect.x - self.g.player.rect.x
                if dv > 200:
                    self.direction = 1
                if dv < -200:
                    self.direction = 0
                if self.jumping == 0:
                    # jumping every 30 frames
                    if self.framecount % 40 == 0 and self.jumping == 0:
                        self.jumping = 1
                        self.jumpvec = -10
                        if self.attacking == 3:
                            self.jumpvec = -15
                    # shooting every random interval
                    elif random.randint(0, 15) == 0 and self.framecount > 10:
                        self.timer = -30
            self.framecount += 1
            self.walking = 1
            self.walktopos = (self.rect.x, self.rect.y)
        
        # hitting the bullets and player
        s = Rect(self.rect)
        if s.colliderect (g.player.rect):
            g.player.touch(self)
        for b in g.bullets:
            if b.owner == 'player':
                drect = (b.rect.x + 30, b.rect.y )
                if s.collidepoint(drect):
                    b.destroy()
                    self.health -= b.get_damage()
                    e = Effect(self.g, 'health', (self.rect.x, self.rect.y))
                    e.healthchange = -b.get_damage()
                    if self.feeling != 'sad':
                        self.hitme.play()
                    self.feeling = 'sad'
                    self.image = g.make_image_white(self.image, (96, 64))