Esempio n. 1
0
 void execIA()
 {
     if ((new Vector2(transform.position.x, transform.position.y) - new Vector2(m_pacman.transform.position.x, m_pacman.transform.position.y)).magnitude < m_pacmanRadius)
     {
         setTarget(Mathf.RoundToInt(m_pacman.transform.position.x), Mathf.RoundToInt(m_pacman.transform.position.y));
     }
     else if (SnakePowerupPopulatorLogic.powerup != null)
     {
         setTarget(Mathf.RoundToInt(SnakePowerupPopulatorLogic.powerup.transform.position.x), Mathf.RoundToInt(SnakePowerupPopulatorLogic.powerup.transform.position.y));
     }
     else
     {
         var target = new UniformVector2CircleSurfaceDistribution(m_randomRange).Next(new StaticRandomGenerator <DefaultRandomGenerator>());
         setTarget(Mathf.RoundToInt(transform.position.x + target.x), Mathf.RoundToInt(transform.position.y + target.y));
     }
 }
Esempio n. 2
0
    void Update()
    {
        if (PlayerControler.Instance() == null)
        {
            return;
        }

        m_timer -= Time.deltaTime;

        if (m_stopped)
        {
            Vector2 target = PlayerControler.Instance().transform.position;
            Vector2 pos    = transform.position;

            m_viewDirection = target - pos;
        }
        else
        {
            m_viewDirection = m_velocity;
        }

        if (m_timer <= 0)
        {
            if (m_stopped)
            {
                m_weapon.EndFire();
                m_timer = new UniformFloatDistribution(m_minMoveTime, m_maxMoveTime).Next(new StaticRandomGenerator <MT19937>());

                var dir = new UniformVector2CircleSurfaceDistribution(m_speed).Next(new StaticRandomGenerator <MT19937>());

                if (Physics2D.CircleCast(transform.position, 0.9f, dir, dir.magnitude, LayerMask.GetMask("Default")).collider == null || m_tryCount >= 10)
                {
                    m_velocity = dir;

                    m_animator.SetBool("Move", true);

                    m_stopped  = false;
                    m_tryCount = 0;
                }
                else
                {
                    m_timer = 0;
                    m_tryCount++;
                }
            }
            else
            {
                Vector2 target = PlayerControler.Instance().transform.position;
                Vector2 pos    = transform.position;

                m_viewDirection = target - pos;

                m_weapon.StartFire(m_viewDirection);

                m_velocity = new Vector2(0, 0);

                m_timer = new UniformFloatDistribution(m_minFireTime, m_maxFireTime).Next(new StaticRandomGenerator <MT19937>());

                m_animator.SetBool("Move", false);

                m_stopped = true;
            }
        }

        m_weapon.Process(m_viewDirection);

        m_rigidbody.velocity = m_velocity;

        float angle = Mathf.Atan2(m_viewDirection.y, m_viewDirection.x);

        m_animator.SetBool("Left", angle <-Mathf.PI / 2 || angle> Mathf.PI / 2);
    }