Exemple #1
0
    // Start is called before the first frame update
    void Start()
    {
        State   = FlyingState.Flying;
        groundP = GroundPredator.GetComponent <GroundPred>();

        this.observer.Attach(groundP.GroundPredSub);
    }
Exemple #2
0
        public void Update()
        {
            horizontalInput = Input.GetAxisRaw("Horizontal");

            FlyingState fs = new FlyingState(horizontalInput);

            fs.setTargetHold(fs.findClosestAnchor());
            SwingingState ss;

            checkValidity();

            if (!_parent.GroundCheck())
            {
                Print.Log("STATE TRANSITION grounded -> flying");
                _parent.currentState = fs;
                return;
            }

            if (Input.GetKeyDown(KeyCode.Space))
            {
                if (fs.targetHold != null)
                {
                    Print.Log("STATE TRANSITION grounded -> swinging");
                    ss = new SwingingState(fs.targetHold);
                    _parent.currentState = ss;

                    // Play hook audio
                    AudioManager.instance.Play("hook");
                }
            }

            _parent.Walk(horizontalInput);
        }
Exemple #3
0
    // Update is called once per frame
    void Update()
    {
        if (this.observer.State == FlyingState.ChasePred)
        {
            this.State = this.observer.State;
        }
        switch (State)
        {
        case FlyingState.Flying:
            this.GetComponent <UnityFlocking>().Flocking();
            if (this.GetComponentInChildren <Sight>().DetectAspect() && !FoodLocation.GetComponent <Food>().IsHarvestable)
            {
                this.State          = FlyingState.FoundSeeds;
                this.observer.State = FlyingState.FoundSeeds;
            }
            break;

        case FlyingState.FoundSeeds:
            FoundSeeds();
            break;

        case FlyingState.ChasePred:
            GoToPredNoise();
            break;

        case FlyingState.Scare:
            ScareThePred();
            break;
        }
    }
Exemple #4
0
        public void Land(int timeout)
        {
            // We do not want to fly while landing
            lock (ThisLock)
            {
                FlyVector.ResetVector();

                Logger.Debug("Landing...");
                CommandTuple cmdTuple = new CommandTuple(1, 0, 3);

                SendNoParam(cmdTuple);

                Stopwatch sw = new Stopwatch();
                sw.Start();
                while (FlyingState.GetState() != FlyingState.State.Landed && sw.ElapsedMilliseconds < timeout)
                {
                    if (FlyingState.GetState() == FlyingState.State.Emergency)
                    {
                        break;
                    }

                    SmartSleep(100);
                }

                sw.Stop();
            }
        }
Exemple #5
0
        public void TakeOff(int timeout)
        {
            Logger.Debug("Performing takeoff...");
            CommandTuple cmdTuple = new CommandTuple(1, 0, 1);

            if (FlyingState.GetState() == FlyingState.State.Landed || FlyingState.GetState() == FlyingState.State.UnKn0wn)
            {
                SendNoParam(cmdTuple);
            }
            else
            {
                return;
            }

            Stopwatch sw = new Stopwatch();

            sw.Start();
            while (FlyingState.GetState() != FlyingState.State.Hovering && FlyingState.GetState() != FlyingState.State.Flying && sw.ElapsedMilliseconds < timeout)
            {
                if (FlyingState.GetState() == FlyingState.State.Emergency)
                {
                    break;
                }

                SmartSleep(100);
            }

            sw.Stop();
        }
    private void Start()
    {
        Debug.Log("Bird");
        movementSM = new StateMachine();
        flying     = new FlyingState(this, movementSM);
        chasing    = new ChasingState(this, movementSM);
        eating     = new EatingState(this, movementSM);
        resting    = new RestingState(this, movementSM);

        movementSM.Initialize(flying);  // Default
    }
Exemple #7
0
    public void FoundSeeds()
    {
        if (Vector3.Distance(FoodLocation.transform.position, transform.position) <= 2.5f)
        {
            this.State          = FlyingState.Flying;
            this.observer.State = FlyingState.Flying;
        }

        Quaternion tarRot = Quaternion.LookRotation(FoodLocation.transform.position - transform.position);

        //tarRot.eulerAngles = new Vector3()
        transform.rotation = Quaternion.Slerp(transform.rotation, tarRot, 20.0f * Time.deltaTime);
        transform.Translate(new Vector3(20 * Time.deltaTime, 20 * Time.deltaTime, 20 * Time.deltaTime));
    }
 public void ObserverUpdate(object sender, object message)
 {
     if (sender is GroundPredSubject)
     {
         if (message is string)
         {
             switch (message.ToString())
             {
             case "Attack":
                 this.State = FlyingState.ChasePred;
                 break;
             }
         }
     }
 }
        private void ChangeObjectState(object sender, System.Windows.RoutedEventArgs e)
        {
            IObjectState objectState;

            if (_flag)
            {
                objectState = new FlyingState();
            }
            else
            {
                objectState = new JumpingState();
            }

            _flag = !_flag;
            _myObject.ChangeState(objectState);
            ExampleBlock.Text += "State changed.\n";
        }
    private void ShootPlayer()
    {
        timeToNextFire = fireRate;
        audioManager.PlaySound(bulletSound);

        //Vector2 targetPos = new Vector2(thePlayer.transform.position.x, thePlayer.transform.position.y);
        Vector2 moveDirection = (thePlayer.transform.position - transform.position).normalized * bulletSpeed;

        GameObject newbullet = Instantiate(bulletPrefab, bulletMuzzle.position, Quaternion.identity);

        newbullet.GetComponent <HurtPlayerOnHit>().enemyHM = enemyHealth;
        newbullet.GetComponent <Rigidbody2D>().velocity    = new Vector2(moveDirection.x, moveDirection.y);

        _flyingState = FlyingState.chase;
        //TODO: Flip Sprite Renderer during shooting
        //if player is to the right, shoot at the right side
    }
Exemple #11
0
 public void GoToPredNoise()
 {
     Debug.Log(Vector3.Distance(this.transform.position, GroundPredator.transform.position));
     if (Vector3.Distance(this.transform.position, GroundPredator.transform.position) <= HearingDistance)
     {
         if (Vector3.Distance(this.transform.position, GroundPredator.transform.position) <= 5.0f)
         {
             this.State          = FlyingState.Scare;
             this.observer.State = FlyingState.Scare;
         }
         Quaternion tarRot = Quaternion.LookRotation(GroundPredator.transform.position - transform.position);
         //tarRot.eulerAngles = new Vector3()
         transform.rotation = Quaternion.Slerp(transform.rotation, tarRot, 20.0f * Time.deltaTime);
         transform.Translate(new Vector3(0, 80 * Time.deltaTime, 80 * Time.deltaTime));
     }
     else
     {
         this.State          = FlyingState.Flying;
         this.observer.State = FlyingState.Flying;
     }
 }
    private void Update()
    {
        switch (_flyingState)
        {
        case FlyingState.idle:
            transform.position = this.transform.position;
            isPlayerInRange    = Physics2D.OverlapCircle(transform.position, detectionRange, whatIsShootable);
            if (isPlayerInRange)
            {
                _flyingState = FlyingState.chase;
            }
            break;

        case FlyingState.chase:
            isPlayerInShootingRange = Physics2D.OverlapCircle(transform.position, shootingRange, whatIsShootable);
            if (isPlayerInShootingRange)
            {
                flashParticle.Play();
                bubbleAnim.Play(firingAnim);
                _flyingState = FlyingState.firing;
            }
            break;

        case FlyingState.firing:
            transform.position = this.transform.position;
            timeToNextFire    -= Time.deltaTime;
            if (timeToNextFire < 0)
            {
                ShootPlayer();
            }
            break;

        case FlyingState.stunned:
            bubbleAnim.SetBool("IsHurt", true);
            break;

        default:
            break;
        }
    }
 public void OnDamaged()
 {
     _flyingState = FlyingState.stunned;
     bubbleAnim.SetBool("IsHurt", true);
 }
 public void OnRecovery()
 {
     bubbleRB.velocity = Vector2.zero;
     bubbleAnim.SetBool("IsHurt", false);
     _flyingState = FlyingState.idle;
 }
    //Determines whether the creature will approach with its Long-Range or Short-Range movement, based on how far away it is.
    //Long range moves toward a point above the target resource/animal's position, and has a slower turning speed.
    //Short range moves directly toward the target's position.
    void DetermineState(Vector2 target)
    {
        float distanceFrom = new Vector2 (target.x - transform.position.x, target.y - transform.position.y).magnitude;

        if(distanceFrom > heightAboveTarget + 1f && myState != FlyingState.shortRangeApproach)
        {
            myState = FlyingState.longRangeApproach;
        }
        else
        {
            myState = FlyingState.shortRangeApproach;
        }
    }
 public FlyingPredObserver(GroundPredSubject sub)
 {
     this.State = FlyingState.Flying;
     sub.Attach(this);
 }
Exemple #17
0
 public void ScareThePred()
 {
     GroundPredator.GetComponent <GroundPred>().Scared();
     this.State = FlyingState.Flying;
     Debug.Log("Recovery!");
 }
 public FlyingPredObserver()
 {
     this.State = FlyingState.Flying;
 }
 //Called by AnimalBrain when my food target is reselected (like when someone else eats it first)
 void IfFoodTargetChanged()
 {
     if(myState == FlyingState.shortRangeApproach)
         myState = FlyingState.longRangeApproach;
 }
 void Update()
 {
     //Reset the direction to Up if you're not currently pursuing
     if(brain.myState != BehaviorState.pursue && brain.myState != BehaviorState.returnHome)
     {
         direction = 90f;
     }
     if(!aiMoveWasCalled)
     {
         myState = FlyingState.idle;
     }
     aiMoveWasCalled = false;
 }
Exemple #21
0
 public bool IsLanded()
 {
     return(FlyingState.GetState() == FlyingState.State.Emergency || FlyingState.GetState() == FlyingState.State.Landed);
 }
        private IEnumerator FlyTowards(Direction direction, IsometricMask currentMask, IsometricMask nextMask)
        {
            m_Animator.SetBool("Jump", true);
            m_IsJumping = true;

            m_FlyingState = FlyingState.None;
            while (m_FlyingState == FlyingState.None)
            {
                yield return(null);
            }

            var startPosition =
                new Vector3(
                    currentMask.isometricTransform.position.x,
                    currentMask.isometricTransform.position.y + currentMask.lateralTopography.Evaluate(0.5f),
                    currentMask.isometricTransform.position.z);
            var endPosition =
                new Vector3(
                    currentMask.isometricTransform.position.x,
                    Mathf.Max(
                        currentMask.isometricTransform.position.y
                        + currentMask.lateralTopography.Evaluate(0.5f),
                        nextMask.isometricTransform.position.y
                        + nextMask.lateralTopography.Evaluate(0.5f))
                    + 1f,
                    currentMask.isometricTransform.position.z);

            var deltaTime = 0f;

            while (m_FlyingState == FlyingState.TakingOff)
            {
                m_IsometricTransform.position =
                    Vector3.Lerp(startPosition, endPosition, deltaTime / m_CurrentAnimationLength);

                deltaTime += Time.deltaTime;

                yield return(null);
            }

            endPosition =
                new Vector3(
                    nextMask.isometricTransform.position.x,
                    m_IsometricTransform.position.y,
                    nextMask.isometricTransform.position.z);

            while (m_IsometricTransform.position != endPosition)
            {
                m_IsometricTransform.position =
                    Vector3.MoveTowards(m_IsometricTransform.position, endPosition, 1f * Time.deltaTime);

                yield return(null);
            }

            m_Animator.SetBool("Jump", false);
            while (m_FlyingState != FlyingState.Landing)
            {
                yield return(null);
            }

            startPosition = m_IsometricTransform.position;
            endPosition   =
                new Vector3(
                    nextMask.isometricTransform.position.x,
                    nextMask.isometricTransform.position.y + nextMask.lateralTopography.Evaluate(0.5f),
                    nextMask.isometricTransform.position.z);

            deltaTime = 0f;
            while (m_FlyingState == FlyingState.Landing && deltaTime <= m_CurrentAnimationLength)
            {
                m_IsometricTransform.position =
                    Vector3.Lerp(startPosition, endPosition, deltaTime / m_CurrentAnimationLength);

                deltaTime += Time.deltaTime;

                yield return(null);
            }

            m_IsJumping   = false;
            m_FlyingState = FlyingState.None;
        }