Ejemplo n.º 1
0
    private IEnumerator LerpToInside(GameObject a_player)
    {
        var moveController = a_player.gameObject.GetComponentInChildren <MoveController>();

        if (moveController != null)
        {
            moveController.Stop();
        }

        var roomSideVec    = (Vector2)a_player.transform.position - Rect.center;
        var enterDirection = Facing.VectorToDirectionCardinal(roomSideVec);

        var offset         = Mathf.Max(0, m_wallSize);
        var spriteRenderer = a_player.GetComponentInChildren <SpriteRenderer>();

        if (spriteRenderer != null)
        {
            if (Facing.IsVertical(enterDirection))
            {
                offset += a_player.transform.localScale.y * (spriteRenderer.drawMode == SpriteDrawMode.Simple ? 1.0f : spriteRenderer.size.y / 2.0f);
            }
            else
            {
                offset += a_player.transform.localScale.x * (spriteRenderer.drawMode == SpriteDrawMode.Simple ? 1.0f : spriteRenderer.size.x / 2.0f);
            }
        }

        var x = a_player.transform.position.x;
        var y = a_player.transform.position.y;

        switch (enterDirection)
        {
        // the direction they're coming from
        case Facing.Direction.East: x = Right - offset; break;

        case Facing.Direction.North: y = Top - offset; break;

        case Facing.Direction.South: y = Bottom + offset; break;

        case Facing.Direction.West: x = Left + offset; break;
        }

        var startPos    = a_player.transform.position;
        var targetPos   = new Vector2(x, y);
        var timeElapsed = 0.0f;

        while (timeElapsed < RoomManager.instance.TransitionTime)
        {
            var t = timeElapsed / RoomManager.instance.TransitionTime;
            a_player.transform.position = Vector3.Lerp(startPos, targetPos, t);
            timeElapsed += Time.deltaTime;
            yield return(null);
        }
    }
Ejemplo n.º 2
0
    public void Split()
    {
        if (!Facing.IsCardinal(Direction))
        {
            Debug.LogWarningFormat("Cannot split a wall in direction {0}.", Direction);
            return;
        }

        var wallMin = this;

        var collider = GetComponent <BoxCollider2D>();
        var size     = collider.size;
        var shift    = 0.0f;

        size.x        = size.x / 2.0f;
        shift         = size.x / 2.0f;
        collider.size = size;

        var renderer = GetComponent <SpriteRenderer>();

        if (renderer != null)
        {
            renderer.size = size;
        }

        var wallMax = Instantiate(wallMin);

        wallMax.transform.parent   = transform.parent;
        wallMax.transform.position = wallMin.transform.position;

        var baseName = name;

        if (Facing.IsVertical(Direction))
        {
            wallMin.name = baseName + " (West)";
            wallMin.transform.position += Vector3.left * shift;

            wallMax.name = baseName + " (East)";
            wallMax.transform.position += Vector3.right * shift;
        }
        else
        {
            wallMin.name = baseName + " (South)";
            wallMin.transform.position += Vector3.down * shift;

            wallMax.name = baseName + " (North)";
            wallMax.transform.position += Vector3.up * shift;
        }
    }
    private void UpdateAnimation()
    {
        m_prevFacing = m_facing.CurDirection;

        var directionString = m_facing.CurDirection.ToString();

        // if we're sticking to cardinal and not N or S, use horizontal component
        if (!m_useIntercardinal && !Facing.IsVertical(m_facing.CurDirection))
        {
            directionString = Facing.GetHorizontal(m_facing.CurDirection).ToString();
        }

        m_animator.SetAnimation(directionString);
        m_animator.IsPaused = !m_mover.IsMoving;
    }
Ejemplo n.º 4
0
    public Vector2 GetWallCenter(Facing.Direction a_direction, bool a_relative = false)
    {
        var   offset      = -Facing.DirectionToVector(a_direction) * WallSize / 2.0f;
        float attachPoint = 0.0f;

        switch (a_direction)
        {
        case Facing.Direction.East: attachPoint = Right - (a_relative ? transform.position.x : 0.0f); break;

        case Facing.Direction.North: attachPoint = Top - (a_relative ? transform.position.y : 0.0f); break;

        case Facing.Direction.South: attachPoint = Bottom - (a_relative ? transform.position.y : 0.0f); break;

        case Facing.Direction.West: attachPoint = Left - (a_relative ? transform.position.x : 0.0f); break;
        }
        if (!Facing.IsVertical(a_direction))
        {
            return(new Vector2(attachPoint + offset.x, 0.0f));
        }
        return(new Vector2(0.0f, attachPoint + offset.y));
    }
    private void Awake()
    {
        var length = Facing.IsVertical(m_scrollDirection) ? m_sprite.bounds.size.y * m_size.y
            : m_sprite.bounds.size.x * m_size.x;
        var step = length / 2.0f - m_overlapUnits;

        for (int count = 0; count < m_segmentCount; ++count)
        {
            var segment = new GameObject();

            var pos = transform.position - (Vector3)MoveVector.normalized * count * step;
            segment.transform.parent   = transform;
            segment.transform.position = pos;

            var sr = segment.AddComponent <SpriteRenderer>();
            sr.sprite           = m_sprite;
            sr.color            = m_color;
            sr.sortingOrder     = m_sortingOrder;
            sr.sortingLayerName = m_sortingLayerName;
            sr.drawMode         = m_drawMode;
            if (m_drawMode != SpriteDrawMode.Simple)
            {
                sr.size = m_size;
            }

            var iss = segment.AddComponent <InfiniteScrollSegment>();
            iss.SegmentCount    = m_segmentCount;
            iss.OverlapUnits    = m_overlapUnits;
            iss.ScrollDirection = m_scrollDirection;
            iss.SegmentSize     = step;

            m_segmentList.Add(segment);
        }

        m_body = gameObject.AddComponent <Rigidbody2D>();
        m_body.gravityScale = 0.0f;
    }