// Note: There is a more efficient way of doing this. public bool CanCollide(TwoCol other) { if (this.HasType(ColType.COMBAT_DEF) && other.HasType(ColType.COMBAT_OFF)) { return(true); } if (this.HasType(ColType.PHYSICS_DEF) && other.HasType(ColType.PHYSICS_OFF)) { return(true); } if (this.HasType(ColType.T1_DEF) && other.HasType(ColType.T1_OFF)) { return(true); } if (this.HasType(ColType.T2_DEF) && other.HasType(ColType.T2_OFF)) { return(true); } if (this.HasType(ColType.T3_DEF) && other.HasType(ColType.T3_OFF)) { return(true); } return(false); }
public List <Col> CheckCol(TwoCol other) { List <Col> output = new List <Col>(); foreach (TwoCol e in twoCol) { if (e == other || !e.CanCollide(other)) { continue; } Col col = new Col(); Vector2 vec = other.CheckCol(e); if (vec != Vector2.zero) { col.col = e; col.move = vec; output.Add(col); } } // No collisions. return(output); }
// Use this for initialization void Awake() { TwoCol[] temp = GetComponents <TwoCol> (); foreach (TwoCol e in temp) { if (e.HasType(TwoCol.ColType.PHYSICS_OFF)) { tCol = e; break; } } tCommon = GetComponent <TwoCommon> (); }
void Update() { if (tCols.Length > 0) { foreach (TwoCol e in tCols) { TwoCol col = e.ColManager.IsCol(e, TwoCol.ColType.COMBAT_DEF); if (col) { col.GetComponent <PlatHero>().Die(); } } } }
public Vector2 CheckColMove(TwoCol other, TwoCol.ColType type) { Vector2 output = Vector2.zero; foreach (TwoCol e in twoCol) { if (e == other || !e.HasType(type) || !e.CanCollide(other)) { continue; } output += other.CheckCol(e); } // No collisions. return(output); }
public TwoCol IsCol(TwoCol other, TwoCol.ColType type) { foreach (TwoCol e in twoCol) { if (e == other || !e.HasType(type) || !e.CanCollide(other)) { continue; } if (other.CheckCol(e) != Vector2.zero) { return(e); } } // No collisions. return(null); }
protected bool CheckColBounds(TwoCol other) { if (BL.x > other.TR.x) { return(false); } if (TR.x < other.BL.x) { return(false); } if (BL.y > other.TR.y) { return(false); } if (TR.y < other.BL.y) { return(false); } return(true); }
public Vector2 CheckCol(TwoCol other) { if (other.GetType() == typeof(TwoColCircle)) { return(this.CheckColCircle((TwoColCircle)other)); } else if (other.GetType() == typeof(TwoColSquare)) { return(this.CheckColSquare((TwoColSquare)other)); } else if (other.GetType() == typeof(TwoColSquarePlat)) { return(this.CheckColSquare((TwoColSquarePlat)other)); } else if (other.GetType() == typeof(TwoColLine)) { return(this.CheckColLine((TwoColLine)other)); } return(Vector2.zero); }
// Update is called once per frame void Update() { anim.Draw(this.transform.position); TwoCol colC = colCirc.ColManager.IsCol(colCirc, TwoCol.ColType.COMBAT_DEF); if (colC) { BatHero hero = colC.GetComponent <BatHero>(); if (hero) { hero.EatMoth(); Die(); return; } } //boop. // Note to self: Rethink the way the hitboxes were handles by the bat (maybe make the MOTHS the ones that collide with it. // Seems more efficient. // // Also, instead of the random the moths currently have, maybe limit the rotation between two angles (so that the moths always go from one end of the screen to the other). //rot += 1.0f; /*if (rot >= 256.0f) * { * rot -= 256.0f; * } * if (rot < 0.0f) * { * rot += 256.0f; * }*/ if (col.Length > 0) { Vector2 wiskR = new Vector2(Mathf.Cos(Mathf.Deg2Rad * (rot - 40.0f)) * 20.0f, Mathf.Sin(Mathf.Deg2Rad * (rot - 40.0f)) * 20.0f); Vector2 wiskL = new Vector2(Mathf.Cos(Mathf.Deg2Rad * (rot + 40.0f)) * 20.0f, Mathf.Sin(Mathf.Deg2Rad * (rot + 40.0f)) * 20.0f); Vector2 wiskM = new Vector2(Mathf.Cos(Mathf.Deg2Rad * (rot)) * 15.0f, Mathf.Sin(Mathf.Deg2Rad * (rot)) * 15.0f); col[0].P2 = wiskR; col[1].P2 = wiskL; col[2].P2 = wiskM; Vector2 leftMove = Vector2.zero, rightMove = Vector2.zero, midMove = Vector2.zero; foreach (TwoColManager.Col e in col[0].ColManager.CheckCol(col[0])) { rightMove += e.move; } foreach (TwoColManager.Col e in col[1].ColManager.CheckCol(col[1])) { leftMove += e.move; } foreach (TwoColManager.Col e in col[2].ColManager.CheckCol(col[2])) { midMove += e.move; } if (midMove == Vector2.zero) { deadEndTurn = 0; } if (deadEndTurn == 0) { deadEndTurn = Random.Range(0, 2); deadEndTurn = -1 + deadEndTurn * 2; } rot += midMove.magnitude * 2.0f * (float)deadEndTurn; rot -= leftMove.magnitude * 0.2f; rot += rightMove.magnitude * 0.2f; rotWander += Random.Range(-0.1f, 0.1f); Mathf.Clamp(rotWander, -0.25f, 0.25f); rot += rotWander; } this.transform.position += new Vector3(Mathf.Cos(Mathf.Deg2Rad * (rot)) * Time.deltaTime * 16.0f, Mathf.Sin(Mathf.Deg2Rad * (rot)) * Time.deltaTime * 16.0f, 0.0f); }
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)); } }
public void RemoveCol(TwoCol pass) { twoCol.Remove(pass); }
public void AddCol(TwoCol pass) { twoCol.Add(pass); }