Example #1
0
    public override Vector2 CheckColCircle(TwoColCircle other)
    {
        if (!CheckColBounds(other))
        {
            return(Vector2.zero);
        }

        Vector2 lineVector = P2 - P1;

        lineVector.Normalize();

        Vector2 toCenter = other.Center - P1;

        Debug.DrawRay(P1, toCenter);

        float projection = Vector2.Dot(toCenter, lineVector);

        Vector2 dist = (P1 + projection * lineVector) - other.Center;

        if (projection > 0.0f && projection < (P2 - P1).magnitude && dist.magnitude < other.Rad)
        {
            return(dist - dist.normalized * other.Rad);
        }

        if ((P1 - other.Center).magnitude < other.Rad)
        {
            return((P1 - other.Center) - (P1 - other.Center).normalized * other.Rad);
        }
        if ((P2 - other.Center).magnitude < other.Rad)
        {
            return((P2 - other.Center) - (P2 - other.Center).normalized * other.Rad);
        }

        return(Vector2.zero);
    }
Example #2
0
    public override Vector2 CheckColCircle(TwoColCircle other)
    {
        if (CheckColBounds(other))
        {
            print("homestar");

            if (other.Center.x > this.BL.x && other.Center.x < this.TR.x)
            {
                if (other.Center.y > this.Center.y)
                {
                    return(new Vector2(0.0f, other.Center.y - other.Rad - this.TR.y));
                }
                if (other.Center.y < this.Center.y)
                {
                    return(new Vector2(0.0f, other.Center.y + other.Rad - this.BL.y));
                }
            }
            if (other.Center.y > this.BL.y && other.Center.y < this.TR.y)
            {
                if (other.Center.x > this.Center.x)
                {
                    return(new Vector2(other.Center.x - other.Rad - this.TR.x, 0.0f));
                }
                if (other.Center.x < this.Center.x)
                {
                    return(new Vector2(other.Center.x + other.Rad - this.BL.x, 0.0f));
                }
            }



            Vector2 dist;
            dist = new Vector2(BL.x, TR.y) - other.Center;
            if (dist.magnitude < other.Rad)
            {
                return(dist.normalized * (other.Rad - dist.magnitude));
            }

            dist = BL - other.Center;
            if (dist.magnitude < other.Rad)
            {
                return(dist.normalized * (other.Rad - dist.magnitude));
            }

            dist = TR - other.Center;
            if (dist.magnitude < other.Rad)
            {
                return(dist.normalized * (other.Rad - dist.magnitude));
            }

            dist = new Vector2(TR.x, BL.y) - other.Center;
            if (dist.magnitude < other.Rad)
            {
                return(dist.normalized * (other.Rad - dist.magnitude));
            }
        }

        return(Vector2.zero);
    }
Example #3
0
    public override Vector2 CheckColCircle(TwoColCircle other)
    {
        if (!CheckColBounds(other))
        {
            return(Vector2.zero);
        }

        Vector2 dist = this.Center - other.Center;

        float distMax = this.rad + other.Rad;

        if (dist.magnitude < distMax)
        {
            return(dist - dist.normalized * distMax);
        }

        return(Vector2.zero);
    }
Example #4
0
 public virtual Vector2 CheckColCircle(TwoColCircle other)
 {
     return(Vector2.zero);
 }
Example #5
0
 // Use this for initialization
 void Awake()
 {
     col     = GetComponents <TwoColLine> ();
     colCirc = GetComponent <TwoColCircle> ();
 }
Example #6
0
    public void OnSceneGUI()
    {
        TwoCol myTarget = (TwoCol)target;

        if (myTarget.GetTypes.Length == 0)
        {
            return;
        }

        if (myTarget.GetTypes.Length > 1)
        {
            Handles.color = UnityEngine.Color.magenta;
        }
        if (myTarget.HasType(TwoCol.ColType.COMBAT_DEF))
        {
            Handles.color = UnityEngine.Color.blue;
        }
        else if (myTarget.HasType(TwoCol.ColType.COMBAT_OFF))
        {
            Handles.color = UnityEngine.Color.red;
        }
        else if (myTarget.HasType(TwoCol.ColType.PHYSICS_DEF))
        {
            Handles.color = UnityEngine.Color.green;
        }
        else if (myTarget.HasType(TwoCol.ColType.PHYSICS_OFF))
        {
            Handles.color = UnityEngine.Color.yellow;
        }
        else if (myTarget.HasType(TwoCol.ColType.T3_DEF))
        {
            Handles.color = UnityEngine.Color.cyan;
        }
        else
        {
            Handles.color = UnityEngine.Color.grey;
        }

        if (myTarget.GetType() == typeof(TwoColCircle))
        {
            TwoColCircle temp = (TwoColCircle)myTarget;

            Handles.DrawWireDisc(temp.Center, UnityEngine.Vector3.forward, temp.Rad);
        }
        else
        if (myTarget.GetType() == typeof(TwoColSquare))
        {
            TwoColSquare temp = (TwoColSquare)myTarget;

            Handles.DrawLine(new UnityEngine.Vector3(temp.BL.x, temp.BL.y, 0.0f), new UnityEngine.Vector3(temp.BL.x, temp.TR.y, 0.0f));
            Handles.DrawLine(new UnityEngine.Vector3(temp.BL.x, temp.BL.y, 0.0f), new UnityEngine.Vector3(temp.TR.x, temp.BL.y, 0.0f));
            Handles.DrawLine(new UnityEngine.Vector3(temp.TR.x, temp.TR.y, 0.0f), new UnityEngine.Vector3(temp.BL.x, temp.TR.y, 0.0f));
            Handles.DrawLine(new UnityEngine.Vector3(temp.TR.x, temp.TR.y, 0.0f), new UnityEngine.Vector3(temp.TR.x, temp.BL.y, 0.0f));
        }
        if (myTarget.GetType() == typeof(TwoColLine))
        {
            TwoColLine temp = (TwoColLine)myTarget;

            Handles.DrawLine(new UnityEngine.Vector3(temp.P1Draw.x, temp.P1Draw.y, 0.0f), new UnityEngine.Vector3(temp.P2Draw.x, temp.P2Draw.y, 0.0f));
        }
    }
Example #7
0
    // Update is called once per frame
    void Update()
    {
        anim.Draw(this.transform.position);

        if (col)
        {
            TwoColCircle colPhys = col;
            TwoColCircle colOff  = col;

            List <TwoColManager.Col> other = colPhys.ColManager.CheckCol(colPhys);

            if (other.Count > 0)
            {
                foreach (TwoColManager.Col e in other)
                {
                    transform.position += (Vector3)e.move;
                }
            }

            List <TwoColManager.Col> other2 = colOff.ColManager.CheckCol(colOff);

            if (other2.Count > 0)
            {
                foreach (TwoColManager.Col e in other2)
                {
                    BatMoth  colMoth  = e.col.GetComponent <BatMoth>();
                    BatEnemy colEnemy = e.col.GetComponent <BatEnemy>();

                    if (colMoth)
                    {
                    }
                    else
                    if (colEnemy)
                    {
                        transform.position = new Vector3(100.0f, 150.0f, 0.0f);
                    }
                }
            }
        }

        if (Input.GetKey("left"))
        {
            xSpeed -= xSpeedAccel - xSpeedAccel * xSpeedAccelChange * weight;
        }
        else if (Input.GetKey("right"))
        {
            xSpeed += xSpeedAccel - xSpeedAccel * xSpeedAccelChange * weight;
        }
        else
        {
            if (Mathf.Abs(xSpeed) > 0.05f)
            {
                xSpeed *= xFriction + (1.0f - xFriction) * xFrictionChange * weight;
            }
            else
            {
                xSpeed = 0.0f;
            }
        }

        if (xSpeed > xSpeedMax || xSpeed < -xSpeedMax)
        {
            xSpeed *= 0.95f;
        }

        if (ySpeed > -ySpeedMax)
        {
            ySpeed -= gravity;
        }

        if (energy > 0.0f && Input.GetKeyDown("up"))
        {
            ySpeed += flapHeight;

            if (Input.GetKey("right"))
            {
                xSpeed -= xSpeedAccel - xSpeedAccel * xSpeedAccelChange * weight * 50.0f;
            }
            else if (Input.GetKey("left"))
            {
                xSpeed += xSpeedAccel - xSpeedAccel * xSpeedAccelChange * weight * 50.0f;
            }

            energy -= 0.05f;
            if (energy < 0.0f)
            {
                energy = 0.0f;
            }

            weight -= 0.025f;
            if (weight < 0.0f)
            {
                weight = 0.0f;
            }

            energyBar.SetValue(energy);
            weightBar.SetValue(weight);

            anim.PlayOnce(0, 4, 0.04f);
        }

        if (Input.GetKey("up"))
        {
            if (ySpeed < -ySpeedGlide)
            {
                ySpeed = -ySpeedGlide;                //(ySpeed + ySpeedGlide)*0.5f;
            }
        }

        if (Time.frameCount % 50 == 0)
        {
            weight -= 0.01f;
            weightBar.SetValue(weight);
        }

        ySpeed = Mathf.Clamp(ySpeed, -ySpeedMax, ySpeedMax);

        transform.position += new Vector3(xSpeed, ySpeed, 0.0f);
    }
Example #8
0
 // Use this for initialization
 void Awake()
 {
     col = GetComponent <TwoColCircle> ();
 }