// 设定角色能力
    public override void SetCharacterAttr()
    {
        AIMonster aIMonster = new AIMonster(m_BuildParam.NewCharacter);
        PatrolAI  patrolAI  = new PatrolAI();

        aIMonster.ChangeAIState(patrolAI);
        m_BuildParam.NewCharacter.SetAI(aIMonster);
    }
Exemple #2
0
        protected void SpawnMonster(string name, Vector2 position, int delay)
        {
            uint         netId   = Game.NetIdProvider.PopNextNetId();
            AIUnitRecord record  = AIUnitRecord.GetAIUnitRecord(name);
            AIMonster    monster = new AIMonster(netId, record, delay);

            monster.SpawnPosition = position;
            monster.Position      = position;
            monster.DefineGame(Game);
            Game.AddUnitToTeam(monster, TeamId.NEUTRAL);
            Game.Map.AddUnit(monster);
        }
        public void SpawnCamp(string monsterName, Game game, Vector2 position)
        {
            AIMonster monster = new AIMonster(game.NetIdProvider.PopNextNetId(), AIUnitRecord.GetAIUnitRecord(monsterName), 0);

            monster.Position      = position;
            monster.SpawnPosition = position;
            monster.DefineGame(game);
            game.AddUnitToTeam(monster, TeamId.NEUTRAL);
            game.Map.AddUnit(monster);
            monster.Initialize();
            monster.Create();
        }
Exemple #4
0
        public override void Update(double timeDiff)
        {
            base.Update(timeDiff);
            Scenes.SceneComponent bunny = thisObject as Scenes.SceneComponent;
            double distanceSquared      = (setPoint - bunny.Position2D).LengthSquared();
            int    currentDirection     = (setPoint.X - bunny.Position2D.X) > 0 ? right : left;

            if (!movingToNext)
            {
                if (distanceSquared <= 0.1 || currentDirection != direction)
                {
                    //go to next setpoint
                    AIManager.messageQueue.sendMessage(new NextSetPointMessage(thisObject as IMessageProcessor, thisObject as IMessageProcessor));
                    movingToNext = true;
                }
                if (distanceSquared >= lastDistanceSquared)
                {
                    nrOffSetbacks++;
                    //Check nrOffSetbacks against a limit and go to next setpoint if exceded
                    if (!movingToNext && nrOffSetbacks > maxSetBacks)
                    {
                        AIManager.messageQueue.sendMessage(new NextSetPointMessage(thisObject as IMessageProcessor, thisObject as IMessageProcessor));
                        movingToNext = true;
                    }
                }
            }
            lastDistanceSquared = distanceSquared;
            nrOffSetbacks       = 0;

            //set proper animation
            if (direction != currentDirection)
            {
                if (direction == right)
                {
                    AIManager.messageQueue.sendMessage(new AnimationCommandMessage(thisObject as IMessageProcessor, thisObject as IMessageProcessor, moveRightAnimationCommand));
                }
                if (direction == left)
                {
                    AIManager.messageQueue.sendMessage(new AnimationCommandMessage(thisObject as IMessageProcessor, thisObject as IMessageProcessor, moveLeftAnimationCommand));
                }
            }
            // do physics action
            double    distance  = (setPoint - bunny.Position2D).Length();
            AIMonster thisBunny = thisObject as AIMonster;

            thisBunny.Position2D = new Vector2(thisBunny.Position2D.X + (float)(speed * timeDiff > distance ? direction * distance : direction * speed * timeDiff), thisBunny.Position2D.Y);
        }
Exemple #5
0
        public override void Update(double timeDiff)
        {
            //set proper animation
            if (directionChanged)
            {
                if (chargingDirection.X > 0)
                {
                    AIManager.messageQueue.sendMessage(new AnimationCommandMessage(thisObject as IMessageProcessor, thisObject as IMessageProcessor, moveRightAnimationCommand));
                }
                if (chargingDirection.X < 0)
                {
                    AIManager.messageQueue.sendMessage(new AnimationCommandMessage(thisObject as IMessageProcessor, thisObject as IMessageProcessor, moveLeftAnimationCommand));
                }
            }
            int direction = (chargingDirection.X > 0 ? +1 : -1);
            //do physics action
            AIMonster thisBunny = thisObject as AIMonster;

            thisBunny.Position2D = new Vector2(thisBunny.Position2D.X + (float)(speed * timeDiff > Math.Abs(chargingDirection.X) ? chargingDirection.X : direction * speed * timeDiff), thisBunny.Position2D.Y);
        }