public Level(string filename) { try { StreamReader fileIn = new StreamReader(filename); LevelWidth = int.Parse(fileIn.ReadLine()); LevelHeight = int.Parse(fileIn.ReadLine()); BlockGrid = new IBlock[LevelWidth, LevelHeight]; for(int i = Utility.ZERO; i < LevelHeight; ++i) { string[] nextLine = fileIn.ReadLine().Split(Utility.LEVEL_LOADER_DELIMITER); for (int j = Utility.ZERO; j < LevelWidth; ++j) { if (nextLine[j].Length > Utility.ZERO) { BlockGrid[j, i] = CharToBlock(nextLine[j][Utility.ZERO], j, i); } else { BlockGrid[j, i] = new NullBlock(); } } } foreach (IBlock b in BlockGrid) { SprintFourGame.GetInstance().Components.Add(b); } } catch (IOException e) { Console.WriteLine(Utility.LEVEL_LOAD_ERROR + filename); Console.WriteLine(e.ToString()); BlockGrid = new IBlock[Utility.ONE, Utility.ONE]; } }
public virtual void GenerateColumn(int column) { if (column > Utility.ChunkLength - Utility.HOLE_MAX_LENGTH) canGenerateHole = false; if (generateHole) { currentHoleLength++; if (currentHoleLength > currentHoleGoalLength) generateHole = false; } if (generateBricks) { currentBrickLength++; if (currentBrickLength > currentBrickGoalLength) generateBricks = false; } //Decides if it should generate a hole if (!generateBricks && !generateHole && canGenerateHole && r.Next(Utility.RANDOM_VALUE_MAX) < holeDensity) { generateHole = true; canGenerateHole = false; currentHoleLength = 1; currentHoleGoalLength = r.Next(Utility.HOLE_MIN_LENGTH, Utility.HOLE_MAX_LENGTH); } if (!generateHole && !generateBricks && canGenerateBricks && r.Next(Utility.RANDOM_VALUE_MAX) < brickDensity) { generateBricks = true; canGenerateBricks = false; currentBrickLength = 1; currentBrickGoalLength = r.Next(bricksMin, bricksMax); currentBrickHeight = r.Next(chunk.ChunkYValue - bricksHeightMax, chunk.ChunkYValue - bricksHeightMin); } for (int y = Utility.ZERO; y < Utility.WorldHeight; y++) { Vector2 pos = new Vector2(column * Utility.BLOCK_POSITION_SCALE + chunk.Start.X, y * Utility.BLOCK_POSITION_SCALE); IBlock b = new NullBlock(); if (generateHole) { //b = new NullBlock(); } else { if (!canGenerateHole) canGenerateHole = true; if (generateBricks) { if (y == currentBrickHeight) { b = Chunk.GetRandomBrickBlock(pos, r); //Spawns an enemy if (r.Next(Utility.RANDOM_VALUE_MAX) < enemySpawnDensity) { Chunk.SpawnRandomEnemy(new Vector2(column * Utility.BLOCK_POSITION_SCALE + chunk.Start.X, y * Utility.BLOCK_POSITION_SCALE), r); } } } else canGenerateBricks = true; if (y == Utility.KILL_BLOCK_HEIGHT) b = new Block(new KillBlockState(), pos); else GenerateGroundBlocks(ref b, y, pos); } chunk.Blocks[column, y] = b; SprintFourGame.GetInstance().Components.Add(b); } //Spawns an enemy if (r.Next(Utility.RANDOM_VALUE_MAX) < enemySpawnDensity) { Chunk.SpawnRandomEnemy(new Vector2(column * Utility.BLOCK_POSITION_SCALE + chunk.Start.X, chunk.ChunkYValue * Utility.BLOCK_POSITION_SCALE), r); } }