Exemplo n.º 1
0
 /// <summary>
 /// Render black bar
 /// </summary>
 /// <param name="yPos">Y position</param>
 /// <param name="height">Height</param>
 public void RenderBlackBar(int yPos, int height)
 {
     buttons.RenderOnScreen(
         BaseGame.CalcRectangle(0, yPos, 1024, height),
         BlackBarGfxRect,
         ColorHelper.ApplyAlphaToColor(Color.White, 0.85f));
 }
Exemplo n.º 2
0
        /// <summary>
        /// Render all time fadeup effects, move them up and fade them out.
        /// </summary>
        public void RenderTimeFadeupEffects()
        {
            for (int num = 0; num < fadeupTexts.Count; num++)
            {
                TimeFadeupText fadeupText = fadeupTexts[num];
                fadeupText.showTimeMs -= BaseGame.ElapsedTimeThisFrameInMilliseconds;
                if (fadeupText.showTimeMs < 0)
                {
                    fadeupTexts.Remove(fadeupText);
                    num--;
                }
                else
                {
                    // Fade out
                    float alpha = 1.0f;
                    if (fadeupText.showTimeMs < 1500)
                    {
                        alpha = fadeupText.showTimeMs / 1500.0f;
                    }
                    // Move up
                    float moveUpAmount =
                        (TimeFadeupText.MaxShowTimeMs - fadeupText.showTimeMs) /
                        TimeFadeupText.MaxShowTimeMs;

                    // Calculate screen position
                    TextureFont.WriteTextCentered(BaseGame.Width / 2,
                                                  BaseGame.Height / 3 - (int)(moveUpAmount * BaseGame.Height / 3),
                                                  fadeupText.text,
                                                  ColorHelper.ApplyAlphaToColor(fadeupText.color, alpha),
                                                  2.25f);
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Render menu background
        /// </summary>
        public void RenderMenuBackground()
        {
            BaseGame.UI.UpdateCarInMenu();

            // Render game background
            RenderGameBackground();

            // And show track
            RenderMenuTrackBackground();

            // Render background with transparency
            // The background itself should be rendered before this ^^
            background.RenderOnScreen(
                BaseGame.ResolutionRect, BackgroundGfxRect,
                ColorHelper.ApplyAlphaToColor(Color.White, 0.85f));

            // Show RacingGame logo bouncing with the music
            float bounceSize = 1.005f +
                               (float)Math.Sin(BaseGame.TotalTime / 0.46f) * 0.045f *
                               (float)Math.Cos(BaseGame.TotalTime / 0.285f);

            background.RenderOnScreen(
                BaseGame.CalcRectangleWithBounce(362, 36, 601, 218, bounceSize),
                RacingGameLogoGfxRect);
        }
        /// <summary>
        /// Write digit
        /// </summary>
        /// <param name="x">X</param>
        /// <param name="y">Y</param>
        /// <param name="digit">Digit</param>
        /// <param name="alpha">Alpha</param>
        /// <returns>Int</returns>
        private static int WriteDigit(int x, int y, int digit, float alpha)
        {
            float resScalingX = (float)BaseGame.Width / 1600.0f;
            float resScalingY = (float)BaseGame.Height / 1200.0f;

            Rectangle rect = BigNumberRects[digit % BigNumberRects.Length];

            BaseGame.UI.Ingame.RenderOnScreen(new Rectangle(x, y,
                                                            (int)Math.Round(rect.Width * resScalingX),
                                                            (int)Math.Round(rect.Height * resScalingY)), rect,
                                              ColorHelper.ApplyAlphaToColor(Color.White, alpha));

            return((int)Math.Round(rect.Width * resScalingX));
        }
Exemplo n.º 5
0
        }         // SetHitDirectionEffect(direction)

        /// <summary>
        /// Show hit direction effect
        /// </summary>
        public void ShowHitDirectionEffect()
        {
            if (hitDirectionEffectTimeoutMs > 0)
            {
                hitDirectionEffectTimeoutMs -= (int)BaseGame.ElapsedTimeThisFrameInMs;

                hitDirectionTexture.RenderOnScreenWithRotation(
                    new Point(BaseGame.Width / 2,
                              BaseGame.Height / 2),
                    BaseGame.Height / 2,
                    (float)Math.PI + hitDirection,
                    hitDirectionTexture.GfxRectangle,                    //0, 0, 1, 1,
                    ColorHelper.ApplyAlphaToColor(
                        Color.White,
                        // Use 1.0f for first second, then fade out.
                        Math.Min(1.0f,
                                 (hitDirectionEffectTimeoutMs /
                                  ((float)MaxHitDirectionTimeoutMs / 2.0f)))));
            }     // if
        }         // ShowHitDirectionEffect()
Exemplo n.º 6
0
 /// <summary>
 /// 绘制并更新自己
 /// </summary>
 public void Draw()
 {
     if (frameRePlatforms <= 0)
     {
         ended = true;
         return;
     }
     else
     {
         frameRePlatforms--;
         curDest += step;
         color    = ColorHelper.ApplyAlphaToColor(color, CalAlpha());
         if (inLogic)
         {
             BaseGame.FontMgr.DrawInScrnCoord(text, BaseGame.CoordinMgr.ScreenPos(pos) - new Vector2(0, curDest), scale, color, layerDepth, fontType);
         }
         else
         {
             BaseGame.FontMgr.DrawInScrnCoord(text, pos - new Vector2(0, curDest), scale, color, layerDepth, fontType);
         }
     }
 }
        }         // RenderOnScreen(rect, pixelRect, color)

        /// <summary>
        /// Render texture at rect directly on screen using texture cordinates.
        /// This method allows to render with specific color and alpha values.
        /// </summary>
        /// <param name="rect">Rectangle</param>
        /// <param name="pixelRect">Pixel rectangle</param>
        /// <param name="color">Color</param>
        public void RenderOnScreen(Rectangle rect, Rectangle pixelRect,
                                   Color color, float alphaValue)
        {
            SpriteHelper.AddSpriteToRender(this, rect, pixelRect,
                                           ColorHelper.ApplyAlphaToColor(color, alphaValue));
        }         // RenderOnScreen(rect, pixelRect, color)
Exemplo n.º 8
0
        /// <summary>
        /// Render lens flare.
        /// Checks the zbuffer if objects are occluding the lensflare sun.
        /// </summary>
        public void Render(Color sunColor)
        {
            ScreenFlareSize = 250 * BaseGame.Width / 1024;
            Vector3 relativeLensPos = lensOrigin3D + BaseGame.CameraPos;

            // Only show lens flare if facing in the right direction
            if (BaseGame.IsInFrontOfCamera(relativeLensPos) == false)
            {
                return;
            }

            // Convert 3D point to 2D!
            Point lensOrigin =
                BaseGame.Convert3DPointTo2D(relativeLensPos);

            // Check sun occlusion itensity and fade it in and out!
            float thisSunIntensity = 0.75f;

            /*unsupported in XNA: BaseGame.OcclusionIntensity(
             *   flareMaterials[SunFlareType].diffuseTexture,
             *   lensOrigin, ScreenFlareSize / 5);
             */
            sunIntensity = thisSunIntensity * 0.1f + sunIntensity * 0.9f;

            // We can skip rendering the sun if the itensity is to low
            if (sunIntensity < 0.01f)
            {
                return;
            }

            int resWidth    = BaseGame.Width,
                resHeight   = BaseGame.Height;
            Point center    = new Point(resWidth / 2, resHeight / 2);
            Point relOrigin = new Point(
                center.X - lensOrigin.X, center.Y - lensOrigin.Y);

            // Check if origin is on screen, fade out at borders
            float alpha    = 1.0f;
            float distance = Math.Abs(Math.Max(relOrigin.X, relOrigin.Y));

            if (distance > resHeight / 1.75f)
            {
                distance -= resHeight / 1.75f;
                // If distance is more than half the resolution, don't show anything!
                if (distance > resHeight / 1.75f)
                {
                    return;
                }
                alpha = 1.0f - (distance / ((float)resHeight / 1.75f));
                if (alpha > 1.0f)
                {
                    alpha = 1.0f;
                }
            }

            // Use square of sunIntensity for lens flares because we want
            // them to get very weak if sun is not fully visible.
            alpha *= sunIntensity * sunIntensity;

            foreach (FlareData data in flareTypes)
            {
                int size = (int)(ScreenFlareSize * data.scale);
                flareTextures[data.type].RenderOnScreen(
                    new Rectangle(
                        (int)(center.X - relOrigin.X * data.position - size / 2),
                        (int)(center.Y - relOrigin.Y * data.position - size / 2),
                        size, size),
                    flareTextures[data.type].GfxRectangle,
                    ColorHelper.ApplyAlphaToColor(//MixAlphaToColor(
                        ColorHelper.MultiplyColors(sunColor, data.color),
                        ((float)data.color.A / 255.0f) *
                        // For the sun and glow flares try always to use max. intensity
                        (data.type == SunFlareType || data.type == GlowFlareType ?
                         sunIntensity : alpha)),
                    SpriteBlendMode.Additive);
            }
        }
Exemplo n.º 9
0
        }                                           // ShowAllItems(useShader)

        #endregion

        #region Render
        /// <summary>
        /// Render, most performance critical method of the game.
        /// Renders all asteroids and handles all physics, updating, etc.
        /// We use instancing to speed up asteroid rendering!
        /// </summary>
        public void Render(Texture inGameTexture, Texture lightEffectTexture)
        {
            #region Initialize
            // Use alpha blending for blending out asteroids
            BaseGame.EnableAlphaBlending();

            // Get camera position, no need to call the property 1 mio times.
            Vector3 cameraPos = BaseGame.CameraPos;

            // Empty display distance list
            remToDisplayDistance.Clear();
            #endregion

            #region Show target behind asteroids
            // Show target icon behind all asteroids and items (only in game)
            if (inGameTexture != null)
            {
                // First find out where the target is.
                Point screenPos = BaseGame.Convert3DPointTo2D(TargetPosition);
                bool  isVisible = BaseGame.IsInFrontOfCamera(TargetPosition);

                if (isVisible &&
                    screenPos.X >= 0 && screenPos.X < BaseGame.Width &&
                    screenPos.Y >= 0 && screenPos.Y < BaseGame.Height)
                {
                    // From Mission.cs:70.
                    Rectangle TargetIconRect = new Rectangle(106, 49, 61, 61);

                    // Render target icon centered at screenPos
                    // Note: This will be blurred because we render it before
                    // the glow/bloom/motion blur shader is applied, but if we
                    // render after that we can't render behind the asteroids.
                    // See Mission.RenderTarget!
                    inGameTexture.RenderOnScreen(new Rectangle(
                                                     screenPos.X - TargetIconRect.Width / 2,
                                                     screenPos.Y - TargetIconRect.Height / 2,
                                                     TargetIconRect.Width, TargetIconRect.Height),
                                                 TargetIconRect, Color.White, SpriteBlendMode.Additive);
                }         // if (isVisible)
            }             // if (inGameTexture)
            #endregion

            #region Show glow behind items
            // Show glow behind all items
            for (int num = 0; num < Level.NumOfItemTypes; num++)
            {
                // Go through all items of this type
                foreach (Vector3 pos in items[num])
                {
                    // Get distance to viewer
                    float distance = (pos - cameraPos).Length();

                    // Skip if out of visible range * 6
                    if (distance > MaxViewDepth * 6 ||
                        BaseGame.IsInFrontOfCamera(pos) == false)
                    {
                        continue;
                    }

                    // Convert to screen coordinates
                    Point screenPos = BaseGame.Convert3DPointTo2D(pos);
                    int   glowSize  = 36 * BaseGame.Width / 1024;

                    // If not visible, skip!
                    if (screenPos.X < -glowSize ||
                        screenPos.Y < -glowSize ||
                        screenPos.X > BaseGame.Width + glowSize ||
                        screenPos.Y > BaseGame.Height + glowSize)
                    {
                        continue;
                    }

                    // Calculate alpha
                    float alpha = 1.0f;
                    if (distance > MaxViewDepth * 4)
                    {
                        alpha = 1.0f -
                                ((distance - MaxViewDepth * 4) / (MaxViewDepth * (6 - 4)));
                    }

                    // Show glow with help of light effect
                    if (lightEffectTexture != null)
                    {
                        lightEffectTexture.RenderOnScreen(
                            new Rectangle(screenPos.X - glowSize, screenPos.Y - glowSize,
                                          glowSize * 2, glowSize * 2),
                            lightEffectTexture.GfxRectangle,
                            ColorHelper.ApplyAlphaToColor(ItemColors[num], alpha * 0.5f),
                            SpriteBlendMode.Additive);
                    }

                    // And display distance to item below it (not here, see below).
                    float textAlpha = alpha * 1.5f *
                                      (1.0f - (distance / (MaxViewDepth * 6)));
                    AddDistanceToBeDisplayed(screenPos, distance,
                                             textAlpha < 1.0f ? textAlpha : 1.0f);
                }         // foreach (pos)
            }             // for (num)

            // Flush all glow sprites on the screen (before rendering asteroids!)
            SpriteHelper.DrawSprites();
            #endregion

            #region Render 3d models, especially the asteroids
            // Draw goal at target position
            goalModel.Render(Matrix.CreateScale(100) *
                             Matrix.CreateRotationX(-(float)Math.PI / 2.0f) *
                             Matrix.CreateTranslation(TargetPosition));

            // Call base render method, target and item glow is behind of the
            // asteroids.
            base.RenderAsteroids();
            #endregion
        }         // Render()
        }         // WriteTextCentered(x, y, text)

        /// <summary>
        /// Write text centered
        /// </summary>
        /// <param name="x">X</param>
        /// <param name="y">Y</param>
        /// <param name="text">Text</param>
        /// <param name="col">Color</param>
        /// <param name="alpha">Alpha</param>
        public static void WriteTextCentered(int x, int y, string text,
                                             Color col, float alpha)
        {
            WriteText(x - BaseGame.GameFont.GetTextWidth(text) / 2, y, text,
                      ColorHelper.ApplyAlphaToColor(col, alpha));
        }         // WriteTextCentered(x, y, text)