public Slime Split(Vector3Int splitLocation) { if (!CanSplit()) { throw new CannotSplitException(); } // decrease Scale and move the slime SetScale(Scale - 1); Vector3Int offset = splitLocation - TileLocation; offset.Clamp(Vector3Int.zero, new Vector3Int(1, 1, 0)); // create the new slime GameObject newSlimeObject = Instantiate(SlimePrefab, tilemap.CellToWorld(TileLocation + offset), Quaternion.Euler(0, 0, 0)); Slime newSlime = newSlimeObject.GetComponent <Slime>(); newSlime.Init(); newSlime.SetScale(Scale); EventSystem.Current.FireEvent(new SlimeSplitContext(this, newSlime)); // move slimes MoveInstant(TileLocation + offset); newSlime.Move(splitLocation); return(newSlime); }
public void PlaceTiles(int selectedBuildingID)// [Dragable Tiles] { Vector3 difference = new Vector3(); Vector3Int tilePosition = new Vector3Int(); Quaternion Lookrotation = new Quaternion(); Vector3Int LookDirection = Vector3Int.FloorToInt(tempStartPos - tempEndPos); Lookrotation = Quaternion.LookRotation(LookDirection); float count = Vector3.Distance(tempStartPos, tempEndPos); difference = tempStartPos - tempEndPos; if (count > 0) { for (int i = 0; i <= count; i++) { tilePosition = Vector3Int.FloorToInt(tempStartPos - (difference / count) * i); Vector3Int myBuildingGridPos = new Vector3Int(tilePosition.x + ((size / 2)), MapMaker.activefloor, tilePosition.z + ((size / 2))); myBuildingGridPos.Clamp(new Vector3Int(1, 1, 1), new Vector3Int(size - 2, size - 2, size - 2));//Clamp for empty outer ring SetTileData(myBuilding.myData[myBuildingGridPos.x, myBuildingGridPos.y, myBuildingGridPos.z], Lookrotation, selectedBuildingID); } } //Debug.Log("StartPos: " + tempStartPos + " EndPos: " + tempEndPos + "LookRotation: " + LookDirection); tempStartPos = Vector3Int.zero; tempEndPos = Vector3Int.zero; }
protected override void UpdateObject() { if (atDestination) { int movingSlimeWidth = slimeController.CurrentSlime.Scale + 1; Vector3 peepeepoopoo = slimeController.CurrentSlime.Destination - slimeController.CurrentSlime.transform.position; Vector3Int movingSlimeTile = tilemap.WorldToCell(slimeController.CurrentSlime.transform.position + Vector3.up * (peepeepoopoo.y < 0 ? 0.499f : 0.001f)); Vector3Int movingSlimeDirection = slimeController.CurrentSlime.TileLocation - movingSlimeTile; movingSlimeDirection.Clamp(new Vector3Int(-1, -1, 0), new Vector3Int(1, 1, 0)); if (movingSlimeDirection.sqrMagnitude > 0) { HashSet <Vector3Int> movingSlimeOccupiedTiles = new HashSet <Vector3Int>(); for (int h = 0; h < movingSlimeWidth; h++) { for (int k = 0; k < movingSlimeWidth; k++) { movingSlimeOccupiedTiles.Add(movingSlimeTile + new Vector3Int(h, k, 0)); } } Vector3Int[] directions = { new Vector3Int(1, 0, 0), new Vector3Int(-1, 0, 0), new Vector3Int(0, 1, 0), new Vector3Int(0, -1, 0) }; bool done = false; foreach (Vector3Int direction in directions) { Vector3Int perpendicular = direction.x == 0 ? directions[0] : directions[2]; for (int i = 0; i < scale + 1; i++) { Vector3Int testPos = TileLocation + direction * (direction.x > 0 || direction.y > 0 ? scale + 1 : 1) + perpendicular * i; if (movingSlimeOccupiedTiles.Contains(testPos) && movingSlimeDirection == -direction) { Move(TileLocation + (slimeController.CurrentSlime.TileLocation - movingSlimeTile)); done = true; break; } } if (done) { break; } } } } }
void Update() { if (mode == "disabled") { return; } Vector3 pos = Camera.main.ScreenToWorldPoint(Input.mousePosition); Vector3Int coordinate = grid.WorldToCell(pos); coordinate.Clamp(minCoordinate, maxCoordinate); cursorLayer.ClearAllTiles(); cursorLayer.SetTile(coordinate, cursorTile); }
/// <summary> /// Modifies the density value at the specified point, and notifies the <c>Chunk</c> /// that its points have been updated. /// </summary> /// <param name="point"></param> /// <param name="value"></param> public void ModifyChunkAtPoint(Vector3Int point, Vector2 value) { point.Clamp(Vector3Int.zero, Vector3Int.one * chunkSize); if (modifiedPoints.ContainsKey(point)) { modifiedPoints[point] = value; } else { modifiedPoints.Add(point, value); } points[point.z * chunkSize * chunkSize + point.y * chunkSize + point.x] = value; pointsHaveBeenModified = true; NotifyPointsUpdate(); }
void OnMouseDown() { Vector3 pos = Camera.main.ScreenToWorldPoint(Input.mousePosition); Vector3Int coordinate = grid.WorldToCell(pos); coordinate.Clamp(minCoordinate, maxCoordinate); if (mode == "place") { controller.PlaceShip(coordinate); } else if (mode == "attack") { // outside code thinks coordinates are 0, 0 based controller.TakeTurn(coordinate - new Vector3Int(0, size, 0)); } }
public Vector3Int GetNearestTileInBounds(Vector3Int origin, Vector3Int offset) { Vector3Int nearest = origin; int max = Mathf.Max(Mathf.Abs(offset.x), Mathf.Abs(offset.y)); Vector3Int dir = offset; dir.Clamp(Vector3Int.one * -1, Vector3Int.one); for (int i = max; i >= 0; i--) { var v = dir * i; if (IsPositionInBounds(origin + v) && !MapInfo.CollisionMap.HasTile(origin + v)) { nearest = origin + v; break; } } return(nearest); }
private void Update() { if (!myIsEnded) { if (Input.GetMouseButton(0)) { //Avrundar spelarens input till integers myInputCoordinates.x = Mathf.RoundToInt(GetClickCoordinates().x); myInputCoordinates.z = Mathf.RoundToInt(GetClickCoordinates().z); myInputCoordinates.Clamp(new Vector3Int(0, 0, 0), new Vector3Int(WorldController.Instance.GetWorldWidth - 1, 0, WorldController.Instance.GetWorldDepth - 1)); //Kollar om en tile är upptagen if (WorldController.Instance.GetTileAtPosition(myInputCoordinates.x, myInputCoordinates.z).GetSetTileState == Tile.TileState.empty) { PlacementLogic(); } } //else //{ // if (Input.GetMouseButton(0)) // { // //Avrundar spelarens input till integers // myInputCoordinates.x = Mathf.RoundToInt(GetClickCoordinates().x); // myInputCoordinates.z = Mathf.RoundToInt(GetClickCoordinates().z); // myInputCoordinates.Clamp(new Vector3Int(0, 0, 0), new Vector3Int(10, 0, 10)); // //Kollar om en tile är upptagen // //if (WorldController.Instance.GetTileAtPosition(myInputCoordinates.x, myInputCoordinates.z).GetSetTileState == Tile.TileState.road) // //{ // // AudioManager.ourInstance.PlayEffect(AudioManager.EEffects.REMOVE); // // myBuildManager.ResetTilesPositionRemoval(); // // myPathManager.DeleteTile(myInputCoordinates); // // //Sätter tilen till empty // // //Reset:ar tile-objektet // //} // } //} } }
static void RemoveDuplicates(List <Vector3Int> path, Vector3Int v) { if (path.Count >= 2) { Vector3Int last = path[path.Count - 1]; Vector3Int secondLast = path[path.Count - 2]; Vector3Int dir1 = last - secondLast; dir1.Clamp(Vector3Int.one * -1, Vector3Int.one); Vector3Int dir2 = v - last; dir2.Clamp(Vector3Int.one * -1, Vector3Int.one); if (dir1 == dir2) { path.RemoveAt(path.Count - 1); } } }
override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { currChaseTime += Time.deltaTime; currUpdateTime += Time.deltaTime; if (currChaseTime > ghost.ChaseTime && !Game.IsNearLevelEnd()) { animator.SetBool("is_scattering", true); } else { if (ghost.HasStopped || currUpdateTime > updateTargetPosTime) { currUpdateTime = 0f; Vector3Int playerCellPos = tilemap.WorldToCell(player.transform.position); Vector3Int ghostCellPos = tilemap.WorldToCell(ghost.transform.position); Vector3Int dir = playerCellPos - ghostCellPos; dir.Clamp(Vector3Int.one * -1, Vector3Int.one); if (pathfinding.GetTileDistance(ghostCellPos, playerCellPos) <= 4 && dir != player.MoveDir) { ghost.MoveTo(playerCellPos); } else { /* * According to the reference article for Ghost AI: * To locate Inky (cyan) target: * 1 - Select the position two tiles in front of Pac-Man in his * current direction of travel. * 2 - Create a vector from Blinky position to this tile, and * then double the length of the vector. * 3 - The ending position of the vector (starting from Blinky) * is Inky's target. */ Vector3Int redGhostCellPos = tilemap.WorldToCell(GhostsManager.instance.RedGhost.transform.position); Vector3Int vectorEnd = playerCellPos + player.MoveDir * 2; Vector3Int vec = (vectorEnd - redGhostCellPos) * 2; ghost.MoveTo(pathfinding.GetNearestTileInBounds(redGhostCellPos, vec)); } } } }
public void PlaceSingleTile(int selectedBuildingID)//[Single Tiles] { Vector3Int tilePosition = new Vector3Int(); Quaternion Lookrotation = new Quaternion(); Vector3Int LookDirection = Vector3Int.FloorToInt(tempStartPos - tempEndPos); LookDirection = new Vector3Int(LookDirection.x, 0, LookDirection.z); Lookrotation = Quaternion.LookRotation(LookDirection); tilePosition = Vector3Int.FloorToInt(tempStartPos); Vector3Int myBuildingGridPos = new Vector3Int(tilePosition.x + ((size / 2)), MapMaker.activefloor, tilePosition.z + ((size / 2))); myBuildingGridPos.Clamp(new Vector3Int(1, 1, 1), new Vector3Int(size - 2, size - 2, size - 2));//Clamp for empty outer ring SetTileData(myBuilding.myData[myBuildingGridPos.x, myBuildingGridPos.y, myBuildingGridPos.z], Lookrotation, selectedBuildingID); Debug.Log("StartPos: " + tempStartPos + " EndPos: " + tempEndPos + "LookRotation: " + Lookrotation + "Direction: " + LookDirection); tempStartPos = Vector3Int.zero; tempEndPos = Vector3Int.zero; }
public int GetPriority(Vector3Int playerChunkPosition, Vector3Int playerDirection) { Vector3Int playerToChunk = new Vector3Int(cx, cy, cz) - playerChunkPosition; if (playerToChunk.x == 0 && (playerToChunk.y == 0 || playerToChunk.y == -1) && playerToChunk.z == 0) { return(0); } Vector3Int chunkDirection = playerToChunk; chunkDirection.Clamp(new Vector3Int(-1, -1, -1), new Vector3Int(1, 1, 1)); int a = (int)playerToChunk.magnitude; if (a > 1) { a += 5; } a += chunkDirection.x == playerDirection.x ? 0 : 2; a += chunkDirection.y == playerDirection.y ? 0 : 2; a += chunkDirection.z == playerDirection.z ? 0 : 2; return(a); }
public static void ClampDirection(this Vector3Int v) { v.Clamp(Vector3Int.one * -1, Vector3Int.one); }
/// <summary> /// Returns the density value at a given point. /// </summary> /// <param name="point"></param> /// <returns></returns> public Vector2 GetValueAtPoint(Vector3Int point) { point.Clamp(Vector3Int.zero, Vector3Int.one * chunkSize); return(points[point.z * voxelsPerChunkSqr + point.y * chunkSize + point.x]); }
public static Vector3Int Normalize(Vector3Int v) { v.Clamp(Vector3Int.one * -1, Vector3Int.one); return(v); }