コード例 #1
0
    private bool PlacePlanet(int layer, int slice, int revSpeed, RevolveDirection dir, GameObject planetPrefab)
    {
        GameObject planet     = Instantiate(planetPrefab);
        GridCell   parentCell = GameStateManager.Instance.solarSystemGrid.GetGridCell(layer, slice);

        if (parentCell.Selectable == null)
        {
            planet.transform.position = parentCell.transform.position;

            Planet planetScript = planet.GetComponent <Planet>();
            planetScript.SetParentCell(parentCell);
            planetScript.SetRevolveDirection(dir);
            planetScript.revolveSpeed = revSpeed;
            int numTries = 0;
            do
            {
                planetScript.planetName = ((char)('A' + Random.Range(0, 26))).ToString() + ((char)('A' + Random.Range(0, 26))).ToString() +
                                          "-" +
                                          Random.Range(0, 10) + Random.Range(0, 10) + Random.Range(0, 10) + Random.Range(0, 10);
                numTries++;
            }while (planetNames.Contains(planetScript.planetName) && numTries < 50);
            planetNames.Add(planetScript.planetName);
            planetScript.PopupLabel = planetScript.planetName;
            Instantiate(GameData.Instance.PlanetNamePrefab).GetComponent <PlanetName>().Setup(planetScript);
            planet.transform.SetParent(planetHolder.transform);

            PlanetManager.Instance.AddPlanet(planetScript);
            parentCell.Selectable   = planetScript;
            planetScript.ParentCell = parentCell;

            //The way level generation works, it will automatically subtract 2 from the number of layers
            //because we discard the inner ring (it's the sun) and the outer ring (because you can't move off of the solar system)
            //So a range from 4-8 is actually the same as a range from 2-6
            int systemLayers = Random.Range(4, 8);
            //Must have at least 4 slices. Max is inconsequential.
            int systemSlices = Random.Range(8, 15);

            //TODO:
            //We will either need to find a new way of generating grid placement or cull out grids that aren't the
            //grid in view, because grids are now generating sufficiently close to one another to be seen
            planetScript.gravityWell = CircleGridBuilder.Instance.BuildGrid(systemLayers, systemSlices, new Vector3(layer * 200, 0, slice * 200));

            planetScript.grid = planetScript.gravityWell.transform.Find("Grid").GetComponent <CircularGrid>();
            planetScript.grid.parentPlanet = planetScript;

            GameObject planet2 = Instantiate(planet);
            planet2.transform.SetParent(planetScript.gravityWell.transform);
            planet2.transform.position   = planetScript.gravityWell.transform.position;
            planet2.transform.localScale = new Vector3(4, 4, 4);

            Destroy(planet2.GetComponent <Planet>());
            return(true);
        }
        return(false);
    }
コード例 #2
0
    public GridCell GetGridCellForRevolve(GridCell originCell, RevolveDirection direction, int revolveSpeed)
    {
        int currentSlice = originCell.slice;
        int targetSlice  = -1;

        if (direction == RevolveDirection.CounterClockwise)
        {
            targetSlice = (currentSlice + revolveSpeed) % slices;
        }
        else
        {
            targetSlice = (currentSlice - revolveSpeed + slices) % slices;
        }

        return(gridCells[originCell.layer, targetSlice]);
    }
コード例 #3
0
ファイル: Chip.cs プロジェクト: nusisschad/XNAGameStudio
        /// <summary>
        /// Causes the chip to revolve one half revolution in a specified direction.
        /// </summary>
        /// <param name="direction">Direction to revolve.</param>
        /// <param name="amount">Amount to revolve in radians. Values other than
        /// MathHelpers.Pi or MathHelpers.TwoPi may break other behaviors.</param>
        /// <param name="revolutionDuration">Duration of the animation.</param>
        public void Flip(RevolveDirection direction)
        {
            // Do nothing if we are already revolving
            if (isRevolving)
            {
                return;
            }

            float amount = MathHelper.Pi;

            Audio.Play("Flip Chip");

            // Select a new target rotation
            switch (direction)
            {
            case RevolveDirection.Up:
                if (!horizontalRotationCorrect)
                {
                    amount = -amount;
                }
                targetRevolutionX = currentRevolutionX - amount;
                break;

            case RevolveDirection.Down:
                if (!horizontalRotationCorrect)
                {
                    amount = -amount;
                }
                targetRevolutionX = currentRevolutionX + amount;
                break;

            case RevolveDirection.Left:
                targetRevolutionY = currentRevolutionY - amount;
                break;

            case RevolveDirection.Right:
                targetRevolutionY = currentRevolutionY + amount;
                break;
            }

            // Begin the animation
            this.revolutionDirection   = direction;
            this.revolutionDuration    = FlipDuration;
            this.currentRevolutionTime = 0.0f;
            this.isRevolving           = true;
        }
コード例 #4
0
ファイル: Planet.cs プロジェクト: CharlieDelune/Orbital-Decay
 public void SetRevolveDirection(RevolveDirection direction)
 {
     revolveDirection = direction;
 }
コード例 #5
0
ファイル: Chip.cs プロジェクト: GodLesZ/svn-dump
		public void Flip( RevolveDirection direction ) {
			if( isRevolving )
				return;

			float amount = MathHelper.Pi;

			Audio.Play( "Flip Chip" );

			switch( direction ) {
				case RevolveDirection.Up:
					if( !horizontalRotationCorrect )
						amount = -amount;
					targetRevolutionX = currentRevolutionX - amount;
					break;

				case RevolveDirection.Down:
					if( !horizontalRotationCorrect )
						amount = -amount;
					targetRevolutionX = currentRevolutionX + amount;
					break;

				case RevolveDirection.Left:
					targetRevolutionY = currentRevolutionY - amount;
					break;

				case RevolveDirection.Right:
					targetRevolutionY = currentRevolutionY + amount;
					break;
			}

			this.revolutionDirection = direction;
			this.revolutionDuration = FlipDuration;
			this.currentRevolutionTime = 0.0f;
			this.isRevolving = true;
		}
コード例 #6
0
 public List <Vector3> GetGridVectorsForRevolve(GridCell parentCell, GridCell targetCell, RevolveDirection revolveDirection)
 {
     return(parentCell.parentGrid.GetGridVectorsForRevolve(parentCell.layer, parentCell.slice, targetCell.slice, revolveDirection));
 }
コード例 #7
0
 public GridCell GetGridCellForRevolve(GridCell parentCell, RevolveDirection revolveDirection, int revolveSpeed)
 {
     return(parentCell.parentGrid.GetGridCellForRevolve(parentCell, revolveDirection, revolveSpeed));
 }
コード例 #8
0
    public List <Vector3> GetGridVectorsForRevolve(int layer, int startSlice, int endSlice, RevolveDirection direction)
    {
        List <Vector3> vectors      = new List <Vector3>();
        int            currentSlice = startSlice;

        do
        {
            if (direction == RevolveDirection.CounterClockwise)
            {
                currentSlice = (currentSlice + 1) % slices;
            }
            else
            {
                currentSlice = (currentSlice - 1 + slices) % slices;
            }

            vectors.Add(gridCells[layer, currentSlice].transform.position);
        }while (currentSlice != endSlice);

        return(vectors);
    }