Example #1
0
        /// Loads the passed mapFile and sets it as active map
        public void load(Besmash game, string mapFile)
        {
            if (Content == null)
            {
                Content = new ContentManager(
                    game.Content.ServiceProvider,
                    game.Content.RootDirectory);
            }

            ContentManager mapContent = new ContentManager(
                Content.ServiceProvider,
                Content.RootDirectory
                );


            bool newGame;

            if ((newGame = Team == null))
            {
                Team = new Team(
                    (mapContent.Load <Player>("objects/world/entities/player/grey").clone() as Player),
                    (mapContent.Load <Player>("objects/world/entities/player/pink").clone() as Player)
                    );

                Team.Formation.Add(Team.Members[0], new Point(0, 1));
            }

            TileMap prevMap = ActiveMap;

            ActiveMap = Content.Load <TileMap>(mapFile);
            if (!ActiveMap.Initialized)
            {
                ActiveMap.init(game);
            }

            ActiveMap.onLoad(prevMap, Team);
            if (prevMap != null)
            {
                prevMap.unload();                 // TODO test!
            }
            ActiveMap.load(mapContent);
            ActiveMap.spawnEntities();
            LastMap = mapFile;
            Game    = game;

            // TODO testcode (battle start)
            ActiveMap.Entities.Where(e => e is Creature)
            .Cast <Creature>().ToList().ForEach(c => {
                if (c is Enemy)
                {
                    (c as Enemy)
                    .PlayerInRangeEvent += onPlayerInEnemyRange;
                }
            });

            if (newGame)
            {
                int i;
                Team.Player.ForEach(pl => {
                    for (i = 0; i < 3; ++i)  // TODO init level
                    {
                        pl.Exp = pl.MaxExp;
                        pl.levelUp();
                    }

                    pl.HP = pl.MaxHP;
                    pl.AP = pl.MaxAP;
                });
            }
        }