コード例 #1
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);
            //21/35
            sample_image = new SpriteSheet(Content.Load <Texture2D>("sprites/commandos"), spriteBatch, 21, 35);
            sample_tile  = new SpriteSheet(Content.Load <Texture2D>("sprites/green_tile20x20"), spriteBatch, 20, 20);
            sample_util  = new SpriteSheet(Content.Load <Texture2D>("sprites/util_misc20x20"), spriteBatch, 20, 20);
            menuUI       = new SpriteSheet(Content.Load <Texture2D>("gamePlayUI/menuUI"), spriteBatch, 299, 211);
            iconUI       = new SpriteSheet(Content.Load <Texture2D>("gamePlayUI/icons"), spriteBatch, 208, 51);
            gamePlayMenu = new ViewGamePlayMenu(graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight, menuUI);
            gamePlayMenu.loadIconSprite(iconUI);

            gameSelectView.loadSpriteSheet(sample_util);

            gameView = new View(800, 600, spriteBatch);
            gameView.LoadScenario(this.testGameController.scenario);
            gamePlayMenu.LoadScenario(this.testGameController.scenario);
            gameView.LoadMap(this.testGameController.gameWorld);


            gameView.LoadSpriteSheet(sample_tile);
            gameView.LoadUnitsSpriteSheet(sample_image);
            gameView.LoadUtilitySpriteSheet(sample_util);
            gameView.LoadBuildingSpriteSheet(new SpriteSheet(Content.Load <Texture2D>("gameBuildings/sample_build"), spriteBatch, 40, 40));
            testGameController.registerObserver(gameSelectView);
            // TODO: use this.Content to load your game content here
        }
        /// <summary>
        /// Update Input
        /// </summary>
        /// <param name="input"></param>
        /// <param name="testGameController"></param>
        /// <param name="gameView"></param>
        /// <param name="gamePlayMenu"></param>
        public void updateInput(MouseState input, Controller testGameController, ZRTS.View.ViewGame gameView, ViewGamePlayMenu gamePlayMenu)
        {
            // Right click to give a command
            if (input.RightButton == ButtonState.Pressed && prevInput.RightButton == ButtonState.Released)
            {
                giveCommand(input, gameView, testGameController);
            }

            if(gamePlayMenu.containsPoint(input.X, input.Y))
            {
                if (input.LeftButton == ButtonState.Pressed)
                {
                    /** Handle Menu Input **/
                    int button = gamePlayMenu.onButton(input.X, input.Y);
                    //button corespons with the button pressed 0 to 3 left to right

                    if (button == 0)
                    {
                        currentPlayerCommand = PlayerCommand.CANCEL;
                    }
                    if (button == 1)
                    {
                        currentPlayerCommand = PlayerCommand.BUILD;
                    }
                    if (button == 2)
                    {
                        currentPlayerCommand = PlayerCommand.MOVE;
                    }
                    if (button == 3)
                    {
                        currentPlayerCommand = PlayerCommand.ATTACK;
                    }

                }
            }
            else
            {
                handleSelecting(input, testGameController, gameView, gamePlayMenu);
            }

            prevInput = input;
        }
        /// <summary>
        /// Update Input
        /// </summary>
        /// <param name="input"></param>
        /// <param name="testGameController"></param>
        /// <param name="gameView"></param>
        /// <param name="gamePlayMenu"></param>
        public void updateInput(MouseState input, Controller testGameController, View gameView, ViewGamePlayMenu gamePlayMenu)
        {
            // Right click to give a command
            if (input.RightButton == ButtonState.Pressed && prevInput.RightButton == ButtonState.Released)
            {
                giveCommand(input, gameView, testGameController);
            }


            if (gamePlayMenu.containsPoint(input.X, input.Y))
            {
                if (input.LeftButton == ButtonState.Pressed)
                {
                    /** Handle Menu Input **/
                    int button = gamePlayMenu.onButton(input.X, input.Y);
                    //button corespons with the button pressed 0 to 3 left to right

                    if (button == 0)
                    {
                        currentPlayerCommand = PlayerCommand.CANCEL;
                    }
                    if (button == 1)
                    {
                        currentPlayerCommand = PlayerCommand.BUILD;
                    }
                    if (button == 2)
                    {
                        currentPlayerCommand = PlayerCommand.MOVE;
                    }
                    if (button == 3)
                    {
                        currentPlayerCommand = PlayerCommand.ATTACK;
                    }
                }
            }
            else
            {
                handleSelecting(input, testGameController, gameView, gamePlayMenu);
            }

            prevInput = input;
        }
        /// <summary>
        /// Handle selecting units and buildings by the user
        /// </summary>
        /// <param name="input"></param>
        /// <param name="testGameController"></param>
        /// <param name="gameView"></param>
        /// <param name="gamePlayMenu"></param>
        private void handleSelecting(MouseState input, Controller testGameController, View gameView, ViewGamePlayMenu gamePlayMenu)
        {
            /* Left click to select units */

            // Store the first corner of the "drag box"
            if (input.LeftButton == ButtonState.Pressed && prevInput.LeftButton == ButtonState.Released)
            {
                if (testGameController.isWithinGameBound(selectX, selectY))
                {
                    selectX = gameView.convertScreenLocToGameLoc(input.X, input.Y).X;
                    selectY = gameView.convertScreenLocToGameLoc(input.X, input.Y).Y;

                    gameView.setFirstCornerOfDragBox(input.X, input.Y);
                    gameView.IsDragging = true;
                }
            }

            // While dragging, update the view to draw the box
            if (input.LeftButton == ButtonState.Pressed)
            {
                gameView.setDragBox(input.X, input.Y);
            }

            // "Drag box" is created, select all units within box
            if (input.LeftButton == ButtonState.Released && prevInput.LeftButton == ButtonState.Pressed)
            {
                float releaseX = gameView.convertScreenLocToGameLoc(input.X, input.Y).X; // coords of release location
                float releaseY = gameView.convertScreenLocToGameLoc(input.X, input.Y).Y;
                float pressX   = selectX;                                                // coords of press location
                float pressY   = selectY;

                if (testGameController.isWithinGameBound(releaseX, releaseY) && testGameController.isWithinGameBound(pressX, pressY))
                {
                    /*
                     * Retrieve all units within the drag box - Use Min and Max to find the topleft and
                     * bottomright corner
                     */
                    testGameController.scenario.selectUnits(
                        (int)Math.Min(pressX, releaseX),
                        (int)Math.Min(pressY, releaseY),
                        (int)(Math.Max(pressX, releaseX) - Math.Min(pressX, releaseX)),
                        (int)(Math.Max(pressY, releaseY) - Math.Min(pressY, releaseY))
                        );
                }

                gameView.IsDragging = false;
                //gameView.resetDragBox();
            }
        }
        /// <summary>
        /// Handle selecting units and buildings by the user
        /// </summary>
        /// <param name="input"></param>
        /// <param name="testGameController"></param>
        /// <param name="gameView"></param>
        /// <param name="gamePlayMenu"></param>
        private void handleSelecting(MouseState input, Controller testGameController, ZRTS.View.ViewScreenConvert gameView, ViewGamePlayMenu gamePlayMenu)
        {
            /* Left click to select units */

            // Store the first corner of the "drag box"
            if (input.LeftButton == ButtonState.Pressed && prevInput.LeftButton == ButtonState.Released)
            {
                if (testGameController.isWithinGameBound(selectX, selectY))
                {
                    selectX = gameView.convertScreenLocToGameLoc(input.X, input.Y).X;
                    selectY = gameView.convertScreenLocToGameLoc(input.X, input.Y).Y;

                    //gameView.setFirstCornerOfDragBox(input.X, input.Y);
                    //gameView.IsDragging = true;
                }

            }

            // While dragging, update the view to draw the box
            if (input.LeftButton == ButtonState.Pressed)
            {
                //gameView.setDragBox(input.X, input.Y);
            }

            // "Drag box" is created, select all units within box
            if (input.LeftButton == ButtonState.Released && prevInput.LeftButton == ButtonState.Pressed)
            {
                float releaseX = gameView.convertScreenLocToGameLoc(input.X, input.Y).X;     // coords of release location
                float releaseY = gameView.convertScreenLocToGameLoc(input.X, input.Y).Y;
                float pressX = selectX;  // coords of press location
                float pressY = selectY;

                if (testGameController.isWithinGameBound(releaseX, releaseY) && testGameController.isWithinGameBound(pressX, pressY))
                {
                    /*
                     * Retrieve all units within the drag box - Use Min and Max to find the topleft and
                     * bottomright corner
                     */
                    testGameController.scenario.selectUnits(
                        (int)Math.Min(pressX, releaseX),
                        (int)Math.Min(pressY, releaseY),
                        (int)(Math.Max(pressX, releaseX) - Math.Min(pressX, releaseX)),
                        (int)(Math.Max(pressY, releaseY) - Math.Min(pressY, releaseY))
                    );
                }

                //gameView.IsDragging = false;
                //gameView.resetDragBox();

            }
        }
コード例 #6
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);
            //21/35
            sample_image = new SpriteSheet(Content.Load<Texture2D>("sprites/commandos"), spriteBatch, 21, 35);
            sample_tile = new SpriteSheet(Content.Load<Texture2D>("sprites/green_tile20x20"), spriteBatch, 20, 20);
            sample_util = new SpriteSheet(Content.Load<Texture2D>("sprites/util_misc20x20"), spriteBatch, 20, 20);
            menuUI = new SpriteSheet(Content.Load<Texture2D>("gamePlayUI/menuUI"), spriteBatch, 299, 211);
            iconUI = new SpriteSheet(Content.Load<Texture2D>("gamePlayUI/icons"), spriteBatch, 208, 51);
            gamePlayMenu = new ViewGamePlayMenu(graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight,menuUI);
            gamePlayMenu.loadIconSprite(iconUI);

            gameSelectView.loadSheet(sample_util);

            gameView = new ZRTS.View.ViewGame(800,600);
            //gameView.LoadScenario(this.testGameController.scenario);
            gamePlayMenu.LoadScenario(this.testGameController.scenario);
            gameView.loadGameWorld(this.testGameController.gameWorld);

            gameView.loadSheet(sample_tile);
            gameView.loadUnitSheet(sample_image);
            //gameView.LoadUtilitySpriteSheet(sample_util);
            gameView.loadBuildingSheet(new SpriteSheet(Content.Load<Texture2D>("gameBuildings/sample_build"), spriteBatch, 40, 40));
            testGameController.registerObserver(gameSelectView);
            // TODO: use this.Content to load your game content here
        }