public Mortimer(Vector2 loc, Game tempGame, PowerupManager powerupManager) : base(50, 50, 20) { this.loc = loc; color = Color.White; rect = new Rectangle((int)loc.X, (int)loc.Y, 50, 50); sourceRect = new Rectangle(0, 0, 31, 31); //bullets bullets = new List <Projectiles.Bullet>(); bulletDirection = (float)Math.PI / 2; oldPad = GamePad.GetState(PlayerIndex.One); //direction direction = 0; //powerup stuff game = tempGame; //powerbar healthBar = new Bar(game, new Vector2(0, 0), 250, 25, health, health, Color.Green); this.powerupManager = powerupManager; //double[,] locs = new double[,] { { 100, 100 }, { 500, 100 }, { 600, 100 }, { -50, 50 }, { -40, 200 } }; //string[] types = new string[] { "white", "pink", "pink", "red", "pink", "red", "pink" }; //powerupManager = new PowerupManager(game, spriteBatch, locs, types); }
public void loadContent(Game1 game, string tilemap, string entitymap) { using (StreamReader reader = new StreamReader(@"Content/" + tilemap)) { string[] offStrings = reader.ReadLine().Split(' '); offsets[0] = new Vector2(Convert.ToInt32(offStrings[0]), Convert.ToInt32(offStrings[1])); mapX = offsets[0].X; mapY = offsets[0].Y; mortimerX = Convert.ToInt32(offStrings[2]); mortimerY = Convert.ToInt32(offStrings[3]); for (int i = 0; i < tiles.GetLength(0); i++) { string line = reader.ReadLine(); string[] data = line.Split(' '); for (int j = 0; j < tiles.GetLength(1); j++) { string tileName = data[j]; tiles[i, j] = new Tile(tileName, game, i, j, (int)-mapX, (int)-mapY); } } } //spawns entities from the entity map List <Vector2> locs = new List <Vector2>(); List <String> types = new List <String>(); using (StreamReader reader = new StreamReader(@"Content/" + entitymap)) { for (int i = 0; i < tiles.GetLength(0); i++) { string line = reader.ReadLine(); string[] data = line.Split(' '); for (int j = 0; j < tiles.GetLength(1); j++) { //decodes the id from the text file int entityid = Convert.ToInt32(data[j]); //interprets ids into entities switch (entityid) { // entity ids case 0: //no entities on this tile break; case 1: //offsets are in the map file. They offset the enemy position to match the position of the map. //Locations are loaded with the equations in the Vector2. They spawn them based on their locations in the entity map file and correspond with the tile locations in the map file. You can copy the equations directly for all entities. enemies.Add(new Cat(game, new Vector2(j * 64 - (int)offsets[0].X, i * 64 - (int)offsets[0].Y))); break; //add as many entities (enemies or powerups) as needed, but don't reuse ids case 2: //blue cheese types.Add("blue"); locs.Add(new Vector2(j * 64 - (int)offsets[0].X, i * 64 - (int)offsets[0].Y)); break; case 5: //white cheese types.Add("white"); locs.Add(new Vector2(j * 64 - (int)offsets[0].X, i * 64 - (int)offsets[0].Y)); break; case 4: //pink cheese types.Add("pink"); locs.Add(new Vector2(j * 64 - (int)offsets[0].X, i * 64 - (int)offsets[0].Y)); break; case 3: //green cheese types.Add("green"); locs.Add(new Vector2(j * 64 - (int)offsets[0].X, i * 64 - (int)offsets[0].Y)); break; case 6: //purple cheese types.Add("purple"); locs.Add(new Vector2(j * 64 - (int)offsets[0].X, i * 64 - (int)offsets[0].Y)); break; case 7: //yellow cheese types.Add("yellow"); locs.Add(new Vector2(j * 64 - (int)offsets[0].X, i * 64 - (int)offsets[0].Y)); break; case 8: //red cheese types.Add("red"); locs.Add(new Vector2(j * 64 - (int)offsets[0].X, i * 64 - (int)offsets[0].Y)); break; case 9: //tasks tasks.Add(new Task(game, new Vector2(j * 64 - (int)offsets[0].X, i * 64 - (int)offsets[0].Y))); break; case 10: //win area winArea.Add(new EndZone(game, new Vector2(j * 64 - (int)offsets[0].X, i * 64 - (int)offsets[0].Y))); break; case 11: //cat boss enemies.Add(new CatBoss(game, new Vector2(j * 64 - (int)offsets[0].X, i * 64 - (int)offsets[0].Y))); break; default: throw new InvalidDataException("Unknown entity id: " + entityid); } } } } powerupManager = new PowerupManager(game, locs, types); player = new Mortimer(new Vector2(200, 200), game, powerupManager); player.loadContent(game); }