Esempio n. 1
0
 public void MoveToSpecial()
 {
     m_State = BirdState.Moving;
     nextWaypoint = specialLoc;
     moveTime = Time.time;
     journeyLength = Vector3.Distance(curWaypoint, nextWaypoint);
 }
Esempio n. 2
0
 // Use this for initialization
 void Start()
 {
     birdState = BirdState.idle;
     gameManager = GameObject.FindGameObjectWithTag ("GM");
     gameManagerScript = gameManager.GetComponent<GameManagerScript> () as GameManagerScript;
     newPos = this.transform.position;
 }
Esempio n. 3
0
 public void StopAttacking()
 {
     m_State = BirdState.Moving;
     curWaypoint = transform.position;
     nextWaypoint = m_Waypoints[(Random.Range(0, m_Waypoints.Length))];
     moveTime = Time.time;
     journeyLength = Vector3.Distance(curWaypoint, nextWaypoint);
     isSafe = true;
 }
Esempio n. 4
0
 // Use this for initialization
 public virtual void Start()
 {
     //trailrenderer is not visible until we throw the bird
     GetComponent<TrailRenderer>().enabled = false;
     GetComponent<TrailRenderer>().sortingLayerName = "Foreground";
     //no gravity at first
     GetComponent<Rigidbody2D>().isKinematic = true;
     //make the collider bigger to allow for easy touching
     GetComponent<CircleCollider2D>().radius = Constants.BirdColliderRadiusBig;
     State = BirdState.BeforeThrown;
 }
Esempio n. 5
0
    void Start()
    {
        birdState = BirdState.idle;
        gameManager = GameObject.FindGameObjectWithTag("GM");
        gameManagerScript = gameManager.GetComponent<GameManagerScript>() as GameManagerScript;
        spriteRenderer = gameObject.GetComponent<SpriteRenderer>();

        gameManagerScript.SetBossName(bossName);
        gameManagerScript.SetHPBar(Health);

        newPos = this.transform.position;
    }
Esempio n. 6
0
 public virtual void OnThrow()
 {
     //play the sound
     //      GetComponent<AudioSource>().Play();
     //show the trail renderer
     GetComponent<TrailRenderer>().enabled = true;
     //allow for gravity forces
     GetComponent<Rigidbody2D>().isKinematic = false;
     //make the collider normal size
     GetComponent<CircleCollider2D>().radius = Constants.BirdColliderRadiusNormal;
     State = BirdState.Thrown;
 }
Esempio n. 7
0
    // Update is called once per frame
    void Update()
    {
        if (birdState == BirdState.idle) {
            newPos.x -= speed * Time.deltaTime;

            if (transform.position.x < 20) {
                birdState = BirdState.powerUp;
                powerUpTimer = 1.5f;
            }
        }

        if (birdState == BirdState.powerUp) {
            powerUpTimer -= Time.deltaTime;

            if (powerUpTimer < 0) {
                birdState = BirdState.highSpeed;
            }
        }

        if (birdState == BirdState.highSpeed) {
            newPos.x -= highSpeed * Time.deltaTime;
        }
    }
Esempio n. 8
0
 void OnTriggerEnter2D(Collider2D other)
 {
     if (other.gameObject.tag == "arrow")
     {
         if (!other.gameObject.GetComponent<Arrow>().hasHit)
         {
             //if you hit the bird, it aggros to you
             Destroy(other.gameObject);
             if (m_State != BirdState.Attack)
             {
                 m_State = BirdState.Attack;
             }
             TakeDamage();
             mAnimator.SetTrigger("Hit");
         }
     }
 }
 private void OnCollisionEnter2D(Collision2D collision)
 {
     _state = BirdState.HitSomething;
     OnBirdHit();
 }
Esempio n. 10
0
 private void Start()
 {
     _birdState = BirdState.Follow;
 }
Esempio n. 11
0
 public virtual void OnCollisionEnter2D(Collision2D collision)
 {
     _state = BirdState.HitSomething;
     Debug.Log("Virtual method called");
 }
Esempio n. 12
0
 public virtual void OnCollisionEnter2D(Collision2D col)
 {
     state = BirdState.HitSomething;
 }
Esempio n. 13
0
    // Update is called once per frame
    void Update()
    {
        int rng = Random.Range(1, 100);
        if (m_State == BirdState.Idle)
        {
            mAnimator.SetBool("isAggrod", false);
            if (rng <= moveChance)
            {
                m_State = BirdState.Moving;
                nextWaypoint = m_Waypoints[(Random.Range(0, m_Waypoints.Length))];
                moveTime = Time.time;
                journeyLength = Vector3.Distance(curWaypoint, nextWaypoint);
            }
        }
        else if (m_State == BirdState.Moving)
        {
            mAnimator.SetBool("isAggrod", false);
            updateFacing();
            float distCovered = (Time.time - moveTime) * speed;
            float fracJourney = distCovered/journeyLength;
            transform.position = Vector3.Lerp(curWaypoint, nextWaypoint, fracJourney);
            if(transform.position == nextWaypoint){ //we have reached the next position
                curWaypoint = nextWaypoint;
                m_State = BirdState.Idle;
            }
        }
        else if(m_State == BirdState.Attack){
            mAnimator.SetBool("isAggrod", true);
            Vector3 charOffset = m_Char.transform.position;
            charOffset.y += m_Char.GetComponent<SpriteRenderer>().bounds.size.y;
            //charOffset.x += m_Char.GetComponent<SpriteRenderer>().bounds.size.x;
            if (m_Char.transform.position.x > transform.position.x)
            {
                Vector3 newScale = transform.localScale;
                newScale.x = -Mathf.Abs(newScale.x);
                transform.localScale = newScale;
            }
            else
            {
                Vector3 newScale = transform.localScale;
                newScale.x = Mathf.Abs(newScale.x);
                transform.localScale = newScale;
            }
            if ((transform.position.x < charOffset.x - m_Char.GetComponent<SpriteRenderer>().bounds.size.x ||
                transform.position.x > charOffset.x + m_Char.GetComponent<SpriteRenderer>().bounds.size.x) ||
                (transform.position.y > charOffset.y + 5 || transform.position.y < charOffset.y - 5))
            transform.position = Vector3.MoveTowards(transform.position, charOffset, Time.deltaTime*speed);
            if ( canAttack )
            {
                StartCoroutine ( AttackPlayer () );
            }
        }

        if (daynight.GetTimeOfDay() > (50 * 0.35) && daynight.GetTimeOfDay() < (50 * 0.75f)) //this is night time
        {
            if (!isSafe)
            {
                m_State = BirdState.Attack;
            }
        }
    }
Esempio n. 14
0
 public void Update(GameTime time)
 {
     if (peckFrames > 0)
     {
         peckFrames--;
     }
     else
     {
         nextPeck--;
         if (nextPeck <= 0)
         {
             if (theater.ShouldBirdsRoost())
             {
                 peckFrames = 50;
             }
             else
             {
                 peckFrames = 5;
             }
             nextPeck = Game1.random.Next(10, 30);
             if (Game1.random.NextDouble() <= 0.75)
             {
                 nextPeck += Game1.random.Next(50, 100);
                 if (!theater.ShouldBirdsRoost())
                 {
                     peckDirection = Game1.random.Next(0, 2);
                 }
             }
         }
     }
     if (birdState == BirdState.Idle)
     {
         if (!theater.ShouldBirdsRoost())
         {
             using (FarmerCollection.Enumerator enumerator = theater.farmers.GetEnumerator())
             {
                 if (enumerator.MoveNext())
                 {
                     Farmer farmer = enumerator.Current;
                     float  num    = Utility.distance(farmer.position.X, position.X, farmer.position.Y, position.Y);
                     framesUntilNextMove--;
                     if (num < 200f || framesUntilNextMove <= 0)
                     {
                         FlyToNewPoint();
                     }
                 }
             }
         }
     }
     else
     {
         if (birdState != BirdState.Flying)
         {
             return;
         }
         float distance             = Utility.distance((float)(endPosition.X * 64) + 32f, position.X, (float)(endPosition.Y * 64) + 32f, position.Y);
         int   max_velocity         = 5;
         float slow_down_multiplier = 0.25f;
         if (distance > (float)max_velocity / slow_down_multiplier)
         {
             velocity = Utility.MoveTowards(velocity, max_velocity, 0.5f);
         }
         else
         {
             velocity = Math.Max(Math.Min(distance * slow_down_multiplier, velocity), 1f);
         }
         float path_distance = Utility.distance((float)endPosition.X + 32f, (float)startPosition.X + 32f, (float)endPosition.Y + 32f, (float)startPosition.Y + 32f) * 64f;
         if (path_distance <= 0.0001f)
         {
             path_distance = 0.0001f;
         }
         float delta = velocity / path_distance;
         pathPosition += delta;
         position      = new Vector2(Utility.Lerp((float)(startPosition.X * 64) + 32f, (float)(endPosition.X * 64) + 32f, pathPosition), Utility.Lerp((float)(startPosition.Y * 64) + 32f, (float)(endPosition.Y * 64) + 32f, pathPosition));
         if (pathPosition >= 1f)
         {
             position            = new Vector2((float)(endPosition.X * 64) + 32f, (float)(endPosition.Y * 64) + 32f);
             birdState           = BirdState.Idle;
             velocity            = 0f;
             framesUntilNextMove = Game1.random.Next(350, 500);
             if (Game1.random.NextDouble() < 0.75)
             {
                 framesUntilNextMove += Game1.random.Next(200, 300);
             }
         }
     }
 }
Esempio n. 15
0
        public bool CanPerformAction(BirdState birdState)
        {
            Int16 state = (Int16)birdState;

            return((this._actionBlockers & state) != state);
        }
Esempio n. 16
0
 void ResetPostion()
 {
     newPos.x = 25;
     newPos.y = Random.Range(-5, 13);
     birdState = BirdState.idle;
 }
Esempio n. 17
0
 public virtual void OnHit()
 {
     _state = BirdState.HitSomething;
 }
Esempio n. 18
0
 // Start is called before the first frame update
 void Start()
 {
     Rigidbody.bodyType     = RigidbodyType2D.Kinematic;
     circleCollider.enabled = false;
     _state = BirdState.Idle;
 }
Esempio n. 19
0
    // Use this for initialization
    void Start()
    {
        GameObject[] wpObjs = GameObject.FindGameObjectsWithTag("waypoint");
        m_Waypoints = new Vector3[wpObjs.Length];
        for(int i=0; i<wpObjs.Length; i++){
            m_Waypoints[i] = wpObjs[i].GetComponent<Transform>().position;
        }
        if(specialWaypoint != null){
            specialLoc = specialWaypoint.GetComponent<Transform>().position;
        }
        m_Char = GameObject.FindGameObjectWithTag("Char");

        //spawn the bird wherever you want and it will fly to an arbirary waypoint
        m_State = BirdState.Moving;

        //move the bird to an arbitrary waypoint
        curWaypoint = transform.position;
        nextWaypoint = m_Waypoints[(Random.Range(0, m_Waypoints.Length))];
        moveTime = Time.time;
        journeyLength = Vector3.Distance(curWaypoint, nextWaypoint);

        daynight = GameObject.FindGameObjectWithTag("Manager").GetComponent<DayNightManager>();
        mAudio = GameObject.FindGameObjectWithTag ( "Manager" ).GetComponent<AudioManager> ();
        mAnimator = GetComponent<Animator>();
    }
Esempio n. 20
0
    void Update()
    {
        gameManagerScript.UpdateHPBar(Health);
        switch (birdState)
        {
            case BirdState.idle:
                newPos.x -= speed * Time.deltaTime;

            if (transform.position.x < 20)
            {
                birdState = BirdState.fighting;
            }
                break;

            case BirdState.fighting:
                reload -= Time.deltaTime;
                if (this.transform.position.y == newPos.y)
                {
                    newPos.y = Random.Range(-9, 14);
                }

                if (reload < 0)
                {
                    reload = 2;
                    if (player != null) {
                        eggTarget = player.transform.position.x + Random.Range(-1f,1f);
                    }
                    else {
                        player = GameObject.FindGameObjectWithTag("Player");
                        eggTarget = Random.Range(-22, -8);
                    }

                    Arrow = Instantiate(ArrowPrefab, new Vector3(eggTarget, 13, -9), Quaternion.identity) as GameObject;
                    StartCoroutine(SpawnEgg());
                }
                break;
        }
    }
Esempio n. 21
0
 void NextBird()             //1.5秒后下一只鸟上场
 {
     state = BirdState.Idle; //改变鸟状态
 }
Esempio n. 22
0
 public void Attack()
 {
     m_State = BirdState.Attack;
     canAttack = true;
 }
Esempio n. 23
0
    void Update()
    {
        if (TheGame.Get().IsPaused())
        {
            return;
        }

        state_timer += Time.deltaTime;

        if (state == BirdState.Sit)
        {
            DetectThreat();

            if (state_timer > sit_duration)
            {
                state_timer = 0f;
                FindFlyPosition(transform.position, wander_radius, out target_pos);
                state = BirdState.Fly;
                sit_model.gameObject.SetActive(false);
                fly_model.gameObject.SetActive(true);
            }
        }

        if (state == BirdState.Alerted)
        {
            if (state_timer > alerted_duration)
            {
                state_timer = 0f;
                FindFlyPosition(transform.position, wander_radius, out target_pos);
                state = BirdState.Fly;
                sit_model.gameObject.SetActive(false);
                fly_model.gameObject.SetActive(true);
            }
        }

        if (state == BirdState.Fly)
        {
            if (state_timer > fly_duration)
            {
                state_timer = 0f;
                Vector3 npos;
                bool    succes = FindGroundPosition(start_pos, wander_radius, out npos);
                if (succes)
                {
                    state      = BirdState.FlyDown;
                    target_pos = npos;
                    fly_model.gameObject.SetActive(true);
                    sit_model.gameObject.SetActive(false);
                }
            }

            if (fly_model.gameObject.activeSelf && HasReachedTarget())
            {
                fly_model.gameObject.SetActive(false);
            }

            DoMovement();
        }

        if (state == BirdState.FlyDown)
        {
            if (HasReachedTarget())
            {
                state_timer = Random.Range(-1f, 1f);
                state       = BirdState.Sit;
                sit_model.gameObject.SetActive(true);
                fly_model.gameObject.SetActive(false);
                facing.y = 0f;
                facing.Normalize();
            }

            //Move
            DoMovement();
        }

        Quaternion face_rot = Quaternion.LookRotation(facing, Vector3.up);

        transform.rotation = Quaternion.RotateTowards(transform.rotation, face_rot, 200 * Time.deltaTime);
    }
Esempio n. 24
0
    void Update()
    {
        gameManagerScript.UpdateHPBar(Health);

        if (birdState == BirdState.idle)
        {
            newPos.x -= speed * Time.deltaTime;

            if (transform.position.x < 20)
            {
                birdState = BirdState.powerUp;
                powerUpTimer = 1.0f;
            }
        }

        if (birdState == BirdState.powerUp)
        {
            powerUpTimer -= Time.deltaTime;

            if (powerUpTimer < 0)
            {
                birdState = BirdState.highSpeed;
            }
        }

        if (birdState == BirdState.highSpeed)
        {
            newPos.x -= highSpeed * Time.deltaTime;
        }
    }
Esempio n. 25
0
    private void UpdateGameState(GameState newState)
    {
        // Update game state.
        gameState = newState;

        // In the pre-game phase, bird should be floating, with a rather slow wing movement.
        if (gameState == GameState.PreGame)
        {
            birdState = BirdState.Floating;
            gameObject.GetComponent <Animator>().speed = 1.0f;

            // Reset bird position to its initial position and zero rotation.
            transform.position = initPos;
            transform.rotation = Quaternion.Euler(0.0f, 0.0f, 0.0f);

            // Play a sound to indicate we are in pre-game phase.
            sfxSwoosh.Play();

            // Randomly select a bird: blue, yellow, or red. We do this in a
            // coroutine, because changing bird animation is an event trigger
            // process, which requires a delay in the thread. We don't (and can't)
            // have a delay in the main thread, so we create a new.
            StartCoroutine(RandomizeBird());
        }

        // The bird should be flying in the game, with a rather faster wing movement.
        else if (gameState == GameState.InGame)
        {
            birdState = BirdState.Flying;
            gameObject.GetComponent <Animator>().speed = 2.0f;
        }

        // If the game is ending, the bird should be dying, with a slow wing movement.
        else if (gameState == GameState.EndingGame)
        {
            birdState = BirdState.Dying;
            gameObject.GetComponent <Animator>().speed = 1.25f;

            // If the bird has a positive vertical velocity due to a jump, we should
            // make it zero, so that it won't go up while dying.
            currVerVel = 0.0f;

            // Current z rotation of the bird should be the initial dying z rotation
            // which will be updated until the bird is completely dead lying on ground.
            // However, transform.eulerAngles.z is not enough, since it is in between
            // 0 and 360, but we want it to be between -90 and 0 if the bird is looking
            // downwards.
            dyingRz = transform.eulerAngles.z < 270.0 ? transform.eulerAngles.z : transform.eulerAngles.z - 360.0f;
        }

        // If the game is over, the bird should be dead, with no wing movement.
        else if (gameState == GameState.GameOver)
        {
            birdState = BirdState.Dead;
            gameObject.GetComponent <Animator>().speed = 0.0f;

            // When the game is over, the bird should be looking ground.
            transform.rotation = Quaternion.Euler(0.0f, 0.0f, -90.0f);

            // The bird should be lying just above the ground when it's dead. However,
            // the collision detection might have occured a bit after the bird actually
            // hit ground. We should correct that by setting the y position of the bird
            // equal to ground upper level, plus half the horizontal width of the bird.
            // Why horizontal? Because when the bird is dead, it is looking ground, which
            // means its vertical height is equal to the horizontal width of it while floating.
            // As the last step, we multiply the width with 0.8, so that bird's mouth is a
            // bit into the ground.
            var sprite = gameObject.GetComponent <SpriteRenderer>().sprite;
            var width  = sprite.rect.width / sprite.pixelsPerUnit * 0.8f;
            transform.position = new Vector3(transform.position.x, GroundUpperY + width * 0.5f, transform.position.z);
        }
    }
Esempio n. 26
0
 public BirdFlewAwayException(string message, BirdState birdState) : base(message)
 {
     BirdStatus = birdState;
 }
Esempio n. 27
0
 void Start()
 {
     rb.bodyType          = RigidbodyType2D.Kinematic;
     birdCollider.enabled = false;
     _state = BirdState.Idle;
 }
Esempio n. 28
0
 // Use this for initialization
 void Start()
 {
     state = BirdState.BeforeThrown;
     GetComponent <TrailRenderer>().enabled = false;
 }
Esempio n. 29
0
 protected void SetState(BirdState state)
 {
     _state = state;
 }
Esempio n. 30
0
 public void OnThrow()
 {
     GetComponent <Rigidbody2D>().bodyType  = RigidbodyType2D.Dynamic;
     GetComponent <TrailRenderer>().enabled = true;
     state = BirdState.Thrown;
 }
Esempio n. 31
0
 void Start()
 {
     rb.bodyType = RigidbodyType2D.Kinematic;
     col.enabled = false;
     state       = BirdState.Idle;
 }
Esempio n. 32
0
 // Use this for initialization
 void Start()
 {
     cart.m_Speed = 0;
     myState      = BirdState.Idle;
 }
Esempio n. 33
0
 public void SetStateToFollow()
 {
     _birdState = BirdState.Follow;
 }
Esempio n. 34
0
    // Update is called once per frame
    void Update()
    {
        float t = getTime();

        bool moveToState = false;

        if (state != nextState)
        {
            stateStartedTime = t;
            state            = nextState;
            moveToState      = true;
        }

        float stateElapsed = t - stateStartedTime;

        switch (state)
        {
        case FlockState.ground:
        {
            foreach (var bird in birds)
            {
                bird.offset = Vector2.zero;
                bird.trans.localPosition = bird.originalPosition;

                bird.trans.GetComponent <Animator>().SetInteger("animState", 0);
            }

            if (stateElapsed > groundDuration)
            {
                nextState = FlockState.rise;
            }
        }
        break;

        case FlockState.rise:
        {
            foreach (var bird in birds)
            {
                bird.offset += new Vector2(0, Time.deltaTime * 4f);
                bird.trans.localPosition = bird.originalPosition + bird.offset;

                bird.trans.GetComponent <Animator>().SetInteger("animState", 1);
            }

            if (stateElapsed > riseDuration)
            {
                nextState = FlockState.fly;
            }
        }
        break;

        case FlockState.fly:
        {
            for (int i = 0; i < birds.Count; ++i)
            {
                BirdState bird = birds[i];

                bird.offset += new Vector2(Mathf.Sin(t * 4 + i) * 0.018f, Mathf.Sin(t * 2.4f + i) * 0.04f);

                bird.trans.localPosition = bird.originalPosition + bird.offset;
            }

            if (stateElapsed > flyDuration)
            {
                nextState = FlockState.land;
            }
        }
        break;

        case FlockState.land:
        {
            foreach (var bird in birds)
            {
                bird.offset -= bird.offset * landDuration * Time.deltaTime;

                bird.trans.localPosition = bird.originalPosition + bird.offset;
            }

            if (stateElapsed > landDuration)
            {
                nextState = FlockState.ground;
            }
        }
        break;
        }
    }
Esempio n. 35
0
    void FixedUpdate()
    {
        state = hash[animator.GetCurrentAnimatorStateInfo(0).shortNameHash];

        //Debug.DrawRay(this.transform.position, this.GetComponent<Rigidbody>().velocity * 5f, Color.magenta);
        //Debug.DrawRay(this.transform.position, this.transform.up * 1f, Color.blue);
        //Debug.DrawRay(this.transform.position, this.transform.forward * 1f, Color.green);
        //Debug.DrawRay(this.transform.position, Vector3.down * 1f, Color.red);

        Vector3 from = this.transform.position;
        Vector3 direction = this.transform.forward;

        //Debug.Log(this.GetComponent<Rigidbody>().velocity.magnitude);
        if (checkDiveCollision())
        {
            this.GetComponent<PlayerSync>().SendBool(Registry.Animator.CanDive, false);
            this.GetComponent<PlayerSync>().SendBool(Registry.Animator.Diving, false);
            animator.SetBool(Registry.Animator.CanDive, false);
            animator.SetBool(Registry.Animator.Diving, false);
        }
        else
        {
            this.GetComponent<PlayerSync>().SendBool(Registry.Animator.CanDive, true);
            animator.SetBool(Registry.Animator.CanDive, true);

            float check = DIVE_SWOOP_DISTANCE;
            if (this.GetComponent<Rigidbody>().velocity.magnitude < check)
                check = this.GetComponent<Rigidbody>().velocity.magnitude;

            if (Physics.Raycast(from, this.transform.forward, out hit, check, layerMask))
            {
                if (state != BirdState.AboutFacing && state != BirdState.FlappingForward)
                {
                    if (Vector3.Angle(hit.normal, -direction) < ABOUT_FACE_ANGLE)
                    {
                        this.GetComponent<PlayerSync>().SendTrigger(Registry.Animator.AboutFace);
                        animator.SetTrigger(Registry.Animator.AboutFace);
                    }
                }
            }
        }

        //Debug.DrawRay(from, (this.transform.forward + this.transform.right) * 0.8f, Color.black);
        //Debug.DrawRay(from, (this.transform.forward - this.transform.right) * 0.8f, Color.black);
        if (Physics.Raycast(from, this.transform.forward + this.transform.right, out hit, 1f, layerMask))
        {
            tilting = 1; // right
            tiltTowards(-TILT_LIMIT); // tilt away (opposite)

            if (Physics.Raycast(from, this.transform.forward + this.transform.right, out hit, 0.7f, layerMask))
            {
                rotationY = Mathf.Lerp(rotationY, rotationY - 20f, Time.deltaTime);
                this.transform.localEulerAngles = new Vector3(transform.localEulerAngles.x, rotationY, 0);
            }

        }
        else if (Physics.Raycast(from, this.transform.forward - this.transform.right, out hit, 1f, layerMask))
        {
            tilting = -1; // left
            tiltTowards(TILT_LIMIT);

            if (Physics.Raycast(from, this.transform.forward - this.transform.right, out hit, 0.7f, layerMask))
            {
                rotationY = Mathf.Lerp(rotationY, rotationY + 20f, Time.deltaTime);
                this.transform.localEulerAngles = new Vector3(transform.localEulerAngles.x, rotationY, 0);
            }
        }
        else
        {
            tilting = 0; // none
        }
    }
Esempio n. 36
0
 public void SetBirdStateToFly()
 {
     state    = BirdState.FLYING;
     landPos += new Vector2(Random.Range(-2.5f, 2.5f), Random.Range(-1.5f, 1.5f));
 }