Esempio n. 1
0
 //
 // Zusammenfassung:
 //     Called when the DrawableGameComponent needs to be drawn.  Override this method
 //     with component-specific drawing code.
 //
 // Parameter:
 //   gameTime:
 //     Time passed since the last call to Microsoft.Xna.Framework.DrawableGameComponent.Draw(Microsoft.Xna.Framework.GameTime).
 public override void Draw(GameTime gameTime)
 {
     if (spriteBatch != null)
     {
         spriteBatch.Begin();
         foreach (HudControl x in this.controls)
         {
             HudTextControl   text   = x as HudTextControl;
             HudSpriteControl sprite = x as HudSpriteControl;
             Hud3DControl     model  = x as Hud3DControl;
             if (text != null)
             {
                 text.Draw(spriteBatch, font);
             }
             if (sprite != null)
             {
                 sprite.Draw(spriteBatch);
             }
             if (model != null)
             {
                 model.Draw(spriteBatch);
             }
         }
         foreach (HudTextControl x in this.scrollingText)
         {
             if (x != null)
             {
                 x.Draw(spriteBatch, font);
             }
         }
         spriteBatch.End();
     }
 }
Esempio n. 2
0
 public HudBarControl(string name, GameTime gameTime, ICanyonShooterGame game, String text, SpriteFont font, String background, Vector2 pos, Vector2 size, float timeToLive, Anchor anchor, HUDEffectType effect)
     : base(name, gameTime, pos, pos, timeToLive, anchor, effect)
 {
     tc    = new HudTextControl(name + "_text", gameTime, text, font, new Color(), pos, timeToLive, anchor, effect);
     sc    = new HudSpriteControl(name + "_sprite", gameTime, game, size, background, pos, timeToLive, anchor, effect);
     Value = 100;
 }
Esempio n. 3
0
        public bool CreateSpriteControl(string name, string texture, Vector2 pos, Vector2 size)
        {
            // Temporary solution by Manuel Rodriguez.
            IHudSpriteControl sc = new HudSpriteControl(name, new GameTime(), this.game, size, texture, pos, 0, Anchor.CENTER, HUDEffectType.NONE);

            controls.Add(sc);
            if (controls.Contains(sc))
            {
                return(true);
            }
            return(false);
            //throw new Exception("Not Implemented yet!");
            //return true;
        }
Esempio n. 4
0
        public bool CreateSpriteControl(string name, string texture, Vector2 pos, Vector2 size)
        {
            // Temporary solution by Manuel Rodriguez.
            IHudSpriteControl sc = new HudSpriteControl(name, new GameTime(), this.game, size, texture, pos, 0, Anchor.CENTER, HUDEffectType.NONE);

            AddControl(sc);
            sc.Resolution = new Vector2(game.Graphics.Device.Viewport.Width, game.Graphics.Device.Viewport.Height);
            if (controls.ContainsKey(sc.Name))
            {
                return(true);
            }
            return(false);
            //throw new Exception("Not Implemented yet!");
            //return true;
        }
Esempio n. 5
0
        /// <summary>
        /// Called when the DrawableGameComponent needs to be drawn.  Override this method with component-specific drawing code.
        /// </summary>
        /// <param name="gameTime">Time passed since the last call to Microsoft.Xna.Framework.DrawableGameComponent.Draw(Microsoft.Xna.Framework.GameTime).</param>
        public override void Draw(GameTime gameTime)
        {
            if (spriteBatch != null)
            {
                spriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Deferred, SaveStateMode.SaveState,
                                  Matrix.CreateScale(game.Graphics.ScreenWidth, game.Graphics.ScreenHeight, 1));

                // DRAW HUD2 - BACK LAYER
                spriteBatch.Draw(hudBack, new Rectangle(0, 0, 1, 1), Color.White);
                spriteBatch.End();


                spriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Texture, SaveStateMode.None);
                // HEALTH, SHIELD
                DrawVerticalBarAt(hudHealthBar, new Vector2(0.027f, 0.829f), game.World.Players[0].Health, 100);
                DrawVerticalBarAt(hudShieldBar, new Vector2(0.09f, 0.829f), game.World.Players[0].Shield, 250);
                // BOOST
                DrawHorizontalBarAt(hudBoostBar, new Vector2(0.144f, 0.932f), game.World.Players[0].BoosterHeat, 100);
                // FUEL
                DrawVerticalBarAt(hudFuelBar, new Vector2(0.007f, 0.128f), (int)((Player2)game.World.Players[0]).Fuel, (int)((Player2)game.World.Players[0]).MaxFuel);

                #region HUD-Controls

                // DRAW CONTROLS
                foreach (HudControl x in controls.Values)
                {
                    HudTextControl   text   = x as HudTextControl;
                    HudSpriteControl sprite = x as HudSpriteControl;
                    Hud3DControl     model  = x as Hud3DControl;
                    HudBarControl    bar    = x as HudBarControl;
                    if (text != null)
                    {
                        text.Draw(spriteBatch);
                    }
                    if (sprite != null)
                    {
                        sprite.Draw(spriteBatch);
                    }
                    if (model != null)
                    {
                        model.Draw(spriteBatch);
                    }
                    if (bar != null)
                    {
                        bar.Draw(spriteBatch, font);
                    }
                }
                foreach (HudTextControl x in this.scrollingText)
                {
                    if (x != null)
                    {
                        x.Draw(spriteBatch);
                    }
                }

                spriteBatch.End();
                #endregion

                spriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Texture, SaveStateMode.SaveState,
                                  Matrix.CreateScale(game.Graphics.ScreenWidth, game.Graphics.ScreenHeight, 1));



                // DRAW HUD2 - FRONT LAYER
                spriteBatch.Draw(hudFront, new Rectangle(0, 0, 1, 1), Color.White);

                if (currentCrossHair != null)
                {
                    float   scale             = 4f;
                    Vector2 crossHairPosition = new Vector2(
                        0.5f - ((currentCrossHair.Width) * (0.05f * scale / game.Graphics.ScreenWidth)),
                        0.55f - ((currentCrossHair.Height) * (0.05f * scale / game.Graphics.ScreenHeight)));

                    spriteBatch.Draw(currentCrossHair, crossHairPosition,
                                     new Rectangle(0, 0, currentCrossHair.Width, currentCrossHair.Height), Color.White,
                                     0, new Vector2(0.5f, 0.5f),
                                     new Vector2(0.1f * scale / game.Graphics.ScreenWidth, 0.1f * scale / game.Graphics.ScreenHeight),
                                     SpriteEffects.None, 0.5f);
                }


                if (((Player2)game.World.Players[0]).Weapons.PrimaryWeapon != null)
                {
                    Texture2D icon = ((Player2)game.World.Players[0]).Weapons.PrimaryWeapon.Icon;
                    spriteBatch.Draw(icon, new Vector2(0.703f, 0.924f),
                                     new Rectangle(0, 0, icon.Width, icon.Height), Color.White,
                                     0, new Vector2(0.5f, 0.5f),
                                     new Vector2(1f / game.Graphics.ScreenWidth, 1f / game.Graphics.ScreenHeight),
                                     SpriteEffects.None, 0.5f);
                }

                if (((Player2)game.World.Players[0]).Weapons.SecondaryWeapon != null)
                {
                    Texture2D icon = ((Player2)game.World.Players[0]).Weapons.SecondaryWeapon.Icon;
                    spriteBatch.Draw(icon, new Vector2(0.818f, 0.924f),
                                     new Rectangle(0, 0, icon.Width, icon.Height), Color.White,
                                     0, new Vector2(0.5f, 0.5f),
                                     new Vector2(1f / game.Graphics.ScreenWidth, 1f / game.Graphics.ScreenHeight),
                                     SpriteEffects.None, 0.5f);
                }

                #region BOOSTER-WARNING

                if (showWarning)
                {
                    if (!alert.Playing())
                    {
                        alert.Play();
                    }
                    warningGlowCount--;

                    if (warningGlowCount <= 0)
                    {
                        warningFpsCount++;
                    }
                    if (warningFpsCount > 8)
                    {
                        warningVisible   = !warningVisible;
                        warningFpsCount  = 0;
                        warningGlowCount = 3;
                    }

                    if (warningVisible)
                    {
                        if (warningGlowCount > 0)
                        {
                            spriteBatch.Draw(hudBoosterWarning,
                                             new Rectangle(0, 0, 1, 1),
                                             new Color(255, 255, 255, (byte)(255 / warningGlowCount)));
                        }
                        else
                        {
                            spriteBatch.Draw(hudBoosterWarning,
                                             new Rectangle(0, 0, 1, 1),
                                             new Color(255, 255, 255, 255));
                        }
                    }
                }
                else
                {
                    alert.Stop();
                }
                #endregion

                spriteBatch.End();
            }
        }