コード例 #1
0
    // CHASING STATE
    void ChasingState()
    {
        sprite.color = new Color(1, 0, 0);

        // Move towards bee
        transform.position = Vector2.MoveTowards(transform.position, targetBee.transform.position, moveSpeed * Time.deltaTime);
        energy             = 0.8f;
        energyAmt         -= energy;

        // Check distance between bees
        if (Vector2.Distance(transform.position, targetBee.transform.position) <= 0.2f)
        {
            state = BirdStates.Eating;
        }


        // Check for energy
        if (!HasEnergy())
        {
            state = BirdStates.Rest;
        }

        if (CheckHive())
        {
            state = BirdStates.Flying;
        }
    }
コード例 #2
0
    void Update()
    {
        switch (state)
        {
        case BirdStates.Flying:
            FlyingState();
            if (CheckBees())
            {
                state = BirdStates.Chasing;
            }
            CheckEnergy();
            break;

        case BirdStates.Chasing:
            ChasingState();
            CheckEnergy();
            break;

        case BirdStates.Rest:
            RestState();
            CheckEnergy();
            break;

        case BirdStates.Eating:
            EatingState();
            CheckEnergy();
            break;
        }
    }
コード例 #3
0
    public void SetState(BirdStates newstate)
    {
        bird?.Exit();
        State = newstate;
        switch (State)
        {
        case BirdStates.Flapping:
            bird = new FlappingState(this);
            break;

        case BirdStates.Flying:
            bird = new FlyingState(this);
            break;

        case BirdStates.Ground:
            bird = new GroundState(this);
            break;

        case BirdStates.Hit:
            bird = new HitState(this);
            break;
        }
        bird.Init();

        if (OnStateChanged != null)
        {
            OnStateChanged(this, null);
        }
    }
コード例 #4
0
    // EATING STATE
    void EatingState()
    {
        sprite.color = new Color(0, 1, 0);
        Destroy(targetBee);
        energyAmt = maxEnergy;

        state = BirdStates.Flying;

        if (!HasEnergy())
        {
            state = BirdStates.Rest;
        }
    }
コード例 #5
0
    // RESTING STATE
    void RestState()
    {
        sprite.color       = new Color(0, 0, 1);
        transform.position = Vector2.MoveTowards(transform.position, nest.position, moveSpeed * Time.deltaTime);

        if (Vector2.Distance(transform.position, nest.position) < 0.2f)
        {
            energyAmt += 0.3f;

            if (energyAmt >= 500f)
            {
                state = BirdStates.Flying;
            }
        }
    }
コード例 #6
0
    // FLYING STATE
    void FlyingState()
    {
        sprite.color       = new Color(1, 0, 1);
        transform.position = Vector2.MoveTowards(transform.position, nodeSpots[randomSpot].position, moveSpeed * Time.deltaTime);
        energy             = 0.4f;
        energyAmt         -= energy;

        if (Vector2.Distance(transform.position, nodeSpots[randomSpot].position) < 0.2f)
        {
            randomSpot = Random.Range(0, nodeSpots.Length);
        }

        // Check for energy
        if (!HasEnergy())
        {
            state = BirdStates.Rest;
        }
    }
コード例 #7
0
    public override void _Ready()
    {
        State = BirdStates.Flying;
        bird  = new FlyingState(this);
        bird.Init();
        SetProcess(true);
        SetProcessInput(true);

        //LEARN:
        //This is possible because we added the Sounds Scene to Autoplay in the project settings.
        camera = (MainCamera)GetNode("/root/MainNode/MainCamera");

        //LEARN:
        //This is possible because we added the Sounds Scene to Autoplay in the project settings.
        WingAudioPlayer  = (AudioStreamPlayer)GetNode("/root/Sounds/WingAudio");
        HitAudioPlayer   = (AudioStreamPlayer)GetNode("/root/Sounds/HitAudio");
        DiedAudioPlayer  = (AudioStreamPlayer)GetNode("/root/Sounds/DieAudio");
        ScoreAudioPlayer = (AudioStreamPlayer)GetNode("/root/Sounds/PointAudio");
    }
コード例 #8
0
 void Start()
 {
     state      = BirdStates.Flying;
     sprite     = GetComponent <SpriteRenderer>();
     randomSpot = Random.Range(0, nodeSpots.Length);
 }
コード例 #9
0
 private void LandToFlyingPosition()
 {
     animator.SetBool("flying", true);
     BirdState = BirdStates.Flying;
 }
コード例 #10
0
 private void LandingPositionToLand()
 {
     animator.SetBool("landing", false);
     animator.SetBool("flying", false);
     BirdState = BirdStates.Ground;
 }
コード例 #11
0
 private void FlyingToLandingPosition()
 {
     animator.SetBool("landing", true);
     animator.SetBool("flying", false);
     BirdState = BirdStates.Landing;
 }