private void AddRect(RectHolder <T> rectHolder) { if (IsRectFree(rectHolder.Rect)) { mRects.Add(rectHolder); mPixelsUsedPercentage += rectHolder.Rect.Width * rectHolder.Rect.Height / (double)(mContainerSize.Width * mContainerSize.Height); } else { throw new AgateException("Attempted to add a rectangle which was not free."); } }
/// <summary> /// Compares two RectHolder objects for sorting purposes. /// </summary> /// <param name="other"></param> /// <returns></returns> public int CompareTo(RectHolder <T> other) { int a1 = Math.Max(Rect.Width, Rect.Height); int a2 = Math.Min(Rect.Width, Rect.Height); int b1 = Math.Max(other.Rect.Width, other.Rect.Height); int b2 = Math.Min(other.Rect.Width, other.Rect.Height); // return values are reversed, because we want largest first. if (a1 < b1) { return(1); } else if (a1 > b1) { return(-1); } if (a2 < b2) { return(1); } else if (a2 > b2) { return(-1); } // ok, max and min dimensions are the same. // make tall rectangles go before short ones. if (Rect.Height < other.Rect.Height) { return(1); } else if (Rect.Height > other.Rect.Height) { return(-1); } else { return(0); } }
private void InitRects(int canvasWidth, int canvasHeight) { Transform rectTrans = GameObject.Find("Rectangles").transform; rectTrans.localPosition = new Vector3((float)-(canvasWidth / 2), (float)(canvasHeight / 2), 0f); int count = 0; for (int y = 0; y < rows; y++) { for (int x = 0; x < columns; x++) { int rdm = Random.Range(0, colors.Count); GameObject rect = InstantiateImage(rectImg, rectTrans, "Rect" + (count + 1), new Vector3(0f, 0f, 0f), scaleVector, colors [rdm]); rectColors [count] = colors [rdm]; dots.Add(new Dot(colors [rdm], dotImg, horDotPerRect * vertDotPerRect)); colors.RemoveAt(rdm); rectangles [y, x] = new RectHolder(rect.GetComponent <Image> ()); count++; HandleRectPosition(rect.GetComponent <RectTransform> (), canvasWidth, canvasHeight, x, y); } } }
override protected BehaviorTreeResults Tick() { BattleTech.Designed.EncounterBoundaryChunkGameLogic boundaryChunk = unit.Combat.EncounterLayerData.encounterBoundaryChunk; if (boundaryChunk.IsInEncounterBounds(unit.CurrentPosition)) { return(new BehaviorTreeResults(BehaviorNodeState.Success)); } // find closest center float bestDist = float.MaxValue; Vector3 destination = Vector3.zero; if (boundaryChunk.encounterBoundaryRectList.Count == 0) { return(new BehaviorTreeResults(BehaviorNodeState.Failure)); } for (int i = 0; i < boundaryChunk.encounterBoundaryRectList.Count; ++i) { RectHolder rh = boundaryChunk.encounterBoundaryRectList[i]; Vector3 c = rh.rect.center; float dist = (unit.CurrentPosition - c).magnitude; if (dist < bestDist) { bestDist = dist; destination = c; } } if ((destination - unit.CurrentPosition).magnitude < 1) { // already close (should probably have been caught, above) return(new BehaviorTreeResults(BehaviorNodeState.Success)); } unit.Pathing.UpdateAIPath(destination, destination, MoveType.Sprinting); Vector3 destinationThisTurn = unit.Pathing.ResultDestination; float movementBudget = unit.Pathing.MaxCost; PathNodeGrid grid = unit.Pathing.CurrentGrid; Vector3 successorPoint = destination; if ((grid.GetValidPathNodeAt(destinationThisTurn, movementBudget) == null) || ((destinationThisTurn - destination).magnitude > 1.0f)) { // can't get all the way to the destination. if (unit.Combat.EncounterLayerData.inclineMeshData != null) { List <AbstractActor> lanceUnits = AIUtil.GetLanceUnits(unit.Combat, unit.LanceId); List <Vector3> path = DynamicLongRangePathfinder.GetDynamicPathToDestination(destinationThisTurn, movementBudget, unit, true, lanceUnits, unit.Pathing.CurrentGrid, 100.0f); if ((path != null) && (path.Count > 0)) { destinationThisTurn = path[path.Count - 1]; } } } Vector3 cur = unit.CurrentPosition; AIUtil.LogAI(string.Format("issuing order from [{0} {1} {2}] to [{3} {4} {5}] looking at [{6} {7} {8}]", cur.x, cur.y, cur.z, destinationThisTurn.x, destinationThisTurn.y, destinationThisTurn.z, successorPoint.x, successorPoint.y, successorPoint.z )); BehaviorTreeResults results = new BehaviorTreeResults(BehaviorNodeState.Success); MovementOrderInfo mvtOrderInfo = new MovementOrderInfo(destinationThisTurn, successorPoint); mvtOrderInfo.IsSprinting = true; results.orderInfo = mvtOrderInfo; results.debugOrderString = string.Format("{0}: dest:{1} sprint:{2}", this.name, destination, mvtOrderInfo.IsSprinting); return(results); }
public void checkDotPosition(GameObject dot1, GameObject dot2) { float x1 = dot1.transform.localPosition.x; float y1 = dot1.transform.localPosition.y; float x2 = dot2.transform.localPosition.x; float y2 = dot2.transform.localPosition.y; int row1 = (int)(-y1 / yToAvoid); int col1 = (int)(x1 / xToAvoid); int row2 = (int)(-y2 / yToAvoid); int col2 = (int)(x2 / xToAvoid); RectHolder holder1 = rectangles [row1, col1]; RectHolder holder2 = rectangles [row2, col2]; //if the cats are not swapped inside the same rectangle if (holder1.rec.color != holder2.rec.color) { if (holder1.rec.color == dot1.GetComponent <Image> ().color) { holder1.count++; setDots++; } else if (holder2.rec.color == dot1.GetComponent <Image> ().color) { holder2.count--; setDots--; } if (holder2.rec.color == dot2.GetComponent <Image> ().color) { holder2.count++; setDots++; } else if (holder1.rec.color == dot2.GetComponent <Image> ().color) { holder1.count--; setDots--; } } swaps++; GameObject.Find("Score").GetComponent <Text> ().text = "Score: " + setDots + "/" + totalDotCount + " "; GameObject.Find("Swaps").GetComponent <Text> ().text = " Swaps: " + swaps; if (setDots == totalDotCount) { finalText.GetComponent <Text> ().text = winString; handleFinalText(); GameManager.instance.endMatch(GameManager.WIN); } if (holder1.count == horDotPerRect * vertDotPerRect && !holder1.complete) { Debug.Log("Holder1 reached max!"); //the rectangle expands for 1 second when completed StartCoroutine(ExpandRect(holder1.rec, row1, col1)); holder1.complete = true; GameManager.instance.addBonusTime(); } if (holder2.count == horDotPerRect * vertDotPerRect && !holder2.complete) { Debug.Log("Holder2 reached max!"); //the rectangle expands for 1 second when completed StartCoroutine(ExpandRect(holder2.rec, row2, col2)); holder2.complete = true; GameManager.instance.addBonusTime(); } }