Esempio n. 1
0
        // Draws the entire combat board:  floor, grid, player, and obstacles.  Note the order in the way they are draw.  This is to show proper Z-order.
        public override void Draw(GameTime gameTime)
        {
            // Update the grid's view.  The projection and world matrices won't change
            grid.ViewMatrix = combatScreen.MyView;
            grid.Draw();

            // Display grid numbers
            if (gridNumbersVisible)
            {
                drawGridNumbers();
            }

            // Draw player selection if applicable
            if (playerHexSelection != null)
            {
                playerHexSelection.setGraphicsMatrices(combatScreen.MyView, combatScreen.MyProjection, combatScreen.MyWorld);
                playerHexSelection.Draw();
            }

            // Draw the game entities on the board.
            // We have to draw it this way so we get correct z-ordering.
            // When drawing a 3D scene, it is important to depth sort the graphics, so things that are close to the camera will be drawn
            // over the top of things from further away. We do not want those distant mountains to be drawn over the top of the building
            // that is right in front of us! There are three depth sorting techniques in widespread use today:
            //
            //     Depth buffering (aka. z-buffering)
            //     Painter’s algorithm
            //     Backface culling
            //
            // Unfortunately, all have limitations. To get good results, most games rely on a combination of all three.
            //
            // Depth buffering won't work in our case because it can only be used with opaque objects.  That is objects that are completely solid.
            // Since our sprites have transparency (alpha blending) we can't use this mode.  Almost all the websites I looked up said just set the
            // depth buffer stencil and things would draw correctly, but if you have transparent textures the XNA rendering engine ignores the
            // transparency and just fills it with the default color.
            //
            // Backface culling only works with curved objects or more solid objects.  Since our sprites are 2D quads that exist in 3D they don't
            // have any substance.
            //
            // The only other option is to make our algoritm paint these objects in the order from back to front.  Since lower hex cells are in the
            // back we just draw them in row, column order to get the correct depth (z-order).
            //
            // See http://blogs.msdn.com/b/shawnhar/archive/2009/02/18/depth-sorting-alpha-blended-objects.aspx  for details about this stuff
            //
            // TO DO:  Make a sorting algorithm when the game entities are first put on the board or are moved so we don't have to go through
            //         ever hex cell.

            for (int i = 0; i < this.hexBoardHeight; i++)
            {
                for (int j = 0; j < this.hexBoardWidth; j++)
                {
                    Hex        hex            = getHex(i, j);
                    GameEntity inactiveEntity = hex.InactiveEntity;
                    if (inactiveEntity != null)
                    {
                        inactiveEntity.MyView = combatScreen.MyView;
                        inactiveEntity.Draw(gameTime);
                    }

                    GameEntity gameEntity = hex.MyGameEntity;
                    if (gameEntity != null)
                    {
                        gameEntity.MyView = combatScreen.MyView;
                        gameEntity.Draw(gameTime);
                    }
                }
            }

            /*
             * foreach (GameEntity gameEntity in gameEntities.MyGameEntities)
             * {
             *  gameEntity.setViewMatrix(combatScreen.MyView);
             *  gameEntity.Draw(gameTime);
             * }
             * */

            if (combatAttack != null)
            {
                combatAttack.MyView = combatScreen.MyView;
                combatAttack.Draw(gameTime);
            }

            base.Draw(gameTime);
        }