コード例 #1
0
    /// <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);
        }
    }
コード例 #2
0
    /// <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);
    }
コード例 #3
0
    /// <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);
    }
コード例 #4
0
    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);
    }
コード例 #5
0
    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);
    }
コード例 #6
0
    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);
    }
コード例 #7
0
    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();
    }
コード例 #8
0
    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);
    }
コード例 #9
0
 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));
 }
コード例 #10
0
    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);
    }
コード例 #11
0
    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());
        }
    }
コード例 #12
0
 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;
 }
コード例 #13
0
 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;
 }
コード例 #14
0
    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));
    }
コード例 #15
0
 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));
         }
     }
 }
コード例 #16
0
    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);
        }
    }
コード例 #17
0
 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;
 }
コード例 #18
0
    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);
    }
コード例 #19
0
    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);
    }
コード例 #20
0
    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));
        }
    }
コード例 #21
0
ファイル: World.cs プロジェクト: redd096/CubeInvaders-2.0
    /// <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);
    }
コード例 #22
0
    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);
        }
    }
コード例 #23
0
ファイル: World.cs プロジェクト: redd096/CubeInvaders-2.0
    /// <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);
        }
    }
コード例 #24
0
    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();
        }
    }
コード例 #25
0
    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);
    }
コード例 #26
0
    /// <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);
    }
コード例 #27
0
    /// <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);
    }
コード例 #28
0
    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);
    }
コード例 #29
0
ファイル: World.cs プロジェクト: redd096/CubeInvaders-2.0
    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);
    }
コード例 #30
0
 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);
         }
     }
 }