Exemplo n.º 1
0
    private void FixedUpdate()
    {
        if (m_state != ChompAIState.Sleeping && m_state != ChompAIState.Waking)
        {
            m_controller.Move(m_movement, false, true);
        }

        if (m_anchor)
        {
            Vector2 anchorOffset       = transform.position - m_anchor.position;
            var     currentChainLength = anchorOffset.magnitude;
            if (currentChainLength > m_chainLength)
            {
                if (m_fixedAnchor)
                {
                    MoveChomp(-anchorOffset);
                }
                else
                {
                    MoveAnchor(anchorOffset);
                }
                m_state = ChompAIState.Hungry;
            }
        }
    }
Exemplo n.º 2
0
 public void WakeUp()
 {
     if (m_state == ChompAIState.Sleeping)
     {
         m_wakeTimer = 0f;
         m_state     = ChompAIState.Waking;
     }
 }
Exemplo n.º 3
0
    void ChaseFood(Food target)
    {
        var targetOffset = ChaseTarget(target.transform);

        if (targetOffset.magnitude < m_eatRange && target.m_satisfying)
        {
            m_eating    = true;
            m_eatTimer += Time.deltaTime;

            if (m_eatTimer >= m_eatDuration)
            {
                target.Consume();
                m_state = ChompAIState.Fed;
                GameController.Instance.OnChompFed();
            }
        }
        else
        {
            m_eatTimer = 0;
        }
    }
Exemplo n.º 4
0
    void Update()
    {
        m_eating = false;

        if (m_state == ChompAIState.Sleeping)
        {
            m_emitTimer += Time.deltaTime;
            if (m_emitTimer >= m_sleepEmitInterval)
            {
                m_emitTimer = 0;
                GameObject.Instantiate(m_ZzzsPrefab, m_ZzzsEmitPoint.position, Quaternion.identity);
            }
        }
        else if (m_state == ChompAIState.Hungry)
        {
            var target = FindNearestEdible();
            if (target)
            {
                ChaseFood(target);
            }
            else
            {
                Idle();
            }
        }
        else if (m_state == ChompAIState.Fed)
        {
            m_emitTimer += Time.deltaTime;
            if (m_emitTimer >= m_sleepEmitInterval)
            {
                m_emitTimer = 0;
                GameObject.Instantiate(m_HeartPrefab, m_ZzzsEmitPoint.position, Quaternion.identity);
            }

            var target = FindNearestPlayer();
            if (target != null)
            {
                ChaseTarget(target.transform);
            }
        }

        if (m_state == ChompAIState.Sleeping)
        {
            m_sprite.sprite = m_spriteSleep;
        }
        else if (m_state == ChompAIState.Waking)
        {
            const float m_wakeDuration = 1f;
            const float m_openTime     = 0.25f;
            const float m_closeTime    = 0.25f;
            const float m_totalTime    = m_openTime + m_closeTime;
            m_animationTimer += Time.deltaTime;
            if (m_animationTimer < m_openTime)
            {
                m_sprite.sprite = m_spriteSleep;
            }
            else if (m_animationTimer < m_totalTime)
            {
                m_sprite.sprite = m_spriteClose;
            }
            else
            {
                m_animationTimer -= m_totalTime;
            }

            m_wakeTimer += Time.deltaTime;
            if (m_wakeTimer >= m_wakeDuration)
            {
                m_state = ChompAIState.Hungry;
            }
        }
        else
        {
            const float m_openTime  = 0.25f;
            const float m_closeTime = 0.25f;
            const float m_totalTime = m_openTime + m_closeTime;
            m_animationTimer += Time.deltaTime;
            if (m_animationTimer < m_openTime)
            {
                m_sprite.sprite = m_spriteOpen;
            }
            else if (m_animationTimer < m_totalTime)
            {
                if (m_eating && m_sprite.sprite != m_spriteClose)
                {
                    AudioPlayer.Play(Clip.Munch);
                }
                m_sprite.sprite = m_spriteClose;
            }
            else
            {
                m_animationTimer -= m_totalTime;
            }
        }
    }
Exemplo n.º 5
0
 private void Awake()
 {
     m_rigidbody = GetComponent <Rigidbody2D>();
     m_state     = m_initialState;
 }