public bool IsAdjSpaceFree(AdjDirection dir) { Vector2 d = CalcDirection(dir, flipped); Collider2D col = Physics2D.OverlapPoint(d + (Vector2)transform.position, Physics2D.AllLayers); return(col == null); }
/// <summary> /// Add an adjacent room in a direction not already occupied /// </summary> /// <param name="type"></param> /// <returns></returns> public Section addAdjRoom(out AdjDirection dir, Archetype type = Archetype.normal) { while (getAdjRoom(dir = getRandomDirection()) != null) { } return(addAdjRoom(dir, type)); }
/// <summary> /// Make a connection between this section and another. Also makes diagonal connections where valid. /// </summary> /// <param name="index">The direction relative to this section the connection is being made</param> /// <param name="room">The section being connected to</param> /// <param name="reverseConnections">Make connections from the other section to this section</param> public void setAdjRoom(AdjDirection index, Section room, bool reverseConnections = true) { AdjDirection diagDir; Section diag; float r = Random.value, chance = 1f; //outgoing connections adjSections[(int)index] = room; diag = room.adjSections[(int)offsetDirection(index, 2)]; if (diag != null && r < chance) { //outgoing and incoming diagonal connection diagDir = offsetDirection(index, 1); adjSections[(int)diagDir] = diag; diag.adjSections[(int)offsetDirection(diagDir, 4)] = this; } diag = room.adjSections[(int)offsetDirection(index, -2)]; if (diag != null && r < chance) { //outgoing and incoming diagonal connection diagDir = offsetDirection(index, -1); adjSections[(int)diagDir] = diag; diag.adjSections[(int)offsetDirection(diagDir, 4)] = this; } //incoming connections if (reverseConnections) { room.setAdjRoom(offsetDirection(index, 4), this, false); } }
/// <summary> /// Add an adjacent room in the specified direction /// </summary> /// <param name="dir"></param> /// <param name="type"></param> /// <returns></returns> public Section AddAdjRoom(AdjDirection dir, Archetype type = Archetype.normal) { Vector2 direction = CalcDirection(dir, flipped); Section adj = Create((Vector2)transform.position + direction, !flipped, type); SetAdjRoom(dir, adj); return(adj); }
/// <summary> /// Add an adjacent room in the specified direction /// </summary> /// <param name="dir"></param> /// <param name="type"></param> /// <returns></returns> public Section addAdjRoom(AdjDirection dir, Archetype type = Archetype.normal) { Vector2 direction = getDirection(dir); Section adj = create((Vector2)transform.position + direction, type); setAdjRoom(dir, adj); return(adj); }
public static AdjDirection CalcOffsetDirection(AdjDirection dir, int amount) { int max = System.Enum.GetNames(typeof(AdjDirection)).Length; while (amount < 0) { amount += max; } return((AdjDirection)(((int)dir + amount) % max)); }
public static Vector2 getDirection(AdjDirection dir) { int offset = (int)dir; float segments = System.Enum.GetNames(typeof(AdjDirection)).Length; float angle = (offset / segments) * 360f; Vector2 direction = Quaternion.Euler(0f, 0f, angle) * Vector2.right; direction.Scale(Generator.getInstance().getSectionScale()); return(direction); }
/// <summary> /// Make a connection between this section and another. Also makes diagonal connections where valid. /// </summary> /// <param name="index">The direction relative to this section the connection is being made</param> /// <param name="room">The section being connected to</param> /// <param name="reverseConnections">Make connections from the other section to this section</param> public void SetAdjRoom(AdjDirection index, Section room, bool reverseConnections = true) { // if (room.flipped == flipped) // throw new System.InvalidOperationException ("Cannot connect two sections with the same flipped state!\n" + this.name + ", " + room.name); adjSections[(int)index] = room; if (reverseConnections) { SetAdjRoom(index, this, false); } }
public static Vector2 CalcDirection(AdjDirection dir, bool flipped) { int offset = (int)dir; float segments = System.Enum.GetNames(typeof(AdjDirection)).Length; float angle = (offset / segments) * 360f; if (flipped) { angle = (angle + 180f) % 360f; } angle = (angle + 90f) % 360f; Vector2 direction = Quaternion.Euler(0f, 0f, angle) * Vector2.right; direction.Scale(Generator.GetInstance().GetSectionScale() / 2f); return(direction); }
public Section GetAdjRoom(AdjDirection index) { return(adjSections[(int)index]); }