Esempio n. 1
0
    public bool ForcedMove(string dir)
    {
        m_target_x = m_x_position;
        m_target_y = m_y_position;
        switch (dir)
        {
        case "west":
            ++m_target_y;
            break;

        case "north":
            ++m_target_x;
            break;

        case "east":
            --m_target_y;
            break;

        case "south":
            --m_target_x;
            break;
        }

        Arena arena = m_arena.GetComponent <Arena>();

        if (!arena.CanMove(m_x_position, m_y_position, m_target_x, m_target_y))
        {
            return(false);
        }

        Arena.MoveInfo info = arena.GridOcupied(m_target_x, m_target_y);
        if (!info.free)
        {
            return(false);
        }

        Transform root = arena.transform.Find(string.Format("Row{0}/Col{1}", m_y_position, m_x_position));

        m_tile_anim = root.GetChild(root.childCount - 1).gameObject.GetComponent <Animator>();
        if (m_tile_anim != null)
        {
            m_tile_anim.speed = 1.0f;
        }

        m_animation_state = 0.0f;
        if (arena.GridSafe(m_target_x, m_target_y))
        {
            m_status = Status.Moving;
        }
        else
        {
            m_status = Status.Falling;
        }
        return(true);
    }
Esempio n. 2
0
    public bool Move(int n)
    {
        m_target_x = m_x_position;
        m_target_y = m_y_position;
        switch (m_orientation)
        {
        case 0:
            m_target_y += n;
            break;

        case 1:
            m_target_x -= n;
            break;

        case 2:
            m_target_y -= n;
            break;

        case 3:
            m_target_x += n;
            break;
        }

        Arena arena = m_arena.GetComponent <Arena>();

        if (!arena.CanMove(m_x_position, m_y_position, m_target_x, m_target_y))
        {
            return(false);
        }

        Animator anim = gameObject.GetComponent <Animator>();

        m_animation_state = 0.0f;
        if (!arena.GridSafe(m_target_x, m_target_y))
        {
            if (anim != null)
            {
                anim.speed = 1.0f;
            }

            m_status = Status.Falling;
            return(true);
        }

        Arena.MoveInfo info = arena.GridOcupied(m_target_x, m_target_y);
        if (!info.free)
        {
            int ttx = 2 * m_target_x - m_x_position;
            int tty = 2 * m_target_y - m_y_position;

            if (!arena.CanMove(m_target_x, m_target_y, ttx, tty))
            {
                return(false);
            }

            m_target_bot                   = info.bot;
            m_status                       = Status.Pushing;
            m_target_bot.m_target_x        = ttx;
            m_target_bot.m_target_y        = tty;
            m_target_bot.m_animation_state = 0.0f;
            if (arena.GridSafe(ttx, tty))
            {
                m_target_status = Status.Moving;
            }
            else
            {
                m_target_status = Status.Falling;
            }
            if (anim != null)
            {
                anim.speed = 1.0f;
            }
            return(true);
        }

        if (anim != null)
        {
            anim.speed = 1.0f;
        }
        m_status = Status.Moving;
        return(true);
    }