コード例 #1
0
ファイル: PlayScene.cs プロジェクト: Commkeen/Archmage
        public void GotoLevel(Dungeon_Branches branch, int depth)
        {
            //TODO: Any spells affecting monsters on the previous level need to be shut off!

            //Save the player
            Student s = (Student)_gameObjectPool.GetActor(_studentID);

            //Save the player's ActorBehaviors
            List <ActorBehavior> studentBehaviors = new List <ActorBehavior>();

            foreach (int bID in s.GetBehaviors())
            {
                studentBehaviors.Add(_gameObjectPool.GetActorBehavior(bID));
            }

            //Save the current level
            if (_currentDepth != 0)
            {
                _dungeon.SaveLevel(_currentDungeonBranch, _currentDepth, SaveLevelToData());
            }

            //Reset the game object pool and turn counter objects
            _gameObjectPool.ResetGameObjectPool();
            _turnCounter.ClearTurnCounter();

            //Move all the student stuff into the new game object pool
            //TODO: Do this instead: Save the student as a data object properly, with its behaviors
            //And then load it into the level normally, as if the player loaded a saved game
            _gameObjectPool.AddObjectToPool(s, _studentID); //TODO: This is hack-y and should be changed somehow
            _turnCounter.AddObjectToCounter(_studentID);
            foreach (ActorBehavior b in studentBehaviors)
            {
                _gameObjectPool.AddObjectToPool(b, b.InstanceID);
            }

            //Build level
            _currentLevel = _dungeon.LoadLevel(branch, depth);
            if (_currentLevel == null)
            {
                _currentLevel = _gen.GenerateLevel(branch, depth);
            }
            LoadLevelFromData(_currentLevel);

            IntVector2 playerStart = new IntVector2(5, 5);

            //Place the player at the proper location
            if (_currentDepth > depth)
            {
                //Player climbed up, put the player on the down stairs
                IntVector2 tile = _map.GetFirstTileWithFeature(Tile_SimpleFeatureType.STAIRS_DOWN);
                if (tile != null)
                {
                    playerStart = tile;
                }
            }
            else
            {
                //Player went down, put the player on the up stairs
                IntVector2 tile = _map.GetFirstTileWithFeature(Tile_SimpleFeatureType.STAIRS_UP);
                if (tile != null)
                {
                    playerStart = tile;
                }
            }



            _gameObjectPool.GetActor(_studentID).WarpToPosition(playerStart);

            _currentDepth = depth;
            if (_currentDepth > _maxDepth)
            {
                _maxDepth = _currentDepth;
            }

            //A hacky way to make the levels look unique
            _map.ColorTiles(_currentDepth);
        }