Exemplo n.º 1
0
        /// <summary>
        /// Render game user interface
        /// </summary>
        /// <param name="currentGameTime">Current game time</param>
        /// <param name="bestLapTime">Best lap time</param>
        /// <param name="lapNumber">Lap number</param>
        /// <param name="speed">Speed</param>
        /// <param name="gear">Gear</param>
        /// <param name="trackName">Track name</param>
        /// <param name="top5LapTimes">Top 5 lap times</param>
        public void RenderGameUI(int currentGameTime, int bestLapTime,
                                 int lapNumber, float speed, int gear, float acceleration,
                                 string trackName, int[] top5LapTimes)
        {
            if (top5LapTimes == null)
            {
                throw new ArgumentNullException("top5LapTimes");
            }

            Color baseUIColor = Color.White;//ColorHelper.HalfAlpha;

            // If game is over, set speed, gear and acceleration to 0
            if (RacingGameManager.Player.GameOver)
            {
                speed        = 0;
                gear         = 1;
                acceleration = 0;
            }

            // More distance to the screen borders on the Xbox 360 to fit better into
            // the save region. Calculate all rectangles for each platform,
            // then they will be used the same way on both platforms.
#if XBOX360
            // Draw all boxes and background stuff
            Rectangle lapsRect = BaseGame.CalcRectangle1600(
                60, 46, LapsGfxRect.Width, LapsGfxRect.Height);
            ingame.RenderOnScreen(lapsRect, LapsGfxRect, baseUIColor);

            Rectangle timesRect = BaseGame.CalcRectangle1600(
                60, 46, CurrentAndBestGfxRect.Width, CurrentAndBestGfxRect.Height);
            timesRect.Y = BaseGame.Height - timesRect.Bottom;
            ingame.RenderOnScreen(timesRect, CurrentAndBestGfxRect, baseUIColor);

            Rectangle trackNameRect = BaseGame.CalcRectangle1600(
                60, 46, TrackNameGfxRect.Width, TrackNameGfxRect.Height);
            trackNameRect.X = BaseGame.Width - trackNameRect.Right;
            ingame.RenderOnScreen(trackNameRect, TrackNameGfxRect, baseUIColor);
            Rectangle top5Rect1 = BaseGame.CalcRectangle1600(
                60, 4, Best5GfxRect.Width, Best5GfxRect.Height);
            top5Rect1.X = trackNameRect.X;
            int top5Distance = top5Rect1.Y;
            top5Rect1.Y += trackNameRect.Bottom;
            ingame.RenderOnScreen(top5Rect1, Best5GfxRect, baseUIColor);
            Rectangle top5Rect2 = new Rectangle(top5Rect1.X,
                                                top5Rect1.Bottom + top5Distance, top5Rect1.Width, top5Rect1.Height);
            ingame.RenderOnScreen(top5Rect2, Best5GfxRect, baseUIColor);
            Rectangle top5Rect3 = new Rectangle(top5Rect1.X,
                                                top5Rect2.Bottom + top5Distance, top5Rect1.Width, top5Rect1.Height);
            ingame.RenderOnScreen(top5Rect3, Best5GfxRect, baseUIColor);
            Rectangle top5Rect4 = new Rectangle(top5Rect1.X,
                                                top5Rect3.Bottom + top5Distance, top5Rect1.Width, top5Rect1.Height);
            ingame.RenderOnScreen(top5Rect4, Best5GfxRect, baseUIColor);
            Rectangle top5Rect5 = new Rectangle(top5Rect1.X,
                                                top5Rect4.Bottom + top5Distance, top5Rect1.Width, top5Rect1.Height);
            ingame.RenderOnScreen(top5Rect5, Best5GfxRect, baseUIColor);

            Rectangle tachoRect = BaseGame.CalcRectangle1600(
                60, 46, TachoGfxRect.Width, TachoGfxRect.Height);
            tachoRect.X = BaseGame.Width - tachoRect.Right;
            tachoRect.Y = BaseGame.Height - tachoRect.Bottom;
#else
            // Draw all boxes and background stuff
            Rectangle lapsRect = BaseGame.CalcRectangle1600(
                10, 10, LapsGfxRect.Width, LapsGfxRect.Height);
            ingame.RenderOnScreen(lapsRect, LapsGfxRect, baseUIColor);

            Rectangle timesRect = BaseGame.CalcRectangle1600(
                10, 10, CurrentAndBestGfxRect.Width, CurrentAndBestGfxRect.Height);
            timesRect.Y = BaseGame.Height - timesRect.Bottom;
            ingame.RenderOnScreen(timesRect, CurrentAndBestGfxRect, baseUIColor);

            Rectangle trackNameRect = BaseGame.CalcRectangle1600(
                10, 10, TrackNameGfxRect.Width, TrackNameGfxRect.Height);
            trackNameRect.X = BaseGame.Width - trackNameRect.Right;
            ingame.RenderOnScreen(trackNameRect, TrackNameGfxRect, baseUIColor);
            Rectangle top5Rect1 = BaseGame.CalcRectangle1600(
                10, 4, Best5GfxRect.Width, Best5GfxRect.Height);
            top5Rect1.X = trackNameRect.X;
            int top5Distance = top5Rect1.Y;
            top5Rect1.Y += trackNameRect.Bottom;
            ingame.RenderOnScreen(top5Rect1, Best5GfxRect, baseUIColor);
            Rectangle top5Rect2 = new Rectangle(top5Rect1.X,
                                                top5Rect1.Bottom + top5Distance, top5Rect1.Width, top5Rect1.Height);
            ingame.RenderOnScreen(top5Rect2, Best5GfxRect, baseUIColor);
            Rectangle top5Rect3 = new Rectangle(top5Rect1.X,
                                                top5Rect2.Bottom + top5Distance, top5Rect1.Width, top5Rect1.Height);
            ingame.RenderOnScreen(top5Rect3, Best5GfxRect, baseUIColor);
            Rectangle top5Rect4 = new Rectangle(top5Rect1.X,
                                                top5Rect3.Bottom + top5Distance, top5Rect1.Width, top5Rect1.Height);
            ingame.RenderOnScreen(top5Rect4, Best5GfxRect, baseUIColor);
            Rectangle top5Rect5 = new Rectangle(top5Rect1.X,
                                                top5Rect4.Bottom + top5Distance, top5Rect1.Width, top5Rect1.Height);
            ingame.RenderOnScreen(top5Rect5, Best5GfxRect, baseUIColor);

            Rectangle tachoRect = BaseGame.CalcRectangle1600(
                10, 10, TachoGfxRect.Width, TachoGfxRect.Height);
            tachoRect.X = BaseGame.Width - tachoRect.Right;
            tachoRect.Y = BaseGame.Height - tachoRect.Bottom;
#endif

            // Rest can stay the same because we use the rectangles from now on
            ingame.RenderOnScreen(tachoRect, TachoGfxRect, baseUIColor);

            // Ok, now add the numbers, text and speed values
            TextureFontBigNumbers.WriteNumber(
                lapsRect.X + BaseGame.XToRes1600(15),
                lapsRect.Y + BaseGame.YToRes1200(12),
                lapNumber);

            // Current and best game times
            Color highlightColor = new Color(255, 185, 80);
            int   blockHeight    = BaseGame.YToRes1200(74);
            TextureFont.WriteGameTime(
                timesRect.X + BaseGame.XToRes1600(154),
                timesRect.Y + blockHeight / 2 - TextureFont.Height / 2,
                currentGameTime,
                highlightColor);
            TextureFont.WriteGameTime(
                timesRect.X + BaseGame.XToRes1600(154),
                timesRect.Y + timesRect.Height / 2 + blockHeight / 2 -
                TextureFont.Height / 2,
                bestLapTime,
                Color.White);

            // Track name
            TextureFont.WriteTextCentered(
                trackNameRect.X + trackNameRect.Width / 2,
                trackNameRect.Y + blockHeight / 2,
                trackName);

            // Top 5
            // Possible improvement: Show currentRank here (insert us)
            Color rankColor =
                bestLapTime == top5LapTimes[0] ?
                highlightColor : Color.White;
            TextureFont.WriteTextCentered(
                top5Rect1.X + BaseGame.XToRes(32) / 2,
                top5Rect1.Y + blockHeight / 2,
                "1.", rankColor, 1.0f);
            TextureFont.WriteGameTime(
                top5Rect1.X + BaseGame.XToRes(35 + 15),
                top5Rect1.Y + blockHeight / 2 - TextureFont.Height / 2,
                top5LapTimes[0], rankColor);

            rankColor =
                bestLapTime == top5LapTimes[1] ?
                highlightColor : Color.White;
            TextureFont.WriteTextCentered(
                top5Rect2.X + BaseGame.XToRes(32) / 2,
                top5Rect2.Y + blockHeight / 2,
                "2.", rankColor, 1.0f);
            TextureFont.WriteGameTime(
                top5Rect2.X + BaseGame.XToRes(35 + 15),
                top5Rect2.Y + blockHeight / 2 - TextureFont.Height / 2,
                top5LapTimes[1], rankColor);

            rankColor =
                bestLapTime == top5LapTimes[2] ?
                highlightColor : Color.White;
            TextureFont.WriteTextCentered(
                top5Rect3.X + BaseGame.XToRes(32) / 2,
                top5Rect3.Y + blockHeight / 2,
                "3.", rankColor, 1.0f);
            TextureFont.WriteGameTime(
                top5Rect3.X + BaseGame.XToRes(35 + 15),
                top5Rect3.Y + blockHeight / 2 - TextureFont.Height / 2,
                top5LapTimes[2], rankColor);

            rankColor =
                bestLapTime == top5LapTimes[3] ?
                highlightColor : Color.White;
            TextureFont.WriteTextCentered(
                top5Rect4.X + BaseGame.XToRes(32) / 2,
                top5Rect4.Y + blockHeight / 2,
                "4.", rankColor, 1.0f);
            TextureFont.WriteGameTime(
                top5Rect4.X + BaseGame.XToRes(35 + 15),
                top5Rect4.Y + blockHeight / 2 - TextureFont.Height / 2,
                top5LapTimes[3], rankColor);

            rankColor =
                bestLapTime == top5LapTimes[4] ?
                highlightColor : Color.White;
            TextureFont.WriteTextCentered(
                top5Rect5.X + BaseGame.XToRes(32) / 2,
                top5Rect5.Y + blockHeight / 2,
                "5.", rankColor, 1.0f);
            TextureFont.WriteGameTime(
                top5Rect5.X + BaseGame.XToRes(35 + 15),
                top5Rect5.Y + blockHeight / 2 - TextureFont.Height / 2,
                top5LapTimes[4], rankColor);

            // Acceleration
            Point tachoPoint = new Point(
                tachoRect.X +
                BaseGame.XToRes1600(194),
                tachoRect.Y +
                BaseGame.YToRes1200(194));
            //ingame.RenderOnScreenWithRotation(
            //    tachoPoint, TachoArrowGfxRect, -acceleration*2);
            if (acceleration < 0)
            {
                acceleration = 0;
            }
            if (acceleration > 1)
            {
                acceleration = 1;
            }
            float   rotation         = -2.33f + acceleration * 2.5f;
            int     tachoArrowWidth  = BaseGame.XToRes1600(TachoArrowGfxRect.Width);
            int     tachoArrowHeight = BaseGame.YToRes1200(TachoArrowGfxRect.Height);
            Vector2 rotationPoint    = new Vector2(
                TachoArrowGfxRect.Width / 2,
                TachoArrowGfxRect.Height - 13);
            ingame.RenderOnScreenWithRotation(
                new Rectangle(tachoPoint.X, tachoPoint.Y,
                              tachoArrowWidth, tachoArrowHeight),
                TachoArrowGfxRect,
                rotation, rotationPoint);

            // Speed in mph
            TextureFontBigNumbers.WriteNumber(
                tachoRect.X + BaseGame.XToRes1600(TachoMphGfxRect.X),
                tachoRect.Y + BaseGame.YToRes1200(TachoMphGfxRect.Y),
                TachoMphGfxRect.Height,
                (int)Math.Round(speed));

            // Gear
            TextureFontBigNumbers.WriteNumber(
                tachoRect.X + BaseGame.XToRes1600(TachoGearGfxRect.X),
                tachoRect.Y + BaseGame.YToRes1200(TachoGearGfxRect.Y),
                TachoGearGfxRect.Height,
                Math.Min(5, gear));
        }
Exemplo n.º 2
0
        /*not that easy without fixed function
        /// <summary>
        /// Select this texture as texture stage 0
        /// </summary>
        public virtual void Select()
        {
            if (xnaTexture != null)
                RCGame.device.sette.DirectXDevice.SetTexture(0, xnaTexture);
        } // Select()
         */

        #endregion Other

        #if DEBUG

        /*
        /// <summary>
        /// Test fullscreen texture
        /// </summary>
        //[Test]
        public static void TestFullscreenTextures()
        {
            Texture testTexture = null, testTexture2 = null;
            RaceGame.StartTest("TestFullscreenTextures",
                delegate
                {
                    testTexture = new Texture("MainMenu.dds");
                    testTexture2 = new Texture("MouseCursor.dds");
                },
                delegate
                {
                    // Fill background with crazy color
                    RaceGame.DirectXDevice.Clear(ClearFlags.Target,
                        Color.Aquamarine, 1, 0);

                    // Draw texture on top of it without any alpha!
                    RaceGame.DirectXDevice.RenderState.AlphaBlendEnable = false;
                    testTexture.RenderOnScreen(
                        GraphicForm.ResolutionRect,
                        new Rectangle(0, 0, 1024, 768));
                    testTexture2.RenderOnScreen(new Rectangle(0, 0,
                        testTexture2.Width, testTexture2.Height));
                });
        } // TestTextures()
         */
        /// <summary>
        /// Test rendering rotated texture
        /// </summary>
        //[Test]
        public static void TestRenderingRotatedTexture()
        {
            Texture testTexture = null;
            TestGame.Start("TestRenderingRotatedTexture",
                delegate
                {
                    testTexture = new Texture("landscape");
                },
                delegate
                {
                    testTexture.RenderOnScreen(
                        new Rectangle(0, 0, 100, 100),
                        new Rectangle(0, 0, 100, 100));

                    testTexture.RenderOnScreenWithRotation(
                        new Rectangle(100, 100, 150, 150),
                        new Rectangle(100, 100, 150, 150),
                        Input.MousePos.X / 100.0f,
                        new Vector2(50, 50));
                });
        }