コード例 #1
0
ファイル: ChompAI.cs プロジェクト: ghostonline/ld46
    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;
            }
        }
    }
コード例 #2
0
ファイル: ChompAI.cs プロジェクト: ghostonline/ld46
 public void WakeUp()
 {
     if (m_state == ChompAIState.Sleeping)
     {
         m_wakeTimer = 0f;
         m_state     = ChompAIState.Waking;
     }
 }
コード例 #3
0
ファイル: ChompAI.cs プロジェクト: ghostonline/ld46
    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;
        }
    }
コード例 #4
0
ファイル: ChompAI.cs プロジェクト: ghostonline/ld46
    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;
            }
        }
    }
コード例 #5
0
ファイル: ChompAI.cs プロジェクト: ghostonline/ld46
 private void Awake()
 {
     m_rigidbody = GetComponent <Rigidbody2D>();
     m_state     = m_initialState;
 }