/// <summary> /// Get opposite face /// </summary> public static EFace GetOppositeFace(EFace currentFace) { switch (currentFace) { case EFace.front: return(EFace.back); case EFace.right: return(EFace.left); case EFace.back: return(EFace.front); case EFace.left: return(EFace.right); case EFace.up: return(EFace.down); case EFace.down: return(EFace.up); default: return(EFace.front); } }
/// <summary> /// Rotate vector based on face /// </summary> public static Vector3 RotateTowardsFace(Vector3 current, EFace face) { switch (face) { case EFace.front: return(current); case EFace.right: return(new Vector3(-current.z, current.y, current.x)); case EFace.back: return(new Vector3(-current.x, current.y, -current.z)); case EFace.left: return(new Vector3(current.z, current.y, -current.x)); case EFace.up: return(new Vector3(current.x, -current.z, current.y)); case EFace.down: return(new Vector3(current.x, current.z, -current.y)); } return(current); }
/// <summary> /// Get random face, but ignoring previous in queue /// </summary> public static EFace GetRandomFace(Queue <EFace> facesQueue, int numberOfPreviousFacesToIgnore) { //check every possible face List <EFace> faces = new List <EFace>(); for (int i = 0; i < System.Enum.GetNames(typeof(EFace)).Length; i++) { //if not inside facesQueue, add to list EFace tryingFace = (EFace)i; if (facesQueue.Contains(tryingFace) == false) { faces.Add(tryingFace); } } //select random face in list EFace selectedFace = faces[Random.Range(0, faces.Count)]; //add to queue facesQueue.Enqueue(selectedFace); //clamp list of faces to ignore if (facesQueue.Count > numberOfPreviousFacesToIgnore) { facesQueue.Dequeue(); } return(selectedFace); }
void Explosion() { //end game if (endGame) { GameManager.instance.levelManager.EndGame(false); } //destroy every cell on this face if (destroyEveryCellOnFace) { EFace face = cellOwner.coordinates.face; //foreach cell on this face foreach (Cell cell in GameManager.instance.world.Cells.Values) { if (cell.coordinates.face == face) { //kill cell (can't end game) cell.KillCell(false); } } } //destroy self Destroy(gameObject); }
void RotateRightLeftColumn(EFace startFace, bool toUp) { //foreach coordinate, use x to select foreach (Coordinates coordinates in coordinatesToRotate) { int x = coordinates.x; //right face. Left face is the inverse if (startFace == EFace.right) { SelectRightLeftColumnCells(x); } else { SelectRightLeftColumnCells(WorldMath.InverseN(x, world.worldConfig.NumberCells)); } } //in the left is inverse if (startFace == EFace.left) { toUp = !toUp; } //rotate animation if (world.gameObject.activeInHierarchy) { rotatingWorld_Coroutine = world.StartCoroutine(AnimationRotate(Vector3.forward, toUp)); } //update dictionary UpdateDictionaryRightLeftColumn(toUp); }
public Vector3 PivotBasedOnFace(EFace face) { float HalfCell = CellsSize / 2; switch (face) { case EFace.front: return(new Vector3(HalfCell, HalfCell, 0)); case EFace.right: return(new Vector3(0, HalfCell, HalfCell)); case EFace.back: return(new Vector3(HalfCell, HalfCell, 0)); case EFace.left: return(new Vector3(0, HalfCell, HalfCell)); case EFace.up: return(new Vector3(HalfCell, 0, HalfCell)); case EFace.down: return(new Vector3(HalfCell, 0, HalfCell)); } return(Vector3.zero); }
IEnumerator RandomizeWorld() { //wait before randomize yield return(new WaitForSeconds(world.randomWorldConfig.TimeBeforeRandomize)); //for n times, rotate row or column for (int i = 0; i < world.randomWorldConfig.RandomizeTimes; i++) { //randomize rotation EFace face = (EFace)Random.Range(0, 6); int x = Random.Range(0, world.worldConfig.NumberCells); int y = Random.Range(0, world.worldConfig.NumberCells); ERotateDirection randomDirection = (ERotateDirection)Random.Range(0, 4); //effective rotation Rotate(new Coordinates(face, x, y), EFace.front, randomDirection, world.randomWorldConfig.RotationTime); //wait until the end of the rotation OnStartRotation(); yield return(new WaitWhile(() => waitRotation)); //if not last rotation, wait time between every rotation yield return(new WaitForSeconds(world.randomWorldConfig.TimeBetweenRotation)); //repeat if (world.randomWorldConfig.Loop) { i = 0; } } //call start game GameManager.instance.levelManager.StartGame(); }
void RotateUpDownRow(EFace startFace, bool toRight) { //foreach coordinate, use y to select foreach (Coordinates coordinates in coordinatesToRotate) { int y = coordinates.y; //rotate y. Down face is the inverse if (startFace == EFace.up) { SelectUpDownRowCells(y); } else { SelectUpDownRowCells(WorldMath.InverseN(y, world.worldConfig.NumberCells)); } } //in the down face is inverse if (startFace == EFace.down) { toRight = !toRight; } //rotate animation if (world.gameObject.activeInHierarchy) { rotatingWorld_Coroutine = world.StartCoroutine(AnimationRotate(Vector3.forward, !toRight)); } //update dictionary UpdateDictionaryUpDownRow(toRight); }
public void Rotate(Coordinates coordinates, EFace lookingFace, ERotateDirection rotateDirection, float rotationTime) { //start rotation (can NOT skip) Rotate(new RotationStruct(new Coordinates[1] { coordinates }, lookingFace, rotateDirection, rotationTime, false)); }
void SelectFrontColumnCells(int x) { //select x in every front face for (int faceIndex = 0; faceIndex < 4; faceIndex++) { //set f equal to faceIndex, but instead of right and left, use up and down EFace face = (EFace)faceIndex; if ((EFace)faceIndex == EFace.right) { face = EFace.up; } if ((EFace)faceIndex == EFace.left) { face = EFace.down; } for (int y = 0; y < world.worldConfig.NumberCells; y++) { //line is equal to x //but when is face back is the inverse of the other faces, so column 0 is 2, column 1 is 1, column 2 is 0 int line = face != EFace.back ? x : WorldMath.InverseN(x, world.worldConfig.NumberCells); SelectCell(new Coordinates(face, line, y)); } } //select all face right or left SelectAllFace(x, EFace.left, EFace.right); }
void SetPositions(EFace face, List <Turret> turrets) { if (line.ContainsKey(face)) { //if line is destroyed, remove key and recreate line if (line[face] == null) { line.Remove(face); CreateLine(turrets); } //get position of every turret List <Vector3> positions = new List <Vector3>(); foreach (Turret t in turrets) { positions.Add(t.GetComponent <TurretGraphics>().linePosition.position); } //add first as last one too, to close the lines if (GameManager.instance.levelManager.levelConfig.CloseLineFeedback) { positions.Add(positions[0]); } //set positions line[face].positionCount = positions.Count; line[face].SetPositions(positions.ToArray()); } }
public RotationStruct(Coordinates[] coordinates, EFace lookingFace, ERotateDirection rotateDirection, float rotationTime, bool canSkipAnimation) { this.coordinates = coordinates; this.lookingFace = lookingFace; this.rotateDirection = rotateDirection; this.rotationTime = rotationTime; this.canSkipAnimation = canSkipAnimation; }
public CmdTargetAppear(int targetId, bool isBlush, EFace face, ECostume costume, EPosition pos) : base(Command.Type.TargetAppear) { _targetId = targetId; _isBlush = isBlush; _face = face; _costume = costume; _position = pos; }
public void PlayerRotate(Coordinates[] coordinates, EFace lookingFace, ERotateDirection rotateDirection, float rotationTime) { //do nothing if is running a rotation not skippable (enemy rotation) if (rotatingWorld_Coroutine != null && rotationsToDo.Peek().canSkipAnimation == false) { return; } //else start rotation (can skip) Rotate(new RotationStruct(coordinates, lookingFace, rotateDirection, rotationTime, true)); }
void SelectAllFaceCells(EFace face) { //add cell and coordinates for every row and column on this face for (int x = 0; x < world.worldConfig.NumberCells; x++) { for (int y = 0; y < world.worldConfig.NumberCells; y++) { SelectCell(new Coordinates(face, x, y)); } } }
void CheckChangedFace() { //if change face, reselect center cell and move selector EFace face = WorldUtility.SelectFace(transform); if (face != coordinates.face) { coordinates = new Coordinates(face, GameManager.instance.world.worldConfig.CenterCell); GameManager.instance.uiManager.ShowSelector(coordinates); } }
private CardFace(EFace index, string name, int pointAllTrump, int pointNoTrump, int pointOneTrump, int pointIsNotTrump) { Index = index; Name = name; PointAllTrump = pointAllTrump; PointNoTrump = pointNoTrump; PointOneTrump = pointOneTrump; PointIsNotTrump = pointIsNotTrump; CardFacesMapping[index] = this; }
void CreateLine(List <Turret> turrets) { EFace face = turret.CellOwner.coordinates.face; //instantiate line prefab if null if (line.ContainsKey(face) == false) { line.Add(face, Instantiate(linePrefab)); } //set positions and active SetPositions(face, turrets); line[face].gameObject.SetActive(true); }
Coordinates GetNewCoordinates(EFace newFace) { //get cells in new face List <Cell> possibleCells = GameManager.instance.world.GetEveryCellInFace(newFace); //removes coordinates where there are already enemies if (checkNoHitEnemies) { WorldUtility.CheckOverlap(transform.position, coordinatesToAttack.position, possibleCells); } //return random return(possibleCells[Random.Range(0, possibleCells.Count)].coordinates); }
IEnumerator Wave_Coroutine() { //current wave WaveStruct wave = waveConfig.Waves[CurrentWave]; //foreach enemy in this wave, instantiate but deactivate foreach (Enemy enemy in wave.Enemies) { InstantiateNewEnemy(enemy); yield return(null); } //enemies copy(copy because when enemy is killed, it's removed from list) List <Enemy> enemiesCopy = enemies.CreateCopy(); //queue to not spawn on same face Queue <EFace> facesQueue = new Queue <EFace>(); //for every enemy foreach (Enemy enemy in enemiesCopy) { //randomize coordinates to attack EFace face = WorldUtility.GetRandomFace(facesQueue, waveConfig.Waves[CurrentWave].IgnorePreviousFacesAtSpawn); int x = Random.Range(0, GameManager.instance.world.worldConfig.NumberCells); int y = Random.Range(0, GameManager.instance.world.worldConfig.NumberCells); Coordinates coordinatesToAttack = new Coordinates(face, x, y); //get position and rotation Vector3 position; Quaternion rotation; GameManager.instance.world.GetPositionAndRotation(coordinatesToAttack, waveConfig.Waves[CurrentWave].DistanceFromWorld, out position, out rotation); //set enemy position and rotation, then activate enemy.transform.position = position; enemy.transform.rotation = rotation; //instantiate portal at position and rotation if (GameManager.instance.levelManager.generalConfig.PortalPrefab) { Instantiate(GameManager.instance.levelManager.generalConfig.PortalPrefab, position, rotation); } //set enemy destination and activate enemy.Init(coordinatesToAttack); //wait for next enemy yield return(new WaitForSeconds(wave.TimeBetweenSpawns)); } }
/// <summary> /// Get every cell in this face /// </summary> public List <Cell> GetEveryCellInFace(EFace face) { //get cells in new face List <Cell> possibleCells = new List <Cell>(); foreach (Coordinates coordinates in Cells.Keys) { if (coordinates.face == face) { possibleCells.Add(GameManager.instance.world.Cells[coordinates]); } } return(possibleCells); }
public void DestroyLine(EFace face) { if (line.ContainsKey(face)) { //if line is destroyed, remove key if (line[face] == null) { line.Remove(face); return; } //deactive line line[face].gameObject.SetActive(false); } }
/// <summary> /// Enemy rotate cube /// </summary> public void RotateByEnemy(int numberRotations, float rotationTime) { //for n times, rotate row or column for (int i = 0; i < numberRotations; i++) { //randomize rotation EFace face = (EFace)Random.Range(0, 6); int x = Random.Range(0, worldConfig.NumberCells); int y = Random.Range(0, worldConfig.NumberCells); ERotateDirection randomDirection = (ERotateDirection)Random.Range(0, 4); //effective rotation worldRotator.Rotate(new Coordinates(face, x, y), EFace.front, randomDirection, rotationTime); } }
void OnTurretExitQueue(EFace face) { //don't check if is not active (is only a preview) or is rotating if (IsActive == false || isRotating) { return; } //if a turret quit from this face queue if (face == CellOwner.coordinates.face) { //try activate the shield TryActivateShield(); } }
void SelectUpDownRowCells(int y) { //select y in up, right, down, left face for (int faceIndex = 0; faceIndex < 4; faceIndex++) { //set f equal to faceIndex, but instead of front and back, use up and down EFace face = (EFace)faceIndex; if ((EFace)faceIndex == EFace.front) { face = EFace.up; } if ((EFace)faceIndex == EFace.back) { face = EFace.down; } for (int x = 0; x < world.worldConfig.NumberCells; x++) { switch (face) { case EFace.up: //up select the row SelectCell(new Coordinates(face, x, y)); break; case EFace.down: //down select the row but inverse of up SelectCell(new Coordinates(face, x, WorldMath.InverseN(y, world.worldConfig.NumberCells))); break; case EFace.right: //right select the column instead of row SelectCell(new Coordinates(face, y, x)); break; case EFace.left: //left select the column instead of row //but if you are rotating the first row, this is the last column, if you are rotating the last row, this is the first column SelectCell(new Coordinates(face, WorldMath.InverseN(y, world.worldConfig.NumberCells), x)); break; } } } //select all face front or back SelectAllFace(y, EFace.front, EFace.back); }
/// <summary> /// Face up, right, down, left /// </summary> public static EFace FindFaceUpToRight(EFace startFace, bool toRight) { switch (startFace) { case EFace.up: if (toRight) { return(EFace.right); } else { return(EFace.left); } case EFace.right: if (toRight) { return(EFace.down); } else { return(EFace.up); } case EFace.down: if (toRight) { return(EFace.left); } else { return(EFace.right); } case EFace.left: if (toRight) { return(EFace.up); } else { return(EFace.down); } } return(startFace); }
/// <summary> /// Face front, up, back, down /// </summary> public static EFace FindFaceFrontToUp(EFace startFace, bool toUp) { switch (startFace) { case EFace.front: if (toUp) { return(EFace.up); } else { return(EFace.down); } case EFace.up: if (toUp) { return(EFace.back); } else { return(EFace.front); } case EFace.back: if (toUp) { return(EFace.down); } else { return(EFace.up); } case EFace.down: if (toUp) { return(EFace.front); } else { return(EFace.back); } } return(startFace); }
void SelectRightLeftColumnCells(int x) { //select line in up, right, down, left face for (int faceIndex = 0; faceIndex < 4; faceIndex++) { //set f equal to faceIndex, but instead of front and back, use up and down EFace face = (EFace)faceIndex; if ((EFace)faceIndex == EFace.front) { face = EFace.up; } if ((EFace)faceIndex == EFace.back) { face = EFace.down; } for (int y = 0; y < world.worldConfig.NumberCells; y++) { switch (face) { case EFace.right: //select column SelectCell(new Coordinates(face, x, y)); break; case EFace.left: //left select the column, but inverse (when select 0 is the last, when select last is the 0) SelectCell(new Coordinates(face, WorldMath.InverseN(x, world.worldConfig.NumberCells), y)); break; case EFace.up: //up select the row instead of column SelectCell(new Coordinates(face, y, x)); break; case EFace.down: //down is inverse of up SelectCell(new Coordinates(face, y, WorldMath.InverseN(x, world.worldConfig.NumberCells))); break; } } } //select all face front or back SelectAllFace(x, EFace.front, EFace.back); }
Cell InstantiateCellBasedOnFace(EFace face) { //create biome based on face switch (face) { #if UNITY_EDITOR case EFace.front: return(UnityEditor.PrefabUtility.InstantiatePrefab(biomesConfig.Front) as Cell); case EFace.right: return(UnityEditor.PrefabUtility.InstantiatePrefab(biomesConfig.Right) as Cell); case EFace.back: return(UnityEditor.PrefabUtility.InstantiatePrefab(biomesConfig.Back) as Cell); case EFace.left: return(UnityEditor.PrefabUtility.InstantiatePrefab(biomesConfig.Left) as Cell); case EFace.up: return(UnityEditor.PrefabUtility.InstantiatePrefab(biomesConfig.Up) as Cell); case EFace.down: return(UnityEditor.PrefabUtility.InstantiatePrefab(biomesConfig.Down) as Cell); #else case EFace.front: return(Instantiate(biomesConfig.Front)); case EFace.right: return(Instantiate(biomesConfig.Right)); case EFace.back: return(Instantiate(biomesConfig.Back)); case EFace.left: return(Instantiate(biomesConfig.Left)); case EFace.up: return(Instantiate(biomesConfig.Up)); case EFace.down: return(Instantiate(biomesConfig.Down)); #endif } return(null); }
void SelectAllFace(int line, EFace face1, EFace face2) { //select all face 1 or all face 2 if (line <= 0 || line >= world.worldConfig.NumberCells - 1) { if (world.worldConfig.NumberCells > 1) { EFace face = line <= 0 ? face1 : face2; SelectAllFaceCells(face); } else { //if only one cell, then select both faces SelectAllFaceCells(face1); SelectAllFaceCells(face2); } } }