//Spawns gems in a vertical or horizontal line private void SpawnGemsInLine(SpawnGemState gemState, uint numberOfGems) { //Position the line of gems will start Vector2 startPosition = Vector2.Zero; //Amount of horizontal spacing between gems float horizontalSpacing = (viewport.Width - leftWall.Width * 2) / (numberOfGems + 1); //Amount of vertical spacing between gems float verticalSpacing = 20; //Chooses how the gems will be spawned switch (gemState) { case SpawnGemState.VerticalLeft: startPosition = new Vector2(player.marginLeft, player.Position.Y - player.marginVertical - player.verticalOffset); break; case SpawnGemState.VerticalRight: startPosition = new Vector2(player.marginRight, player.Position.Y - player.marginVertical - player.verticalOffset); break; case SpawnGemState.Horizontal: startPosition = new Vector2(leftWall.Width + horizontalSpacing, player.Position.Y - player.marginVertical - player.verticalOffset); break; } //Delay the next spawn time if we are spawning in a vertical line if (gemState == SpawnGemState.VerticalLeft || gemState == SpawnGemState.VerticalRight) { float delayNextSpawnTime = ((verticalSpacing + animationStore["Gem"].FrameHeight) / player.runSpeed) * 1000 * numberOfGems; previousSpawnTime -= delayNextSpawnTime; } //Initialize gems based on the gem spawn state for (int i = 0; i < numberOfGems; i++) { Gem gem = null; if (gemState == SpawnGemState.VerticalLeft || gemState == SpawnGemState.VerticalRight) { gem = new Gem(ScreenManager.Game, new Animation(animationStore["Gem"]), startPosition - new Vector2(0, (animationStore["Gem"].FrameHeight + verticalSpacing) * i), player); } else if (gemState == SpawnGemState.Horizontal) { //Space gems out evenly gem = new Gem(ScreenManager.Game, new Animation(animationStore["Gem"]), startPosition + new Vector2(horizontalSpacing * i, 0), player); } //Add gem to list gems.Add(gem); } }
private void SpawnGemLines(int numberOfLines, int numberOfGemsPerLine) { //Amount of horizontal spacing between gems float horizontalSpacing = (viewport.Width - leftWall.Width * 2) / (numberOfGemsPerLine + 1); //Amount of vertical spacing between gems float verticalSpacing = 80; float delayNextSpawnTime = ((verticalSpacing + animationStore["Gem"].FrameHeight) / player.runSpeed) * 1000 * numberOfLines; previousSpawnTime -= delayNextSpawnTime; Vector2 startPosition = new Vector2(leftWall.Width + horizontalSpacing, player.Position.Y - player.marginVertical - player.verticalOffset); //Initialize gems based on the gem spawn state for (int i = 0; i < numberOfLines; i++) { for (int j = 0; j < numberOfGemsPerLine; j++) { Gem gem = null; //Space gems out evenly gem = new Gem(ScreenManager.Game, new Animation(animationStore["Gem"]), startPosition + new Vector2(horizontalSpacing * j, -(verticalSpacing * i)), player); //Add gem to list gems.Add(gem); } } }