def checkForAttack(self):
        messages = messaging.get()
        for message in messages:
            # PlayerAttack - Player
            if message.type == MessageType.PlayerAttack:
                playerEntity = EntityFinder.findPlayer(self.world)
                playerRenderable = self.world.component_for_entity(
                    playerEntity, system.graphics.renderable.Renderable)

                playerRenderable.texture.changeAnimation(
                    message.data['characterAttackAnimationType'],
                    playerRenderable.direction,
                    interrupt=True)

            # EntityAttack - Enemies
            if message.type == MessageType.EntityAttack:
                entity = EntityFinder.findCharacterByGroupId(
                    self.world, message.groupId)
                entityRenderable = self.world.component_for_entity(
                    entity, system.graphics.renderable.Renderable)

                entityRenderable.texture.changeAnimation(
                    CharacterAnimationType.hitting,
                    entityRenderable.direction,
                    interrupt=True)

            # EntityAttack - Enemies
            if message.type == MessageType.EntityStanding:
                entity = EntityFinder.findCharacterByGroupId(
                    self.world, message.groupId)
                entityRenderable = self.world.component_for_entity(
                    entity, system.graphics.renderable.Renderable)

                entityRenderable.texture.changeAnimation(
                    CharacterAnimationType.standing,
                    entityRenderable.direction,
                    interrupt=True)

            # attackWindup- only for Enemies
            if message.type == MessageType.attackWindup:
                entity = EntityFinder.findCharacterByGroupId(
                    self.world, message.groupId)
                entityRenderable = self.world.component_for_entity(
                    entity, system.graphics.renderable.Renderable)

                entityRenderable.texture.changeAnimation(
                    CharacterAnimationType.hitwindup,
                    entityRenderable.direction,
                    interrupt=True)
    def checkForMove(self):
        for message in messaging.getByType(MessageType.EntityMoved):
            entity = EntityFinder.findCharacterByGroupId(
                self.world, message.groupId)
            renderable = self.world.component_for_entity(
                entity, system.graphics.renderable.Renderable)

            # just updated direction
            # NOTE this only works for CharacterTexture's
            if message.data['x'] == 0 and message.data['y'] == 0:
                renderable.texture.changeAnimation(
                    renderable.texture.characterAnimationType,
                    renderable.direction)
                continue

            if (renderable.texture.characterAnimationType is
                    CharacterAnimationType.walking):
                if message.data['didChangeDirection']:
                    renderable.texture.changeAnimation(
                        CharacterAnimationType.walking, renderable.direction)
                else:
                    renderable.texture.advanceStep()
            else:
                renderable.texture.changeAnimation(
                    CharacterAnimationType.walking, renderable.direction)
    def checkForKnockdown(self):
        for message in messaging.getByType(MessageType.EntityKnockdown):
            entity = EntityFinder.findCharacterByGroupId(
                self.world, message.groupId)
            meRenderable = self.world.component_for_entity(
                entity, system.graphics.renderable.Renderable)

            meRenderable.texture.changeAnimation(
                characterAnimationType=CharacterAnimationType.knockdown,
                direction=meRenderable.direction,
                interrupt=True)
    def checkForDying(self):
        for message in messaging.getByType(MessageType.EntityDying):
            entity = EntityFinder.findCharacterByGroupId(
                self.world, message.groupId)
            meRenderable = self.world.component_for_entity(
                entity, system.graphics.renderable.Renderable)

            animationIndex = random.randint(0, 1)
            meRenderable.texture.changeAnimation(
                characterAnimationType=CharacterAnimationType.dying,
                direction=meRenderable.direction,
                subtype=animationIndex,
                interrupt=False)
    def checkForStun(self):
        for message in messaging.getByType(MessageType.EntityStun):
            entity = EntityFinder.findCharacterByGroupId(
                self.world, message.groupId)
            entityRenderable = self.world.component_for_entity(
                entity, system.graphics.renderable.Renderable)

            # here we also store the current animation
            # by interrupt=True
            entityRenderable.texture.changeAnimation(
                CharacterAnimationType.stun,
                entityRenderable.direction,
                interrupt=True)

        for message in messaging.getByType(MessageType.EntityEndStun):
            entity = EntityFinder.findCharacterByGroupId(
                self.world, message.groupId)
            entityRenderable = self.world.component_for_entity(
                entity, system.graphics.renderable.Renderable)

            # restore saved animation
            entityRenderable.texture.previousAnimationRestore()
示例#6
0
    def moveEnemy(self):
        for msg in directMessaging.getByType(DirectMessageType.moveEnemy):
            entity = EntityFinder.findCharacterByGroupId(
                self.world, msg.groupId)
            if entity is None:
                # May be already deleted?
                continue

            meRenderable = self.world.component_for_entity(
                entity, system.graphics.renderable.Renderable)

            # these are the actual x/y position change we will use to move
            x = msg.data['x']
            y = msg.data['y']

            # turning on the spot
            if meRenderable.direction is Direction.left and x > 0:
                self.updateRenderableDirection(meRenderable, Direction.right,
                                               msg.groupId)
                continue
            if meRenderable.direction is Direction.right and x < 0:
                self.updateRenderableDirection(meRenderable, Direction.left,
                                               msg.groupId)
                continue

            meRenderable.storeCoords()
            meRenderable.changeLocationFromStored(x, y)

            if msg.data['force']:
                canMove = True

                # push player out of the way, if there
                isDestEmpty = EntityFinder.isDestinationEmpty(
                    self.world, meRenderable)
                if not isDestEmpty:
                    if EntityFinder.isDestinationWithPlayer(
                            self.world, meRenderable):
                        directMessaging.add(
                            groupId=0,
                            type=DirectMessageType.movePlayer,
                            data={
                                'x': x,
                                'y': 0,
                                'dontChangeDirection': True,
                                'whenMoved': None,
                            },
                        )

            else:
                canMove = EntityFinder.isDestinationEmpty(
                    self.world, meRenderable)

                if not canMove:
                    # seems we cannot move in the chose direction.
                    # if there are two components in the coordinates, just try one of
                    # them
                    if x != 0 and y != 0:
                        # try x. yes this is ugly, but fast
                        x = msg.data['x']
                        y = 0
                        meRenderable.changeLocationFromStored(x, y)
                        canMove = EntityFinder.isDestinationEmpty(
                            self.world, meRenderable)

                        if not canMove:
                            # try y... ugh
                            x = 0
                            y = msg.data['y']
                            meRenderable.changeLocationFromStored(x, y)
                            canMove = EntityFinder.isDestinationEmpty(
                                self.world, meRenderable)

                # check if we are stuck
                if not canMove:
                    meRenderable.restoreCoords()

                    isStuck = not EntityFinder.isDestinationEmpty(
                        self.world, meRenderable)
                    if isStuck:
                        logger.info(
                            "{}: Overlaps, force way out".format(meRenderable))
                        # force our way out of here. do intended path
                        x = msg.data['x']
                        y = msg.data['y']
                        canMove = True
                    else:
                        # not stuck, just wait until we are free,
                        # as another enemy most likely blocks our way
                        logger.info(
                            "{}: Does not overlap, wait until moving".format(
                                meRenderable))
                        pass

            meRenderable.restoreCoords()

            if canMove:
                self.moveRenderable(meRenderable, msg.groupId, x, y,
                                    msg.data['dontChangeDirection'],
                                    msg.data['updateTexture'])