コード例 #1
0
ファイル: HUDRenderable.cs プロジェクト: cfo82/Magmageddon
        void OnPowerupPickup(Vector3 nextPowerupPickupPosition, String notification)
        {
            PowerupPickupDetails details = new PowerupPickupDetails();

            details.Position     = nextPowerupPickupPosition;
            details.Notification = notification;
            details.Age          = 0;
            powerupPickupDetails.Add(details);
        }
コード例 #2
0
ファイル: HUDRenderable.cs プロジェクト: cfo82/Magmageddon
        private void DrawStrings(Renderer renderer)
        {
            double dt = currentFrameTime - lastFrameTime;

            spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, null, null, null, null, spriteScale);
            Vector3 textColor = defaultTextColor * (1 - frozenColorStrength.Value) + frozenTextColor * frozenColorStrength.Value;


            // draw the player name
            Vector2 playerNameSize      = playerNameFont.MeasureString(playerName.ToUpper());
            Vector2 playerNamePos       = new Vector2(xStart + 50, yStart) + multiplier * (new Vector2(170, 117) - playerNameSize);
            Vector2 playerNameShadowPos = playerNamePos + textShadowOffset;

            spriteBatch.DrawString(playerNameFont, playerName.ToUpper(), playerNameShadowPos, Color.DimGray);
            spriteBatch.DrawString(playerNameFont, playerName.ToUpper(), playerNamePos, new Color(textColor));

            // draw the current powerup status, if any
            string  powerupString     = PowerupString();
            Vector2 powerupStringSize = powerupStatusFont.MeasureString(powerupString);
            Vector2 powerupPos        = new Vector2(xStart + 52, yStart + 21) + invMultiplier * (new Vector2(165, 71) - powerupStringSize);
            Vector2 powerupShadowPos  = powerupPos + textShadowOffset;

            spriteBatch.DrawString(powerupStatusFont, powerupString, powerupShadowPos, Color.DimGray);
            spriteBatch.DrawString(powerupStatusFont, powerupString, powerupPos, new Color(Vector3.One * statusColorStrength.Value));

            // draw the number of lives
            string  livesString       = lives.ToString();
            Vector2 livesStringSize   = powerupStatusFont.MeasureString(livesString);
            Vector2 livesCenterOffset = new Vector2((int)livesStringSize.X / 2, (int)livesStringSize.Y / 2);
            //Viewport v = Game.Instance.GraphicsDevice.Viewport
            //            Vector2 livesPos = new Vector2(xStart + 19, yStart + 50) + multiplier * (new Vector2(236*v.Width/1280, 21*v.Height/720) - livesStringSize * 0.25f) - livesCenterOffset;
            Vector2 livesPos = new Vector2(xStart + 19, yStart + 50) + multiplier * (new Vector2(236, 21) - livesStringSize * 0.25f) - livesCenterOffset;

            spriteBatch.DrawString(livesFont, livesString, livesPos, Color.White * 0.85F);

            for (int i = powerupPickupDetails.Count - 1; i >= 0; i--)
            {
                PowerupPickupDetails details = powerupPickupDetails[i];
                string  detailsString        = details.Notification;
                Vector2 detailsStringSize    = powerupStatusFont.MeasureString(detailsString);
                Vector2 detailsCenterOffset  = new Vector2((int)detailsStringSize.X / 2, (int)detailsStringSize.Y / 2);

                // compute projected position
                Vector3 projection = Vector3.Transform(details.Position, renderer.Camera.CenterView * renderer.Camera.Projection);
                Vector2 detailsPos = new Vector2(projection.X / projection.Z, projection.Y / projection.Z);
                detailsPos   = detailsPos / 2 + new Vector2(0.5f, 0.5f / renderer.Camera.AspectRatio);
                detailsPos.Y = 1.0f / renderer.Camera.AspectRatio - detailsPos.Y;
                detailsPos  *= Game.Instance.GraphicsDevice.Viewport.Width;

                // apply age effect
                //detailsPos.Y -= (float)dt * PowerupNotificationFadeoutVerticalSpeed * details.Age;
                //details.Age += (float)dt * PowerupNotificationAgeStep;


                detailsPos.Y -= PowerupNotificationFadeoutVerticalSpeed * details.Age;
                details.Age  += PowerupNotificationAgeStep;

                // draw it
                Vector2 detailsShadowPos = detailsPos + textShadowOffset;
                spriteBatch.DrawString(powerupCollectFont, detailsString, detailsShadowPos, Color.DimGray * (1.0f - details.Age));
                spriteBatch.DrawString(powerupCollectFont, detailsString, detailsPos, Color.White * (1.0f - details.Age));

                if (details.Age >= 1.0f)
                {
                    powerupPickupDetails.RemoveAt(i);
                }
            }

            spriteBatch.End();
        }