Example #1
0
    void Update()
    {
        if (Menu.runSimulation)
        {
            switch (predState)
            {
            case PredState.MoveAboveMurmuration:
                if (Move())
                {
                    predState = PredState.Hover;
                    falconAnimator.SetInteger("flightType", 1);
                }
                break;

            case PredState.Hover:
                if (Hover())
                {
                    predState = PredState.Stoop;
                    GameObject predTarget = flock.FindPredatorTarget();
                    InitStoop(predTarget);
                    falconAnimator.SetInteger("flightType", 2);
                }
                break;

            case PredState.Stoop:
                if (Stoop())
                {
                    predState = PredState.MoveAboveMurmuration;
                    falconAnimator.SetInteger("flightType", 0);
                }
                break;
            }
        }
    }
Example #2
0
        protected override void Step()
        {
            base.Step();

            if (animTimer % 10 == 0 && ++imageIndex > Sprites.CharacterRects[spriteIndex].Count - 1)
            {
                imageIndex = 0;
                if (currentState == PredState.Emerge)
                {
                    nextState = PredState.Idle;
                }
            }

            if (currentState != nextState)
            {
                stateTimer = 0;
            }
            currentState = nextState;
            int xMove, yMove;

            switch (currentState)
            {
            case PredState.Emerge:
                ChangeSprite("pred_emerge");
                break;

            case PredState.Idle:
                ChangeSprite("pred_idle");
                if (!IsMoving)
                {
                    Dorf foundFood = (Dorf)Characters.FirstOrDefault(x => x is Dorf && Math.Abs(x.GridX - GridX) < 5 && Math.Abs(x.GridY - GridY) < 5);
                    if (foundFood != null)
                    {
                        nextState = PredState.ChaseDorf;
                    }
                    else
                    {
                        bool horizontal = Game.R.Next(2) == 0;
                        Move(horizontal ? Game.R.Next(3) - 1 : 0, horizontal ? 0 : Game.R.Next(3) - 1);
                        nextState = PredState.Wander;
                    }
                }
                break;

            case PredState.Wander:
                ChangeSprite("pred_run");
                if (!IsMoving)
                {
                    nextState = PredState.Idle;
                }
                break;

            case PredState.ChaseDorf:
                ChangeSprite("pred_run");
                if (!IsMoving)
                {
                    Dorf foundFood = (Dorf)Characters.FirstOrDefault(x => x is Dorf && Math.Abs(x.GridX - GridX) + Math.Abs(x.GridY - GridY) == 1);
                    if (foundFood != null && StandingOn != Tile.TileType.Water)
                    {
                        nextState = PredState.Attack;
                    }
                    else
                    {
                        if (localView.MoveToward(localView.GetNearestCharacter(typeof(Dorf)), out xMove, out yMove) && !Game.GridPointOccupied(GridX + xMove, GridY + yMove, true, this))
                        {
                            Move(xMove, yMove);
                        }
                        else
                        {
                            //Move randomly until it can get to the Dorf
                            bool horizontal = Game.R.Next(2) == 0;
                            Move(horizontal ? Game.R.Next(3) - 1 : 0, horizontal ? 0 : Game.R.Next(3) - 1);
                        }
                    }
                }
                break;

            case PredState.Attack:
                ChangeSprite("pred_attack");
                if (stateTimer == 0)
                {
                    Dorf foundFood = (Dorf)Characters.FirstOrDefault(x => x is Dorf && Math.Abs(x.GridX - GridX) + Math.Abs(x.GridY - GridY) == 1);
                    if (foundFood != null)
                    {
                        new SoundPlayer(Properties.Resources.Hit_Hurt2).Play();
                        foundFood.Hit(Strength, this);
                    }
                }
                else if (stateTimer > 40)
                {
                    nextState = PredState.Idle;
                }
                break;

            case PredState.Hurt:
                ChangeSprite("pred_hurt");
                if (stateTimer >= 30)
                {
                    nextState = PredState.Idle;
                }
                break;
            }
        }
Example #3
0
 public void Hit(int strength, Character atttacker)
 {
     nextState = PredState.Hurt;
     Hurt(strength);
 }