コード例 #1
0
        public AiStateMachine(Enemy owner, AIState constState, AIState startState)
        {
            this.owner = owner;
            this.constState = constState;
            this.dynamicState = startState;

            constState.Enter(owner);
            dynamicState.Enter(owner);
        }
コード例 #2
0
 public void UpdateState(Enemy owner, float deltaTime)
 {
     switch (currDir)
     {
         case Direction.NEGATIVE_X:
             UpdateLeft(deltaTime, owner);
             break;
         case Direction.POSITIVE_X:
             UpdateRight(deltaTime, owner);
             break;
     }
 }
コード例 #3
0
 public void UpdateState(Enemy owner, float deltaTime)
 {
     actionCooldownTimer += deltaTime;
     if (actionCooldownTimer >= actionCooldown)
     {
         if (Vector3.Distance(Game.player.Cam.Position, owner.Position) <= playerDistToPerformAction)
         {
             actionCooldownTimer = 0.0f;
              owner.PerformBaseAction();
         }
     }
 }
コード例 #4
0
 public void UpdateState(Enemy owner, float deltaTime)
 {
     switch (currDir)
     {
         case Direction.NEGATIVE_Z:
             UpdateNegative(deltaTime, owner);
             break;
         case Direction.POSITIVE_Z:
             UpdatePositive(deltaTime, owner);
             break;
     }
 }
コード例 #5
0
        public void Enter(Enemy owner)
        {
            owner.Velocity = endPos - startPos;
            Vector3 vel = owner.Velocity;
            vel.Normalize();
            owner.Velocity = vel;
            originalVelocity = owner.Velocity;
            owner.Position = startPos;

            if (originalVelocity.X < 0)
            {
                currDir = Direction.NEGATIVE_X;
                owner.Rotation = new Vector3(0, NegativeHeading, 0);
            }
            else
            {
                currDir = Direction.POSITIVE_X;
                owner.Rotation = new Vector3(0, PositiveHeading, 0);
            }
        }
コード例 #6
0
 void UpdateLeft(float deltaTime, Enemy owner)
 {
     float distance = Vector3.Distance(owner.Position, startPos);
     if (distance <= 400)
     {
         if (distance <= 200)
         {
             if (owner.Rotation.Y < 270)
             {
                 owner.Velocity = new Vector3(owner.Velocity.X + (acceleration * deltaTime), owner.Velocity.Y, owner.Velocity.Z);
                 owner.Rotation = new Vector3(owner.Rotation.X, owner.Rotation.Y + (90 * deltaTime), 0);
             }
             else
             {
                 currDir = Direction.POSITIVE_X;
                 owner.Rotation = new Vector3(0, PositiveHeading, 0);
                 owner.Velocity = endPos - startPos;
                 Vector3 vel = owner.Velocity;
                 vel.Normalize();
                 owner.Velocity = vel;
                 originalVelocity = owner.Velocity;
             }
         }
         else
             owner.Velocity = new Vector3(originalVelocity.X * (distance / 400), originalVelocity.Y, originalVelocity.Z);
     }
     else if (owner.Velocity.X > -maxVelocity)
     {
         owner.Velocity = new Vector3(owner.Velocity.X - (acceleration * deltaTime), owner.Velocity.Y, owner.Velocity.Z);
         originalVelocity = owner.Velocity;
     }
 }
コード例 #7
0
 public void Exit(Enemy owner)
 {
     owner.Velocity = Vector3.Zero;
 }
コード例 #8
0
 void UpdateRight(float deltaTime, Enemy owner)
 {
     float distance = Vector3.Distance(owner.Position, endPos);
     if (distance <= 400)
     {
         if (distance <= 200)
         {
             if (owner.Rotation.Y > 90)
             {
                 owner.Velocity = new Vector3(owner.Velocity.X - (acceleration * deltaTime), 0, 0);
                 owner.Rotation = new Vector3(owner.Rotation.X, owner.Rotation.Y - (90 * deltaTime), 0);
             }
             else
             {
                 currDir = Direction.NEGATIVE_X;
                 owner.Rotation = new Vector3(0, 90, 0);
                 owner.Velocity = startPos - endPos;
                 Vector3 vel = owner.Velocity;
                 vel.Normalize();
                 owner.Velocity = vel;
                 originalVelocity = owner.Velocity;
             }
         }
         else
             owner.Velocity = new Vector3(originalVelocity.X * (distance / 400), originalVelocity.Z, originalVelocity.Y);
     }
      else if (owner.Velocity.X < maxVelocity)
     {
         owner.Velocity = new Vector3(owner.Velocity.X + (acceleration * deltaTime), owner.Velocity.Y, owner.Velocity.Z);
         originalVelocity = owner.Velocity;
     }
 }
コード例 #9
0
 public void Exit(Enemy owner)
 {
 }
コード例 #10
0
 public void Enter(Enemy owner)
 {
     actionCooldownTimer = 0.0f;
 }
コード例 #11
0
        void UpdateNegative(float deltaTime, Enemy owner)
        {
            float distance = Vector3.Distance(owner.Position, currentTarget);
            if (distance <= 400)
            {
                if (distance <= 200)
                {
                    if (owner.Rotation.Y < positiveHeading)
                    {
                        owner.Velocity = new Vector3(owner.Velocity.X, owner.Velocity.Y, owner.Velocity.Z + (acceleration * deltaTime));
                        owner.Rotation = new Vector3(owner.Rotation.X, owner.Rotation.Y + (90 * deltaTime), 0);
                    }
                    else
                    {
                        currDir = Direction.POSITIVE_Z;
                        ChangeTarget();
                        owner.Velocity = currentTarget - otherTarget;
                        Vector3 vel = owner.Velocity;
                        vel.Normalize();
                        owner.Velocity = vel;
                        originalVelocity = owner.Velocity;
                        owner.Rotation = new Vector3(0, positiveHeading, 0);

                    }
                }
                else
                    owner.Velocity = new Vector3(originalVelocity.X, originalVelocity.Y, originalVelocity.Z * (distance / 400));
            }
            else if (owner.Velocity.Z > -maxVelocity)
            {
                owner.Velocity = new Vector3(owner.Velocity.X, owner.Velocity.Y, owner.Velocity.Z - (acceleration * deltaTime));
                originalVelocity = owner.Velocity;
            }
        }