Esempio n. 1
0
 def update(self, spriteStructure, time):
     self.updateStance()
     # The imp gets stunned if it hits the player, preventing it from following inside of him.
     self.scroll = spriteStructure.player.scroll
     if (self.stunnedTime <= 0):
         self.speed = self.direction
         if self.attackTime > 0:
             self.attackTime -= time
         if self.hitPlayer is not None and (self.attackTime <= 0):
             if (self.hitPlayer.looking == LEFT):
                 self.hitPlayer.stun(self.knockback, self.damage)
             else:
                 self.hitPlayer.stun(
                     (-self.knockback[0], self.knockback[1]), self.damage)
             self.attackTime = IMP_ATTACK_DELAY
             self.stunnedTime = IMP_STUN_DELAY
         self.hitPlayer = None
     else:
         self.stunnedTime -= time
     MySprite.update(self, time)
     if self.dead:
         self.onDeath(spriteStructure, time)
Esempio n. 2
0
    def update(self, spriteStructure, time):

        self.updateStance()
        MySprite.update(self, time)

        return
Esempio n. 3
0
    def update(self, spriteStructure, time):
        # Separate speed into components for code legibility
        # these are local and are set to the character at the end of the procedure
        (speedx, speedy) = self.speed
        platforms = pygame.sprite.spritecollide(self,
                                                spriteStructure.platformGroup,
                                                False)

        # First we check if for any reason the character has been killed or fallen oob.
        if self.dead or (self.position[1] > KILLING_FLOOR):
            self.onDeath(spriteStructure, time)
            return

        # Next we update its invulnerability time
        if self.invulTime >= 0:
            self.invulTime -= time

        # Then we check its stun time and update position according to inertia.
        # Currently there is no friction preventing them from sliding along the x axis
        if self.movement == STUNNED:
            self.stunnedTime -= time
            if (speedx > 0):
                if self.checkWall(RIGHT, platforms):
                    speedx = 0
            elif (speedx < 0):
                if self.checkWall(LEFT, platforms):
                    speedx = 0

        # If moving left or right
        elif (self.movement == LEFT) or (self.movement == RIGHT):
            # Set direction the character is facing
            self.looking = self.movement
            # Set movement speeds if we are not running into a wall
            if self.movement == LEFT:
                if self.checkWall(LEFT, platforms):
                    speedx = 0
                else:
                    speedx = -self.runSpeed
            else:
                if self.checkWall(RIGHT, platforms):
                    speedx = 0
                else:
                    speedx = self.runSpeed

            if self.numStance != SPRITE_JUMP:
                # If player is standing on solid ground, reset jump timer
                self.jumpTime = PLAYER_BASE_JUMP
                self.numStance = SPRITE_WALK
                # If we've run out of solid ground (walking out of a platform), start falling
                if not platforms:
                    self.numStance = SPRITE_JUMP

        elif (self.movement == UP) or (self.movement
                                       == UPLEFT) or (self.movement
                                                      == UPRIGHT):
            # If player is jumping, decrease time to keep jumping and set vertical speed accordingly
            if self.numStance != SPRITE_JUMP:
                self.jumpTime = PLAYER_BASE_JUMP
            self.jumpTime -= time
            self.numStance = SPRITE_JUMP
            # Check if we bump into a ceiling
            if self.checkCeiling(platforms):
                speedy = 0
            else:
                speedy = -self.jumpSpeed

            # These allow diagonal jumps and check for walls too
            if (self.movement == UPLEFT):
                if self.checkWall(LEFT, platforms):
                    speedx = 0
                else:
                    speedx = -self.runSpeed
            elif (self.movement == UPRIGHT):
                if self.checkWall(RIGHT, platforms):
                    speedx = 0
                else:
                    speedx = self.runSpeed

        # If not doing anything, stand still and reset jump timer
        elif self.movement == STILL:
            self.jumpTime = PLAYER_BASE_JUMP
            if not self.numStance == SPRITE_JUMP:
                self.numStance = SPRITE_STILL
            speedx = 0

        # If on the air, we have to check if we are landing on a platform
        if self.numStance == SPRITE_JUMP:
            for platform in iter(platforms):
                if (speedy > 0) and (platform.rect.top < self.rect.bottom) \
                            and ((self.rect.bottom - self.rect.height/2) < platform.rect.top):
                    # Set y value to top of the platform and break fall
                    self.setPosition(
                        (self.position[0],
                         platform.position[1] - platform.rect.height + 1))
                    self.numStance = SPRITE_STILL
                    speedy = 0

            # Otherwise, keep falling accelerated by gravity
            if self.numStance != SPRITE_STILL:
                speedy += GRAVITY * time
        self.updateStance()
        self.speed = (speedx, speedy)
        MySprite.update(self, time)

        return