/// <summary> /// Metoda slouzici pro nahrani hry /// </summary> /// <param name="gamename"></param> public static void LoadGame(string gamename) { GameSerialize ob = new GameSerialize(); try { Serializer ser = new Serializer(); ob = ser.DeSerializeGame(gamename); LoadMapAndTextures(ob.mapName); LoadHeroSprite(ob.hero.Gender); //Overrides Units loaded from MapSerialize Units = new List<Unit>(); foreach (Unit item in ob.units) { Unit klon = baseUnits[item.Name].Clone(item.Notoriety, item.Cell.X, item.Cell.Y); Session.FrontMap.GetTile(item.Cell).obj = klon; Units.Add(klon); } //Overrides Keys loaded from MapSerialize Keys = new List<GameKey>(); foreach (GameKey item in ob.keys) { GameKey klon = baseKeys[item.index].Clone(item.Cell.X, item.Cell.Y); Session.FrontMap.GetTile(item.Cell).obj = klon; Keys.Add(klon); } MapLayer frontPath = new MapLayer(Session.MapProps.FrontSizeX, Session.MapProps.FrontSizeY); for (int y = 0; y < frontPath.Height; y++) { for (int x = 0; x < frontPath.Width; x++) { Tile tile = new Tile(-1, -1, y, x); frontPath.SetTile(x, y, tile); } } Session.FrontMap.mapLayers.Add(frontPath); Session.CurrentHero = new Hero(ob.hero, playerSpriteHero); Session.CurrentHero.units = new List<Unit>(); foreach (Unit item in ob.hero.units) { Session.CurrentHero.units.Add(baseUnits[item.Name].Clone(item.Notoriety, item.Cell.X, item.Cell.Y, item.Attack, item.Defense, item.HitPoints, item.isInHero)); } Session.Camera = ob.cam; Session.FrontMap.mapLayers[1] = ob.frontSplatter; } catch (Exception ex) { string message = ex.Message; } }
/// <summary> /// Obsluha tlacitka potvrzujici vstup do hry /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void linkLabel1_Selected(object sender, EventArgs e) { //Nacteni vsech veci okolo mapy, hrdiny a inicializace map Session.LoadMapAndTextures("map.xml"); Session.LoadHeroSprite(genderSelector.SelectedItem); Session.Camera = new Camera(new Vector2(0,0)); //Nastaveni jednotek do tilemapy foreach (Unit item in Session.Units) { Session.FrontMap.GetTile(item.Cell).obj = item; } //Nastaveni klicu do tilemapy foreach (GameKey item in Session.Keys) { Session.FrontMap.GetTile(item.Cell).obj = item; } //Nastaveni vrstvy mapy vyuzivajici pathengine pro vykresleni oznamovaci cesty MapLayer frontPath = new MapLayer(Session.MapProps.FrontSizeX, Session.MapProps.FrontSizeY); for (int y = 0; y < frontPath.Height; y++) { for (int x = 0; x < frontPath.Width; x++) { Tile tile = new Tile(-1, -1, y, x); frontPath.SetTile(x, y, tile); } } Session.FrontMap.mapLayers.Add(frontPath); //Vytvoreni noveho hrdiny CreateNewHero(); //Pridani dat pro ulozeni Session.CurrentHero.Gender = genderSelector.SelectedItem; if(Session.CurrentHero.Gender == "Female") Session.CurrentHero.Sprite.texture = Content.Load<Texture2D>(@"Sprites\femalefighter"); //Autosave Session.SaveGame("AutoSave.xml"); //Vraceni na hlavni menu a okamzity prehozeni na herni okno manager.PopScreen(); manager.PushScreen(GameRef.GamePlayScreen); }