Example #1
0
 public void removeSceneComponent(Scenes.SceneComponent sc)
 {
     AI.IAIEntity ai = sc as AI.IAIEntity;
     if (ai != null)
     {
         objectList.Remove(ai);
         heroPositionListners.removeMessageProcessor(ai);
     }
     Levels.Characters.Hero h = sc as Levels.Characters.Hero;
     if (h != null)
     {
         hero = null;
     }
 }
Example #2
0
 public void addSceneComponent(Scenes.SceneComponent sc)
 {
     AI.IAIEntity ai = sc as AI.IAIEntity;
     if (ai != null)
     {
         objectList.Add(ai);
         heroPositionListners.addMessageProcessor(ai);
     }
     Levels.Characters.Hero h = sc as Levels.Characters.Hero;
     if (h != null)
     {
         hero = h;
     }
 }
Example #3
0
        public override bool ProcessMessage(Message m)
        {
            if (m.MessageType == MessageTypes.characterPosition)
            {
                directionChanged = false;
                Scenes.SceneComponent otherObj = m.from as Scenes.SceneComponent;
                Scenes.SceneComponent thisObj  = thisObject as Scenes.SceneComponent;

                //TODO: a reasonable direction changing test
                chargingDirection = otherObj.Position2D - thisObj.Position2D;
                directionChanged  = true;
                return(true);
            }
            return(false);
        }
Example #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);
        }
Example #5
0
 public override void OnEnter()
 {
     base.OnEnter();
     nrOffSetbacks = 0;
     movingToNext  = false;
     Scenes.SceneComponent bunny = thisObject as Scenes.SceneComponent;
     lastDistanceSquared = (setPoint - bunny.Position2D).LengthSquared();
     direction           = (setPoint.X - bunny.Position2D.X) > 0 ? right : left;
     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));
     }
 }
Example #6
0
 float calSquaredDistance(Message msg, object obj)
 {
     Scenes.SceneComponent otherObj = msg.from as Scenes.SceneComponent;
     Scenes.SceneComponent thisObj  = obj as Scenes.SceneComponent;
     return((otherObj.Position2D - thisObj.Position2D).LengthSquared());
 }