Exemplo n.º 1
0
 //When the AI has sensed the player, it will move
 //into pursuit mode, where it will move towards and
 //attack the player.
 protected void Pursue()
 {
     if (inLineOfSight() || listeningForNoise())
     {
         tankMove.RotateToward(target.transform.position);
         tankMove.Move((target.transform.position - tankData.tf.position) * (Time.deltaTime * tankData.tankForwardSpeed));
         tankAttack.FireCannon();
     }
 }
Exemplo n.º 2
0
 public virtual void Attack()
 {
     //move towards
     if (CanMove(data.forwardSpeed))
     {
         move.Move(data.forwardSpeed);
         move.RotateTowards(target.position, data.rotateSpeed);
     }
     else
     {
         //rotate towards
         move.Rotate(data.rotateSpeed);
     }
     //attack
     attack.FireCannon();
 }
Exemplo n.º 3
0
 void SniperAttack()
 {
     if (control.playerIsInRange() == true)
     {
         move.RotateTowards(control.target.position, data.rotateSpeed);
         attack.FireCannon();
     }
     if (data.tankCurrentLife <= (data.tankMaxLife / 2))
     {
         ChangeState(AIState.Flee);
     }
     else
     {
         ChangeState(AIState.Rest);
     }
 }
Exemplo n.º 4
0
    private void Update()
    {
        switch (input)
        {
        case InputScheme.WASD:
            //When "W" is pressed.
            if (Input.GetKey(KeyCode.W))
            {
                //Move function called, Object moves forward.
                move.Move(data.forwardSpeed);
            }
            //When "S" is pressed.
            else if (Input.GetKey(KeyCode.S))
            {
                //Move function called, Object moves back.
                move.Move(-data.forwardSpeed);
            }
            //When neither is being pressed, audio should stop.
            else
            {
                move.tankNoiseSource.Stop();
            }
            //When "D" is pressed.
            if (Input.GetKey(KeyCode.D))
            {
                //Rotate function called, Object turns right.
                move.Rotate(data.rotateSpeed);
            }
            //When "A" is pressed.
            if (Input.GetKey(KeyCode.A))
            {
                //Rotate function called, Object turns left.
                move.Rotate(-data.rotateSpeed);
            }
            //When "Q" is pressed once.
            if (Input.GetKeyDown(KeyCode.Q))
            {
                //If weaponFire is True.
                if (data.weaponFire == true)
                {
                    //FireCannon function called.
                    attack.FireCannon();
                }
                //If weaponFire is False.
                else
                {
                    //FireGun function called.
                    attack.FireGun();
                }
            }
            //When "E" is pressed once.
            if (Input.GetKeyDown(KeyCode.E))
            {
                //change weaponFire to the opposite of what it is now (t/f).
                data.weaponFire = !data.weaponFire;
            }
            break;

        case InputScheme.IJKL:
            //When "I" is pressed.
            if (Input.GetKey(KeyCode.I))
            {
                //Move function called, Object moves forward.
                move.Move(data.forwardSpeed);
            }
            //When "K" is pressed.
            else if (Input.GetKey(KeyCode.K))
            {
                //Move function called, Object moves back.
                move.Move(-data.forwardSpeed);
            }
            //When neither is being pressed, audio should stop.
            else
            {
                move.tankNoiseSource.Stop();
            }
            //When "L" is pressed.
            if (Input.GetKey(KeyCode.L))
            {
                //Rotate function called, Object turns right.
                move.Rotate(data.rotateSpeed);
            }
            //When "J" is pressed.
            if (Input.GetKey(KeyCode.J))
            {
                //Rotate function called, Object turns left.
                move.Rotate(-data.rotateSpeed);
            }
            //When "U" is pressed once.
            if (Input.GetKeyDown(KeyCode.U))
            {
                //If weaponFire is True.
                if (data.weaponFire == true)
                {
                    //FireCannon function called.
                    attack.FireCannon();
                }
                //If weaponFire is False.
                else
                {
                    //FireGun function called.
                    attack.FireGun();
                }
            }
            //When "O" is pressed once.
            if (Input.GetKeyDown(KeyCode.O))
            {
                //change weaponFire to the opposite of what it is now (t/f).
                data.weaponFire = !data.weaponFire;
            }
            break;
        }
    }
Exemplo n.º 5
0
    void Update()
    {
        switch (aiState)
        {
        case AIState.Patrol:
            //Execute function, 'Patrol' is described below.
            Patrol();
            break;

        case AIState.Chase:
            //Execute function, 'Chase' is described below.
            Chase();
            //Check if lower than half max health.
            if (data.tankCurrentLife < (data.tankMaxLife * .5))
            {
                ChangeState(AIState.CheckForFlee);
            }
            //If 'player' is NOT in range.
            else if (!playerIsInRange())
            {
                ChangeState(AIState.Chase);
            }
            break;

        case AIState.ChaseAndFire:
            Chase();
            attack.FireCannon();
            //Check if lower than half max heath.
            if (data.tankCurrentLife < (data.tankMaxLife * .5))
            {
                //ChangeState is a function below
                ChangeState(AIState.CheckForFlee);
            }
            // TODO: implement 'sight' and 'hearing' so the AI can check this.
            else if (playerIsInRange())
            {
                //ChageState also tracks when the AI switches state.
                ChangeState(AIState.ChaseAndFire);
            }
            break;

        case AIState.CheckForFlee:
            //If 'player' IS in range.
            if (playerIsInRange())
            {
                ChangeState(AIState.Flee);
            }
            else
            {
                ChangeState(AIState.Rest);
            }
            break;

        case AIState.Flee:
            Flee();
            //When the time between states has passed.
            if (Time.time >= stateEnterTime + restTime)
            {
                ChangeState(AIState.CheckForFlee);
            }
            break;

        case AIState.Rest:
            Rest();
            if (playerIsInRange())
            {
                ChangeState(AIState.Flee);
            }
            //Mathf.Approximately compares the 2 integers and allows for answers
            //that are not exactly the same, but close enough to be called good.
            else if (Mathf.Approximately(data.tankCurrentLife, data.tankMaxLife))
            {
                ChangeState(AIState.Chase);
            }
            break;
        }
    }