Exemplo n.º 1
0
        ///
        /// <summary>
        ///		Called to render the tile onto the screen.
        /// </summary>
        ///
        public override void draw(
            GraphicsDeviceManager graphics,
            BasicEffect effect,
            Camera camera,
            World world,
            Int32 tileX,
            Int32 tileZ)
        {
            Tile.renderTile(
                graphics,
                effect,
                camera,
                tileX,
                tileZ,
                this.heights,
                TextureResources.tileGrassTexture,
                0.0F);


            Vector2 treePosition = new Vector2(0.0F, 0.0F);

            switch (this.treeCorner)
            {
            case TileCorner.TopLeft:
                treePosition = new Vector2(-0.25F, -0.25F);
                break;

            case TileCorner.TopRight:
                treePosition = new Vector2(0.25F, -0.25F);
                break;

            case TileCorner.BottomLeft:
                treePosition = new Vector2(-0.25F, 0.25F);
                break;

            case TileCorner.BottomRight:
                treePosition = new Vector2(0.25F, 0.25F);
                break;
            }
            treePosition *= Tile.TILE_WIDTH;


            ModelResources.renderModel(
                ModelResources.treeModel,
                camera,
                new Vector3((tileX * Tile.TILE_WIDTH) + (Tile.TILE_WIDTH / 2.0F) + treePosition.X,
                            getAverageHeight() * Tile.HEIGHT_STEP,
                            (tileZ * Tile.TILE_WIDTH) + (Tile.TILE_WIDTH / 2.0F) + treePosition.Y),
                new Vector3(0.0F, (float)treeRotation, 0.0F),
                new Vector3(1.0F));
        }
Exemplo n.º 2
0
        ///
        /// <summary>
        ///		Renders the entire world onto the screen.
        /// </summary>
        ///
        /// <param name="graphics">The graphics device manager of the game.</param>
        /// <param name="effect">A BasicEffect instance.</param>
        /// <param name="camera">The camera.</param>
        ///
        public void draw(
            GraphicsDeviceManager graphics,
            BasicEffect effect,
            Camera camera)
        {
            int range = 32;

            int minX = (int)((player.position.X / Tile.TILE_WIDTH) - range);
            int minZ = (int)((player.position.Z / Tile.TILE_WIDTH) - range);
            int maxX = (int)((player.position.X / Tile.TILE_WIDTH) + range);
            int maxZ = (int)((player.position.Z / Tile.TILE_WIDTH) + range);

            if (minX < 0)
            {
                minX = 0;
            }
            if (minZ < 0)
            {
                minZ = 0;
            }
            if (maxX >= width)
            {
                maxX = width - 1;
            }
            if (maxZ >= height)
            {
                maxZ = height - 1;
            }

            for (int x = minX; x <= maxX; x++)
            {
                for (int z = minZ; z <= maxZ; z++)
                {
                    this.tiles[x, z].draw(
                        graphics,
                        effect,
                        camera,
                        this,
                        x,
                        z);
                }
            }


            // Draw the items in the world.
            foreach (Item item in items)
            {
                // Don't draw the item if no model is returned...
                if (item.getModel() == null)
                {
                    continue;
                }


                Vector3 itemPosition = new Vector3(
                    item.position.X,
                    this.getHeightAtPoint(item.position.X, item.position.Y),
                    item.position.Y);

                //TODO: Rotate the item based on the position normal.

                ModelResources.renderModel(
                    item.getModel(),
                    camera,
                    itemPosition,
                    new Vector3(0.0F, item.rotation, 0.0F),
                    item.getCustomScaling());
            }


            // Draw the clouds
            Tile.renderClouds(graphics, effect, camera);
        }