// 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; } }
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; } }
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); } }
// EATING STATE void EatingState() { sprite.color = new Color(0, 1, 0); Destroy(targetBee); energyAmt = maxEnergy; state = BirdStates.Flying; if (!HasEnergy()) { state = BirdStates.Rest; } }
// 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; } } }
// 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; } }
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"); }
void Start() { state = BirdStates.Flying; sprite = GetComponent <SpriteRenderer>(); randomSpot = Random.Range(0, nodeSpots.Length); }
private void LandToFlyingPosition() { animator.SetBool("flying", true); BirdState = BirdStates.Flying; }
private void LandingPositionToLand() { animator.SetBool("landing", false); animator.SetBool("flying", false); BirdState = BirdStates.Ground; }
private void FlyingToLandingPosition() { animator.SetBool("landing", true); animator.SetBool("flying", false); BirdState = BirdStates.Landing; }