Ejemplo n.º 1
0
    public virtual void UpdateRectAndCheckForCollisions(UnityMover m)
    {
        m.entity.rect = new Rect(m.entity.position, m.entity.rect.size);

        CheckForBlockCollisions(m);

        m.entity.rect = new Rect(m.entity.position, m.entity.rect.size);
    }
Ejemplo n.º 2
0
    public virtual void UpdatePosition(UnityMover m)
    {
        m.entity.position = new Vector3(
            m.entity.position.x + (m.mover.speed * Time.deltaTime),
            m.entity.position.y + (m.mover.yMoveDir * Time.deltaTime),
            0);

        m.transform.position = m.entity.position;
    }
Ejemplo n.º 3
0
    protected virtual void CheckForBlockCollisions(UnityMover m)
    {
        UnityBlock b   = null;
        Vector2    vec = Vector2.zero;

        float dst = 10; //initialize this to an unimportant value

        m.mover.unitTouchCount  = 0;
        m.mover.blockTouchCount = 0;
        foreach (UnityBlockChunk chunk in m.unityBlockChunksCurrentlyIn)
        {
            foreach (UnityBlock uBlock in chunk.unityBlocks)
            {
                if (Utility.Intersectcs(m.entity.rect, uBlock.block.rect) && m.gameObject.activeSelf)
                {
                    Vector2 newVec = m.entity.position - uBlock.block.position;

                    float newDst = newVec.magnitude;

                    if (newDst < dst)
                    {
                        vec = newVec;
                        dst = newDst;
                        b   = uBlock;
                    }

                    m.mover.unitTouchCount++;
                    m.mover.blockTouchCount++;
                }
            }
        }

        if (m.mover.blockTouchCount > 0)
        {
            float minAngle = Utility.MinDropAngle(m.entity.rect, b.block.rect);

            minAngle = 90 - minAngle;

            float angle = Vector2.Angle(vec, Vector2.up);

            if (angle < minAngle)
            {
                m.HitTop(b);
            }
            else if (angle >= minAngle && angle <= 180 - minAngle)
            {
                m.HitSide(b, vec.x);
            }
            else
            {
                m.HitBottom(b);
            }

            Debug.DrawRay(b.block.rect.position, vec);
        }
    }
Ejemplo n.º 4
0
    void InitializeAllEntities()
    {
        foreach (UnityEntity entity in unityEntities)
        {
            //If its a mover cast it so it can initialize those components
            if (entity is UnityMover)
            {
                UnityMover mover = (UnityMover)entity;
                mover.Initialize(manager.chunks, manager.entities, unityChunks, unityEntities);
            }

            else
            {
                entity.Initialize();
            }
        }
        manager.player.Initialize(manager.goal);
    }
Ejemplo n.º 5
0
    public virtual void CheckForCollisionWithOtherEntities(UnityMover m)
    {
        Vector2 vec = Vector2.zero;
        float   dst = 10;

        foreach (UnityEntity e in m.unityEntities)
        {
            if (m != e && e.gameObject.activeSelf)
            {
                if (Utility.Intersectcs(m.entity.rect, e.entity.rect))
                {
                    Vector2 newVec = m.entity.position - e.entity.position;

                    float newDst = newVec.magnitude;

                    if (newDst < dst)
                    {
                        vec = newVec;
                        dst = newDst;
                    }

                    float minAngle = Utility.MinDropAngle(m.entity.rect, e.entity.rect);

                    minAngle = 90 - minAngle;

                    float angle = Vector2.Angle(vec, Vector2.up);

                    if (angle < minAngle + 5)
                    {
                        m.HitTop(e);
                    }
                    else if (angle >= minAngle - 5 && angle <= 180 - minAngle)
                    {
                        m.HitSide(e, vec.x);
                    }
                    else
                    {
                        m.HitBottom(e);
                    }
                }
            }
        }
    }
Ejemplo n.º 6
0
    public virtual void CheckForChunksCurrentlyIn(UnityMover m)
    {
        m.unityBlockChunksCurrentlyIn.Clear();

        foreach (UnityBlockChunk c in m.unityChunks)
        {
            if (Utility.Intersectcs(m.entity.rect, c.chunk.rect))
            {
                m.unityBlockChunksCurrentlyIn.Add(c);

                //Adds neighboring chunks into collision check. Maybe this can be used for something

                /*int index;
                 * index = m.unityChunks.IndexOf(c);
                 *
                 * if(m.unityChunks.IndexOf(c) != m.unityChunks.Count - 1)
                 *  m.unityBlockChunksCurrentlyIn.Add(m.unityChunks[index + 1]);
                 *
                 * if(m.unityChunks.IndexOf(c) != 0)
                 *  m.unityBlockChunksCurrentlyIn.Add(m.unityChunks[index - 1]);*/
            }
        }
    }