public MapComponent(Game game, Texture2D tileset, GraphicsDeviceManager graphics, SpriteBatch spriteBatch, SpriteFont font, Texture2D player, mapHolder maps, int random) : base(game) { this.player = player; playerSprite = new AnimatedSprite(game, player, spriteBatch); t2dTileSet = tileset; spriteFont = font; this.graphics = graphics; this.spriteBatch = spriteBatch; iMapX = 0; iMapY = 0; this.maps = maps; map temp; temp = maps.newMap(random); iMap = temp.returnMap(); position = temp.returnPosition(); }
public mapHolder mapFile(bool online) { mapHolder maps; maps = new mapHolder(); int i; int x; List <String> listing; listing = new List <String>(); StreamReader streamReader; bool lineOne; //Comented out for demo //if (online) //{ // downloader update; // update = new downloader(); // update.map(); //} //Open the map listing file if (File.Exists("Content/maps/mapListing.txt")) { streamReader = new StreamReader("Content/maps/mapListing.txt");//Change this for a dynamic path. lineOne = true; while (!streamReader.EndOfStream) { if (lineOne) { string line = streamReader.ReadLine(); //Read the line and ignore it. Important so that it moves on to the next line. lineOne = false; } else { string line = streamReader.ReadLine(); //Read the line listing.Add(line); } } streamReader.Close(); } else { //massive error the file does not exist //exit the game } //open each map from the listing foreach (String name in listing) { if (File.Exists("Content/maps/" + name)) { int[,] iMap; int[] position; i = 0; lineOne = true; streamReader = new StreamReader("Content/maps/" + name); //Change this for a dynamic path. position = new int[2]; iMap = new int[100, 100]; //Possible update to allow for differnt sized maps. while (!streamReader.EndOfStream) { if (lineOne) { string line = streamReader.ReadLine(); string[] array = line.Split(','); lineOne = false; position[0] = Convert.ToInt32(array[0]); position[1] = Convert.ToInt32(array[1]); } else { string line = streamReader.ReadLine(); string[] array = line.Split(','); x = 0; foreach (String tileCode in array) { iMap[i, x] = Convert.ToInt32(tileCode); x++; } i++; } } maps.addMap(new map(iMap, position)); } else { //Error file doesn't exsit, it's okay to contiune as it won't be added to maps. } } return(maps); }
//Skill Code public campaignScreen(Game game, SpriteBatch spriteBatch, Texture2D tiles, Texture2D sprite, GraphicsDeviceManager graphics, SpriteFont spriteFont, Texture2D bg, Texture2D heads, Texture2D floathud, Texture2D txtmob, Texture2D allymob, playerComponent Player, Texture2D health, Texture2D mana, Texture2D hudbg, Texture2D closedChestSprite, Texture2D openChestSprite, Texture2D slot1Sprite, Texture2D slot2Sprite, Texture2D slot3Sprite, Texture2D slot4Sprite, Texture2D testItemSprtie, Texture2D redTile, Texture2D tentSprite, Texture2D elfAllySprite, Texture2D orcAllySprite, Texture2D humanAllySprite, Texture2D orcBossSprite, Texture2D humanBossSprite, Texture2D hud2, Texture2D buffIcon, Texture2D spellIcon, Texture2D healIcon, Texture2D aoeIcon, Texture2D swordIcon, List <item> items, mapHolder maps) : base(game, spriteBatch) { //Anni Sprites this.elfAllySprite = elfAllySprite; this.orcAllySprite = orcAllySprite; this.humanAllySprite = humanAllySprite; this.human = humanBossSprite; this.orc = orcBossSprite; healthbar = health; manabar = mana; expbar = health; this.hudbg = hudbg; this.Player = Player; this.hud2 = hud2; allySprite = allymob; mobsprite = txtmob; position[0] = 10; position[1] = 10; otherposition[0] = 14; otherposition[1] = 12; tophud = floathud; hudbar = heads; menubg = bg; this.graphics = graphics; this.spriteFont = spriteFont; this.sprite = sprite; // this.manaPot = manaPot; this.swordIcon = swordIcon; this.healIcon = healIcon; this.buffIcon = buffIcon; this.spellIcon = spellIcon; this.aoeIcon = aoeIcon; //Item Code this.closedChestSprite = closedChestSprite; this.openChestSprite = openChestSprite; itemControl = new dropController(game, openChestSprite, closedChestSprite, spriteBatch, items); this.slot1Sprite = slot1Sprite; this.slot2Sprite = slot2Sprite; this.slot3Sprite = slot3Sprite; this.slot4Sprite = slot4Sprite; this.redTile = redTile; this.testItemSprtie = testItemSprtie; //Item Code map = new MapComponent(game, tiles, graphics, spriteBatch, spriteFont, sprite, maps, RandomNumber(0, maps.total()));//Modified for map files collisions = new CollisionComponent(game, map.iMap, map.position); Components.Add(map); tileControl = new resourceControl(map.iMap); //Updated for tile based resources! Components.Add(itemControl); //Item Code Components.Add(Player); Components.Add(collisions); Texture2D allyToUse; if (Player.Race == "Orc") { allyToUse = orcAllySprite; } else if (Player.Race == "Elf") { allyToUse = elfAllySprite; } else { allyToUse = humanAllySprite; } allies = new Allies(game, spriteBatch, allyToUse, Player.Level, map.iMap); allies.iMapX = map.iMapX; allies.iMapY = map.iMapY; Components.Add(allies); Texture2D mobToUse; Texture2D bossToUse; if (Player.Race == "Human") { mobToUse = orcAllySprite; bossToUse = orc; } else { mobToUse = humanAllySprite; bossToUse = human; } mobControl = new EnemyControl(game, mobToUse, bossToUse, spriteBatch, Player.Level, map.iMap); mobControl.iMapX = map.iMapX; mobControl.iMapY = map.iMapY; Components.Add(mobControl); imageRectangle = new Rectangle( 0, 0, Game.Window.ClientBounds.Width, Game.Window.ClientBounds.Height); //Building Code this.tentSprite = tentSprite; buildings = new buildingControl(game, tentSprite, spriteBatch, map.iMap); Components.Add(buildings); //Building Code }