public Map() { level = 0; tiles = new Tile[MAP_ROWS, MAP_COLS]; for (int i = 0; i < MAP_ROWS; ++i) for (int j = 0; j < MAP_COLS; ++j) { tiles[i, j] = new Tile(); tiles[i, j].location = new Rectangle(j * Fired.TILE_SIZE, i * Fired.TILE_SIZE, Fired.TILE_SIZE, Fired.TILE_SIZE); } levelFinished = true; openWindow = false; loseGame = winGame = false; hero = new Hero(0, 0, 3); employees = new List<Employee>(); swat = new List<Swat>(); guard = new List<SecurityGuard>(); boss = new List<Boss>(); sucker = new List<SewageSucker>(); carcass = new List<Carcass>(); stairs = new Rectangle(); window = new Rectangle(2000, 2000, 1, 1); }
//Change to the next level public void LoadNextLevel(ContentManager content) { level++; if (level > 20) return; employees.Clear(); swat.Clear(); guard.Clear(); sucker.Clear(); boss.Clear(); carcass.Clear(); //Make file name and open file string fileName = "Content/level" + level.ToString() + ".txt"; StreamReader sr = new StreamReader(fileName); string [] line; //Get tiles from file for (int i = 0; i < MAP_ROWS; ++i) { //Read a line in and split each character at the space line = sr.ReadLine().Split(' '); for (int j = 0; j < MAP_COLS; ++j) { if (line[j] == "W") { tiles[i, j].type = TileType.Collision; tiles[i, j].imageSource = new Rectangle(Fired.SOURCE_SIZE, 0, Fired.SOURCE_SIZE, Fired.SOURCE_SIZE); } else if (line[j] == ".") { tiles[i, j].type = TileType.Empty; tiles[i, j].imageSource = new Rectangle(0, 0, Fired.SOURCE_SIZE, Fired.SOURCE_SIZE); } else if(line[j] == "U") { tiles[i, j].type = TileType.Up; tiles[i, j].imageSource = new Rectangle(Fired.SOURCE_SIZE * 2, 0, Fired.SOURCE_SIZE, Fired.SOURCE_SIZE); stairs = new Rectangle(j * Fired.TILE_SIZE, i * Fired.TILE_SIZE, Fired.TILE_SIZE, Fired.TILE_SIZE); } else if (line[j] == "B") { tiles[i, j].type = TileType.Collision; tiles[i, j].imageSource = new Rectangle(Fired.SOURCE_SIZE * 3, 0, Fired.SOURCE_SIZE, Fired.SOURCE_SIZE); } else if (line[j] == "[") { tiles[i, j].type = TileType.Collision; tiles[i, j].imageSource = new Rectangle(Fired.SOURCE_SIZE * 4, 0, Fired.SOURCE_SIZE, Fired.SOURCE_SIZE); } else if (line[j] == "=") { tiles[i, j].type = TileType.Collision; tiles[i, j].imageSource = new Rectangle(Fired.SOURCE_SIZE * 5, 0, Fired.SOURCE_SIZE, Fired.SOURCE_SIZE); } else if (line[j] == "]") { tiles[i, j].type = TileType.Collision; tiles[i, j].imageSource = new Rectangle(Fired.SOURCE_SIZE * 6, 0, Fired.SOURCE_SIZE, Fired.SOURCE_SIZE); } else if (line[j] == "+") { tiles[i, j].type = TileType.Collision; tiles[i, j].imageSource = new Rectangle(Fired.SOURCE_SIZE * 7, 0, Fired.SOURCE_SIZE, Fired.SOURCE_SIZE); window = new Rectangle(j * Fired.TILE_SIZE, i * Fired.TILE_SIZE, Fired.TILE_SIZE, Fired.TILE_SIZE + 5); windowLocation = new Vector2(i, j); } } } //Add player sr.ReadLine(); line = sr.ReadLine().Split(' '); hero = new Hero(int.Parse(line[0]), int.Parse(line[1]), int.Parse(line[2])); hero.load(content, playerImage); Random rand = new Random(); int count; //Add employee Employee e; line = sr.ReadLine().Split(' '); count = int.Parse(line[2]); for(int i = 0; i < count; ++i) { line = sr.ReadLine().Split(' '); e = new Employee(int.Parse(line[0]), int.Parse(line[1]), int.Parse(line[2])); if (rand.Next(2) == 1) e.load(content, employeeImage); else e.load(content, employeeImage2); employees.Add(e); } //Add guards SecurityGuard s; line = sr.ReadLine().Split(' '); count = int.Parse(line[2]); for (int i = 0; i < count; ++i) { line = sr.ReadLine().Split(' '); s = new SecurityGuard(int.Parse(line[0]), int.Parse(line[1]), int.Parse(line[2]), int.Parse(line[3]), int.Parse(line[4])); s.load(content, guardImage); guard.Add(s); } //Add swat Swat sw; line = sr.ReadLine().Split(' '); count = int.Parse(line[2]); for (int i = 0; i < count; ++i) { line = sr.ReadLine().Split(' '); sw = new Swat(int.Parse(line[0]), int.Parse(line[1]), int.Parse(line[2])); sw.load(content, swatImage); swat.Add(sw); } //Add boss Boss b; line = sr.ReadLine().Split(' '); count = int.Parse(line[2]); for (int i = 0; i < count; ++i) { line = sr.ReadLine().Split(' '); b = new Boss(int.Parse(line[0]), int.Parse(line[1]), int.Parse(line[2])); b.load(content, bossImage); boss.Add(b); } //Add Sucker SewageSucker su; line = sr.ReadLine().Split(' '); count = int.Parse(line[2]); for (int i = 0; i < count; ++i) { line = sr.ReadLine().Split(' '); su = new SewageSucker(int.Parse(line[0]), int.Parse(line[1])); su.load(content, sewageImage); sucker.Add(su); slurp.Play(); } sr.Close(); }