Esempio n. 1
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
            {
                this.Exit();
            }

            //Update the mouse manager to update mouse input
            MouseManager.Update();

            //Get the mouse position
            int mousePosX, mousePosY;

            MouseManager.GetPosition(out mousePosX, out mousePosY);

            //Get the tile position under the mouse
            int mouseTilePosX = mousePosX / 64;
            int mouseTilePosY = mousePosY / 64;

            //Left button: Add a tile
            if (MouseManager.ButtonPressed(MouseButton.LEFT))
            {
                //Add a tile under mouse
                tileManager.AddTile(mouseTilePosX, mouseTilePosY);

                //Update the tile generators (regenerate them currently)
                tileRectangleDrawer.SetTileRectangles(TileRectangleCombiner.Combine(tileManager));
                tileRectangleDebugDrawer.SetTileRectangles(TileRectangleCombiner.Combine(tileManager));

                //Create the edge decals
                edgeDecalManager.CreateEdgeDecals(tileManager.GetAllTiles(), tileManager.Width, tileManager.Height, tileManager.TileSize);
            }

            //Right button: Remove a tile
            if (MouseManager.ButtonPressed(MouseButton.RIGHT))
            {
                //Remove the tile under mouse
                tileManager.RemoveTile(mouseTilePosX, mouseTilePosY);

                //Update the tile generators (regenerate them currently)
                tileRectangleDrawer.SetTileRectangles(TileRectangleCombiner.Combine(tileManager));
                tileRectangleDebugDrawer.SetTileRectangles(TileRectangleCombiner.Combine(tileManager));

                //Create the edge decals
                edgeDecalManager.CreateEdgeDecals(tileManager.GetAllTiles(), tileManager.Width, tileManager.Height, tileManager.TileSize);
            }

            //Middle button: Toggle debug drawing
            if (MouseManager.ButtonPressed(MouseButton.MIDDLE))
            {
                debugDraw = !debugDraw;
            }

            base.Update(gameTime);
        }