Exemple #1
0
        //釣りゲーム外

        /// <summary>
        /// 魚が現れる時に最初に行う処理
        /// </summary>
        public void SetAppear()
        {
//            Debug.Log("魚が現れた");
            HPbar.gameObject.SetActive(false);
            m_state = FishState.Nomal;
            ColorFader.Instance.StartFadeIn(sprite, 0.5f);
        }
 public void JumpHighPosition()
 {
     state = FishState.Fall;
     transform.position = new Vector3(transform.position.x, transform.position.y, 0);
     fall.enabled       = true;
     collider.enabled   = true;
 }
Exemple #3
0
 protected void PushState(Action action, FishState state)
 {
     if (action != null)
     {
         _brain.PushState(action, state);
     }
 }
Exemple #4
0
 // Use this for initialization
 void Start()
 {
     timeSinceLastPlayerSound = fleeingTime;
     fishReference            = this.gameObject.GetComponent <Fish>();
     currentState             = approachState;
     currentState.Start();
 }
Exemple #5
0
    void Struggle()
    {
        anim.SetBool("hurt", true);
        tag = "Untagged";
        if (struggleRotationCooldown < 0)
        {
            struggleRotationDirection *= -1;
            struggleRotationCooldown   = 5;
        }
        transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.Euler(0, 0, 180 * struggleRotationDirection), 0.2f);

        stunCountdown -= Time.deltaTime;
        if (stunCountdown < 0 && healthSlider.value == 0)
        {
            Debug.Log("dead");
            jumpCountdown = 2;
            state         = FishState.Dead;
        }
        if (stunCountdown < 0 && submerged)
        {
            phase++;
            transform.position = new Vector2(pools[targetPool].x, pools[targetPool].y);
            tag   = "Enemy";
            state = FishState.Spitting;
        }
        //Jumping before being submerged will cause bugs
        if (phase <= 3 && stunCountdown < 0 && submerged)
        {
            //Debug.Log("reset");
            resetOrientation();
            anim.SetBool("hurt", false);
        }
    }
Exemple #6
0
    void calculateJump(float x2, float y2)
    {
        // Debug.Log(x2 + " " +  y2 + " " + targetPool);

        float x1 = transform.position.x;
        float y1 = transform.position.y;



        if (y2 < -2)
        {
            y2 = -2;
        }

        float x3 = pools[targetPool].x;
        float y3 = pools[targetPool].y;

        denom = (x1 - x2) * (x1 - x3) * (x2 - x3);
        a     = (x3 * (y2 - y1) + x2 * (y1 - y3) + x1 * (y3 - y2)) / denom;
        b     = ((x3 * x3) * (y1 - y2) + (x2 * x2) * (y3 - y1) + (x1 * x1) * (y2 - y3)) / denom;
        c     = (x2 * x3 * (x2 - x3) * y1 + x3 * x1 * (x3 - x1) * y2 + x1 * x2 * (x1 - x2) * y3) / denom;

        float maxHeightX = (-b) / (2 * a);
        float maxHeight  = (a * maxHeightX * maxHeightX) + b * maxHeightX + c;

        if (phase == 3)
        {
            splash();
        }


        state = FishState.Jumping;
    }
    // Use this for initialization
    void Start()
    {
        //Fishes start needing help
        fishState = FishState.Waiting;

        animator = GetComponent<Animator>();
    }
Exemple #8
0
    private void handleState()
    {
        if (state == FishState.COOLDOWN || state == FishState.EXPLODE)
        {
            return;
        }

        if (config.ExplodeTriggerDistance > 0.001f && Vector2.Distance(player.position, transform.position) < config.ExplodeTriggerDistance)
        {
            state = FishState.EXPLODE;
            Invoke("Explode", config.ExplodeDelay);
            explodeTimer = Time.time;
        }

        if (!config.IsAggressive)
        {
            return;
        }

        if (Vector2.Distance(player.position, transform.position) < config.AggroRange)
        {
            state = FishState.ATTACK;
        }
        else
        {
            state = FishState.IDLE;
        }
    }
    IEnumerator Dead()
    {
        string scoreName = string.Empty;

        if (state == FishState.Walking)
        {
            GameManager.DestroyEnemy(20);
            scoreName = "Prefab/point020";
        }
        if (state == FishState.Fall)
        {
            GameManager.DestroyEnemy(100);
            scoreName = "Prefab/point100";
        }

        dead.enabled     = true;
        collider.enabled = false;
        state            = FishState.Dead;

        animation.Stop();

        AudioSource.PlayClipAtPoint(deadSound, Vector3.zero);

        yield return(new WaitForSeconds(dead.time * 2f - 0.01f));

        GameObject score = GameObject.Instantiate(Resources.Load(scoreName)) as GameObject;

        Destroy(score, score.animation ["pointUp@point"].length);
        score.transform.position = gameObject.transform.position;
        Destroy(transform.parent.gameObject);
    }
Exemple #10
0
        /// <summary>
        /// 参照数1!
        /// </summary>
        private void SetCaught()
        {
            sprite.sprite = fishInfo.icon;
            HPbar.gameObject.SetActive(false);
            m_state = FishState.Caught;
//            m_fishingHook.fishingGameMgr.FishingSucceeded();
        }
Exemple #11
0
    private void ChangeState(FishState newState)
    {
        fishState = newState;

        switch (fishState)
        {
        case FishState.Swimming:
            targetPosition = SortPosition(isMovingRight);
            LookAt(targetPosition);

            elapsedBlinkTime = 0;
            anim.SetBool("Eating", false);
            break;

        case FishState.Hungry:
            GetClosestFoodLocation();
            break;

        case FishState.Eating:
            anim.SetBool("Eating", true);
            StartCoroutine(EatingBehaviour());
            break;

        case FishState.Idle:
            anim.SetTrigger("Blink");
            break;
        }
    }
Exemple #12
0
    // Update is called once per frame
    void Update()
    {
        switch (m_state)
        {
        case FishState.Swimming:
            Swimming();

            //if (Input.GetKeyDown(KeyCode.Space))
            //{
            //    m_state = FishState.Facing;
            //    m_lookTimer = 0;
            //}

            break;

        case FishState.Facing:
            Facing();

            m_lookTimer += Time.deltaTime;
            if (m_lookTimer > m_lookDuration)
            {
                m_state = FishState.Swimming;
            }

            break;
        }
    }
Exemple #13
0
        /// <summary>
        /// 針に食いついたときに最初に行う処理
        /// 釣りゲーム状態に移行する
        /// 参照数1!
        /// </summary>
        private void SetBiting()
        {
//            Debug.Log("魚がくいついた!");
            m_state = FishState.Biting;
            HPbar.gameObject.SetActive(true);
            fishingGameMgr.StartFishing();
        }
Exemple #14
0
    void Start()
    {
        fishManager = GameObject.FindGameObjectWithTag("FishManager");
        gameObject.transform.parent = fishManager.transform;

        if (hunger == 0)
        {
            hunger = 2.5f * feedingInterval;
        }
        fishState = FishState.Full;

        Camera camera = GameObject.FindGameObjectWithTag("MainCamera").GetComponent <Camera>();

        x = camera.ViewportToWorldPoint(new Vector3(1, 1)).x - gameObject.GetComponent <BoxCollider2D>().size.x / 1.5f;

        image       = gameObject.GetComponent <SpriteRenderer>();
        rigidbody2D = gameObject.GetComponent <Rigidbody2D>();

        foreach (string consumable in consumables)
        {
            foodList.AddRange(GameObject.FindGameObjectsWithTag(consumable));
        }

        coinList.AddRange(GameObject.FindGameObjectsWithTag("Coin"));
    }
Exemple #15
0
 public void Flee(List <Vector3> sharks)
 {
     m_KnownSharks = sharks;
     m_FishState   = FishState.Fleeing;
     m_Speed       = m_FleeSpeed;
     StartCoroutine(FleeRoutine());
 }
Exemple #16
0
 void OnChaseTriggerEnter(Collider other)
 {
     if (other.tag == "Hook")
     {
         TargetLine = other.GetComponent <ZB_VerletLine>();
         CurrState  = FishState.Chasing;
     }
 }
Exemple #17
0
    IEnumerator FleeRoutine()
    {
        yield return(new WaitForSeconds(Random.Range(1, 5)));

        m_Speed     = Random.Range(m_SpeedRange.x, m_SpeedRange.y);
        m_FishState = FishState.Wandering;
        m_KnownSharks.Clear();
    }
Exemple #18
0
 void OnLightOff()
 {
     if (_state == FishState.Lured)
     {
         _state = FishState.LoosingInterest;
         Invoke(nameof(BackToDefault), loosingInterestTime);
     }
 }
Exemple #19
0
        void OnLightOn()
        {
            if (InLureArea && _state != FishState.Fleeing)
            {
                _state = FishState.Lured;
//                image.color = Color.yellow;
            }
        }
Exemple #20
0
 void OnMouthTriggerEnter(Collider other)
 {
     print(other.name);
     if (TargetLine == null || !TargetLine.hooked)
     {
         CurrState = FishState.Hooked;
         SetHook();
     }
 }
Exemple #21
0
 // Start is called before the first frame update
 void Awake()
 {
     anim = GetComponent <Animator>();
     path = GetComponent <DOTweenPath>();
     //path.duration = speed;
     state = FishState.move;
     //path.loopType = LoopType.Incremental;
     //path.loops = -1;
 }
Exemple #22
0
 public void SetState(FishState pState)
 {
     if (_abstractState != null)
     {
         _abstractState.Refresh();
     }
     _abstractState = _stateCache[pState];
     _abstractState.Start();
 }
Exemple #23
0
 public void Initialize(int id, Dictionary <BehaviorType, bool> enablebehavior, List <int> preyid, List <int> predatorid)
 {
     groupID            = id;
     enableBehaviorList = enablebehavior;
     preyIDList         = preyid;
     predatorIDList     = predatorid;
     fishState          = new FishState();
     fishState.Initialize(gameObject);
     taskList = new List <Task>();
 }
Exemple #24
0
    public void TouchDown()
    {
        state = FishState.Walking;

        transform.position =

            new Vector3(transform.position.x,
                        -42f,
                        transform.position.z);
    }
Exemple #25
0
    void Reproduction()
    {
        float tempDistance;
        int   numberOfSpawn = Random.Range(1, 3);

        Collider[] overlappedObjects = Physics.OverlapSphere(transform.position, manager.awarenessRange);

        foreach (Collider overlappedObject in overlappedObjects)
        {
            if (overlappedObject.CompareTag("Fish") &&
                overlappedObject.GetComponent <FishHealth>().male)                                        // Checks if overlapped object is a fish and is male
            {
                tempDistance = Vector3.Distance(transform.position, overlappedObject.transform.position); // Check distance for each fish between themself and the current fish

                if (closestDistance == 0)                                                                 // Ensures that closest distance has an initial value otherwise it can never be compared
                {
                    closestDistance = tempDistance;
                }

                if (tempDistance <= closestDistance) // Check if the new fish that is checked is closer than the most recent closest fish
                {
                    closestDistance = tempDistance;
                }
            }
        }

        if (closestDistance <= manager.awarenessRange &&
            currentFishState == FishState.ReadyToReproduce &&
            canReproduce)                             // Check if the fish has another fish nearby and this fish is ready to reproduce
        {
            currentFishState = FishState.Reproducing; // Change state to reproducing
        }

        if (currentFishState == FishState.Reproducing)
        {
            gestationPeriod -= Time.deltaTime; // Reduces the time to spawn another fish

            if (gestationPeriod <= 0)
            {
                for (int i = 0; i < numberOfSpawn; i++)
                {
                    manager.allFish.Add(Instantiate(manager.fishPrefab, transform.position, Quaternion.identity)); // Instantiate the fish at that position and add it to the listy
                    manager.lifetimeFishCount++;
                }

                fishHealth.ModifyFood(reproductionCost); // How much food is removed upon reproduciton
                fishHealth.timesReproduced++;

                canReproduce = false;

                GenerateNewGestationPeriod();
                currentFishState = FishState.Roaming; // Change state back to roaming
            }
        }
    }
Exemple #26
0
 void OnTriggerEnter2D(Collider2D collider)
 {
     if(fishState == FishState.Waiting){
         PlayerHealth playerHealth = collider.gameObject.GetComponent<PlayerHealth>();
         if(playerHealth != null){
             playerHealth.AddFish(this);
             fishState = FishState.Following;
             animator.SetTrigger("Rescue");
         }
     }
 }
Exemple #27
0
        void Flee()
        {
//            image.color = Color.red;
            var fleeDirection = (transform.position - _anglerfish.transform.position).normalized;

            _rigidbody.velocity = fleeDirection * fleeingSpeed;
            _state = FishState.Fleeing;

            CancelInvoke();
            Invoke(nameof(BackToDefault), fleeingTime);
        }
Exemple #28
0
    private void Awake()
    {
        manager = GameObject.FindGameObjectWithTag("FishManager").GetComponent <FishGroupManager>(); // Fetches the Fish Group Manager script from the Fish Manager object
        fishDestinationTarget = GameObject.FindGameObjectWithTag("FishTarget");
        fishHealth            = this.GetComponent <FishHealth>();

        sphereCollider        = this.GetComponent <SphereCollider>();
        sphereCollider.radius = 125;

        currentFishState = FishState.Roaming;
    }
Exemple #29
0
    // Use this for initialization
    void Start()
    {
        rBody          = GetComponent <Rigidbody>();
        hookPointRBody = HookPoint.GetComponent <Rigidbody>();
        navAgent       = GetComponent <NavMeshAgent>();
        initSpeed      = navAgent.speed;
        MouthTrigger.onTriggerEnter += OnMouthTriggerEnter;
        ChaseTrigger.onTriggerEnter += OnChaseTriggerEnter;
        ChaseTrigger.onTriggerExit  += OnChaseTriggerExit;

        CurrState = StartState;
    }
Exemple #30
0
    // Update is called once per frame
    void FixedUpdate()
    {
        //Debug.Log(state);
        FishState returnState = state.Update(this);

        if (returnState != null)
        {
            state = returnState;

            state.Enter(this);
        }
    }
 void FishActive()
 {
     //reset to normal when timer runs out
     if (ActiveTimerFish > 1.5f)
     {
         print("Fish Ability over");
         state           = FishState.Normal;
         ActiveTimerFish = 0;
         timerFish       = 0;
         FishShouldCount = false;
     }
 }
Exemple #32
0
        /// <summary>
        /// 釣り針を狙うときに行う最初の処理
        /// 参照数1!
        /// </summary>
        private void SetApproaching()
        {
            if (m_fishingHook.CanBite())
            {
//                Debug.Log("魚がエサを狙っている");
                m_state = FishState.Approaching;
                m_fishingHook.SetTarget(this);
            }
            else
            {
                //              Debug.Log("釣り針はなにか用事があるようだ。");
            }
        }
Exemple #33
0
 public override void Follow(Transform lastTarget)
 {
     base.Follow (lastTarget);
     fishState = FishState.Following;
 }