public Level(Game game, SpriteBatch spriteBatch) : base(game) { // TODO: Construct any child components here textures = new Dictionary<String, Texture2D>(); levelx = 0; this.spriteBatch = spriteBatch; layers = new Layer[3]; layers[0] = new Layer(Game.Content, "Backgrounds/Layer0", 0.2f); layers[1] = new Layer(Game.Content, "Backgrounds/Layer1", 0.5f); layers[2] = new Layer(Game.Content, "Backgrounds/Layer2", 0.8f); waypoints = new Dictionary<String, Waypoint>(); vehicle = null; boss = null; // tileLayers = new TileLayer[3]; // tileLayers.load(levelx); }
/// <summary> /// Load the current level from the text file /// </summary> /// <param name="reader">The level file stream (after width and height have been read in)</param> private void loadLevel(StreamReader reader) { int currentTile = 0; currentTile = reader.Read(); bool swap = true; int x = 0; int y = 0; player = new Player(Game, new Vector2(x * 60, y * 40), this); while (!reader.EndOfStream) { switch (currentTile) { case 'w': // waypoint tiles[x][y] = new Tile(new Vector2(x * 60.0f, y * 40), Tile.TileType.Waypoint, 0.0f); break; case 'p': // player tile. Spawn the player here tiles[x][y] = new Tile(new Vector2(x * 60, y * 40), Tile.TileType.Player, 0.0f); spawn = new Point(x, y); break; case 'P': // platform tiles[x][y] = new Tile(new Vector2(x * 60.0f, y * 40), Tile.TileType.Platform, 0.0f); break; case 'W': tiles[x][y] = new Tile(textures["sewerWall"], new Vector2(x * 60.0f, y * 40), Tile.TileType.SewerWall, 0.0f); break; case 'S': tiles[x][y] = new Tile(textures["sewerInterior"], new Vector2(x * 60.0f, y * 40), Tile.TileType.SewerInterior, 0.0f); break; case 'V': tiles[x][y] = new Tile(new Vector2(x * 60.0f, y * 40.0f), Tile.TileType.Waypoint, 0.0f); waypoints.Add("spinner", new Waypoint(Waypoint.WaypointType.Spinner, player, new Vector2(x * 60, y * 40), 0.0f)); vehicle = new Vehicle(Game, player, Vehicle.VehicleType.Spinner, new Vector2(x * 60, y * 40), this); vehicleSpawn = new Point(x, y); break; case '.': // air tiles[x][y] = new Tile(new Vector2(x * 60.0f, y * 40), Tile.TileType.Air, 0.0f); break; case 'x': // road // swap between the two different textures if (swap) tiles[x][y] = new Tile(textures["road0"], new Vector2(x * 60.0f, y * 40), Tile.TileType.Road, 0.0f); else tiles[x][y] = new Tile(textures["road1"], new Vector2(x * 60.0f, y * 40), Tile.TileType.Road, 0.0f); break; case 'X': tiles[x][y] = new Tile(new Vector2(x * 60.0f, y * 40), Tile.TileType.Waypoint, 0.0f); waypoints.Add("X", new Waypoint(Waypoint.WaypointType.EndRide, vehicle, new Vector2(x * 60, y * 40), 0.0f)); break; case 'c': tiles[x][y] = new Tile(textures["concrete"], new Vector2(x * 60.0f, y * 40), Tile.TileType.Concrete, 0.0f); break; case 's': tiles[x][y] = new Tile(new Vector2(x * 60.0f, y * 40), Tile.TileType.Waypoint, 0.0f); waypoints.Add("s", new Waypoint(Waypoint.WaypointType.SavePoint, this, new Vector2(x * 60, y * 40), 0.0f)); break; case 'e': tiles[x][y] = new Tile(new Vector2(x * 60.0f, y * 40), Tile.TileType.Waypoint, 0.0f); waypoints.Add("e", new Waypoint(Waypoint.WaypointType.EndLevel, this, new Vector2(x * 60, y * 40), 0.0f)); break; case 'E': tiles[x][y] = new Tile(new Vector2(x * 60, y * 40), Tile.TileType.Boss, 0.0f); boss = new Boss(Game, x * 60, y * 40, this); break; case 'B': tiles[x][y] = new Tile(textures["buildingInterior"], new Vector2(x * 60.0f, y * 40), Tile.TileType.BuildingInterior, 0.0f); break; case 'b': tiles[x][y] = new Tile(textures["buildingWall"], new Vector2(x * 60.0f, y * 40), Tile.TileType.BuildingWall, 0.0f); break; case '-': tiles[x][y] = new Tile(textures["buildingPlatform"], new Vector2(x * 60.0f, y * 40), Tile.TileType.Platform, 0.0f); break; case '|': tiles[x][y] = new Tile(textures["ladder"], new Vector2(x * 60.0f, y * 40), Tile.TileType.Ladder, 0.0f); break; case 'l': tiles[x][y] = new Tile(textures["powerline"], new Vector2(x * 60.0f, y * 40.0f), Tile.TileType.Powerline, 0.0f); break; case 'L': tiles[x][y] = new Tile(textures["buildingInterior"], new Vector2(x * 60.0f, y * 40.0f), Tile.TileType.Waypoint, 0.0f); vehicle = new Vehicle(Game, player, Vehicle.VehicleType.Lift, new Vector2(x * 60, (y + 1) * 40), this); waypoints.Add("lift", new Waypoint(Waypoint.WaypointType.Lift, player, new Vector2(x * 60, y * 40), 0.0f)); if (waypoints["X"] != null) waypoints["X"].handler = vehicle; vehicleSpawn = new Point(x, y); break; case '\n': // newline or EOF, reset the x value and increment the y value y++; x = -1; break; default: // carriage return, reset the x-value once more x = -1; break; } x++; swap = !swap; currentTile = reader.Read(); } player.resetRectangle(spawn); }
/// <summary> /// Load the next level /// </summary> public void nextLevel() { levelx++; vehicle = null; LoadContent(); }