Пример #1
0
        public MapCreator(Game game, string outFileName, int numRows, int numCols, Vector2 tileSize)
        {
            this.outFileName = outFileName;

            TilesAcross = numRows;
            TilesDown = numCols;
            TileSize = tileSize;

            int[] tileTypeIndices = new int[numRows * numCols];
            for (int i = 0; i < numRows * numCols; i++)
                tileTypeIndices[i] = (int)TileType.Ground;

            string[] fileNames = Directory.GetFiles(".", "Scenario*.xml", SearchOption.TopDirectoryOnly);

            if (fileNames.Length > 0)
            {
                this.outFileName = fileNames[0];
                Load(this.outFileName);
            }
            else
            {
                scenario = new Scenario();

                scenario.MapDescription = new MapDescription();
                scenario.MapDescription.TilesDown = numRows;
                scenario.MapDescription.TilesAcross = numCols;
                scenario.MapDescription.TileSize = tileSize;
                scenario.MapDescription.MapTiles = tileTypeIndices;

                scenario.PlayerDescription = new PlayerDescription();
                scenario.PlayerDescription.MaxSpeed = 200.0f;

                scenario.EnemiesDescription = new EnemiesDescription();
                scenario.EnemiesDescription.EnemiesInfo = new List<EnemiesDescription.EnemyInfo>();
            }

            Map = new EditorMap(scenario.MapDescription);

            Camera = new MapCreatorCamera(game.GraphicsDevice, Vector2.Zero);

            Gui = new MapCreatorGui();
            buttonActions.Add(MapCreatorGui.Button.Grass, handleGrassEditing);
            buttonActions.Add(MapCreatorGui.Button.Wall, handleWallEditing);
            buttonActions.Add(MapCreatorGui.Button.Bush, handleBushEditing);
            buttonActions.Add(MapCreatorGui.Button.Player_Position, handlePlayerEditing);
            buttonActions.Add(MapCreatorGui.Button.Carrot_Position, handleCarrotEditing);
            buttonActions.Add(MapCreatorGui.Button.Enemies, handleEnemyEditing);
            buttonActions.Add(MapCreatorGui.Button.Save, Save);

            selectionSprite = new VisualRectangle(enemySprite.BoundingBox);
            selectionSprite.FillColor = Color.Transparent;
            selectionSprite.EdgeColor = Color.Transparent;

            // Handle updating anything in the editor if scenario XML was loaded.
            playerSprite.Position = Map.TilePosToWorldPos(scenario.PlayerDescription.StartingTilePosition);
            carrotSprite.Position = Map.TilePosToWorldPos(scenario.PlayerDescription.CarrotTilePosition);
        }
Пример #2
0
 public void Load(string file)
 {
     using (XmlReader reader = XmlReader.Create(file))
     {
         scenario = IntermediateSerializer.Deserialize<Scenario>(reader, null);
     }
 }
Пример #3
0
        private void loadScenario(string scenarioName)
        {
            try
            {
                //currentScenario = Content.Load<Scenario>(GlobalGameSettings.Game.Scenario);
                currentScenario = Content.Load<Scenario>(scenarioName);

                WorldDimensions = new Rectangle(0, 0,
                    currentScenario.MapDescription.TilesAcross * (int)currentScenario.MapDescription.TileSize.X,
                    currentScenario.MapDescription.TilesDown * (int)currentScenario.MapDescription.TileSize.Y);
                WorldCenter = new Vector2(WorldDimensions.Width, WorldDimensions.Height) / 2;

                GameMap = new Map(currentScenario.MapDescription);
                playerManager = new PlayerManager(currentScenario.PlayerDescription);
                enemyManager = new EnemyManager(currentScenario.EnemiesDescription);

                gameCamera = new Camera(graphics.GraphicsDevice, playerManager.Player.Position);
                gameCamera.Magnification = 1.5f;
            }
            // Super hack for when scenarioNumber becomes larger than the number of scenarios.
            catch (ContentLoadException)
            {
                gameState = GameState.WonGame;
            }
        }