Ejemplo n.º 1
0
        /// <summary>
        /// Draws some text from the given font
        /// </summary>
        /// <param name="spriteBatch">The sprite batch to use</param>
        /// <param name="fontStyle">Which font to use</param>
        /// <param name="x">X position in screen pixel space</param>
        /// <param name="y">Y position in screen pixel space</param>
        /// <param name="digits">The characters to draw</param>
        /// <param name="color">The color to draw it in</param>
        public static void Draw(RelativeSpriteBatch spriteBatch, FontStyle fontStyle,
                                int x, int y, string digits, Color color)
        {
            float    xPosition = x;
            FontInfo thisFont  = fontInfo[(int)fontStyle];

            for (int i = 0; i < digits.Length; i++)
            {
                //Don't draw anything if its a space character
                if (digits[i] != ' ')
                {
                    //Look up the character position
                    int character = thisFont.Characters.IndexOf(digits[i]);

                    //Draw the correct character at the correct position
                    spriteBatch.Draw(fontTextures[(int)fontStyle],
                                     new Vector2(xPosition, (float)y),
                                     new Rectangle(character * thisFont.CharacterSpacing +
                                                   thisFont.StartOffset, 0, thisFont.CharacterWidth,
                                                   thisFont.CharacterHeight), color);
                }

                //Move the position of the next character.
                //If the character is a comma or colon then use a 'fudge factor' to make
                //the font look a little proportional
                xPosition += ((digits[i] == ',' || digits[i] == ':') ?
                              thisFont.CharacterWidth / 2 : thisFont.CharacterWidth);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Tidies up the scene.
        /// </summary>
        public virtual void Shutdown()
        {
            ShutdownMusic();

            if (batch != null)
            {
                batch.Dispose();
                batch = null;
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Load your graphics content.
        /// </summary>
        protected override void LoadContent()
        {
            //Re-Create the Sprite Batch!
            IGraphicsDeviceService graphicsService =
                Game.Services.GetService(typeof(IGraphicsDeviceService))
                as IGraphicsDeviceService;

            batch = new RelativeSpriteBatch(graphicsService.GraphicsDevice);

            //Load content for any sub components

            if (!String.IsNullOrEmpty(backgroundImage))
            {
                backgroundTexture = MarbletsGame.Content.Load <Texture2D>(backgroundImage);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Draws the game board and all child objects
        /// </summary>
        /// <param name="spriteBatch">a sprite batch to use to draw any sprites</param>
        public void Draw(RelativeSpriteBatch spriteBatch)
        {
            if (spriteBatch == null)
            {
                return;
            }

            foreach (Marble marble in Marbles)
            {
                if (marble != null)
                {
                    marble.Draw(spriteBatch);
                }
            }

            if (!GameOver)
            {
                //Draw the cursor
                spriteBatch.Draw(marbleCursorTexture, BoardToScreen(cursorX, cursorY),
                                 Color.White);
            }

            if (!GameOver)
            {
                if (totalSelected > 0)
                {
                    Vector2 position = BoardToScreen(cursorX, cursorY) + scoreOffset;
                    Color   color    = Color.White;

                    if (AnimationState == Animation.Breaking)
                    {
                        //Slide the score up and fade it
                        position -= new Vector2(0, scoreFadeFactor * scoreFadeDistance);
                        color     = new Color(255, 255, 255,
                                              (byte)(255 * (1f - scoreFadeFactor)));
                    }

                    Font.Draw(spriteBatch, FontStyle.Large, position,
                              Score(totalSelected), color);
                }
            }
        }
Ejemplo n.º 5
0
        private void Draw2DMarble(RelativeSpriteBatch spriteBatch)
        {
            //Draw the 2d marble
            if (Animation == Animation.Breaking || Animation == Animation.Gone)
            {
                //Draw the correct frame.
                spriteBatch.Draw(breakTexture, Position, new Rectangle(frame * Width, 0,
                                                                       Width, Height), Color);
            }
            else
            {
                spriteBatch.Draw(marble, Position, Color);

                //Highlight selected marbles
                if (Selected)
                {
                    if (pulseFactor < 0.0)
                    {
                        //Make a new color with the correct transparency.
                        Color fade = new Color(255, 255, 255,
                                               (byte)(-pulseFactor * 255.0));

                        //pulse the single ring
                        spriteBatch.Draw(glowRing1Texture, Position, fade);
                    }
                    else
                    {
                        //pulse the double ring

                        //Make a new color with the correct transparency.
                        Color fade = new Color(255, 255, 255,
                                               (byte)(pulseFactor * 255.0));

                        spriteBatch.Draw(glowRing2Texture, Position, fade);
                    }
                }
            }
        }
Ejemplo n.º 6
0
		/// <summary>
		/// Load your graphics content.
		/// </summary>
		protected override void LoadContent()
		{
			//Re-Create the Sprite Batch!
			IGraphicsDeviceService graphicsService =
				Game.Services.GetService(typeof(IGraphicsDeviceService))
				as IGraphicsDeviceService;

			batch = new RelativeSpriteBatch(graphicsService.GraphicsDevice);

			//Load content for any sub components
			if (!String.IsNullOrEmpty(backgroundImage))
			{
				backgroundTexture =
					MarbletsGame.Content.Load<Texture2D>(backgroundImage);
			}
		}
Ejemplo n.º 7
0
		/// <summary>
		/// Tidies up the scene.
		/// </summary>
		public virtual void Shutdown()
		{
			ShutdownMusic();

			if (batch != null)
			{
				batch.Dispose();
				batch = null;
			}
		}
Ejemplo n.º 8
0
 /// <summary>
 /// Draws some text from the given font
 /// </summary>
 /// <param name="spriteBatch">The sprite batch to use</param>
 /// <param name="fontStyle">Which font to use</param>
 /// <param name="position">A vector x,y position</param>
 /// <param name="number">A number to draw</param>
 /// <param name="color">The color of the text</param>
 public static void Draw(RelativeSpriteBatch spriteBatch, FontStyle fontStyle,
     Vector2 position, int number, Color color)
 {
     Draw(spriteBatch, fontStyle, (int)position.X, (int)position.Y,
          number.ToString(), color);
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Draws some text from the given font
 /// </summary>
 /// <param name="spriteBatch">The sprite batch to use</param>
 /// <param name="fontStyle">Which font to use</param>
 /// <param name="x">X position in screen pixel space</param>
 /// <param name="y">Y position in screen pixel space</param>
 /// <param name="digits">The characters to draw</param>
 public static void Draw(RelativeSpriteBatch spriteBatch, FontStyle fontStyle,
     int x, int y, string digits)
 {
     //No color - use 'white' i.e. use whatever is in the file
     Draw(spriteBatch, fontStyle, x, y, digits, Color.White);
 }
Ejemplo n.º 10
0
 /// <summary>
 /// Draws some text from the given font
 /// </summary>
 /// <param name="spriteBatch">The sprite batch to use</param>
 /// <param name="fontStyle">Which font to use</param>
 /// <param name="x">X position in screen pixel space</param>
 /// <param name="y">Y position in screen pixel space</param>
 /// <param name="number">The number to draw</param>
 public static void Draw(RelativeSpriteBatch spriteBatch, FontStyle fontStyle,
     int x, int y, int number)
 {
     //No color - use 'white' i.e. use whatever is in the file
     Draw(spriteBatch, fontStyle, x, y, number.ToString(), Color.White);
 }
Ejemplo n.º 11
0
 /// <summary>
 /// Draws some text from the given font
 /// </summary>
 /// <param name="spriteBatch">The sprite batch to use</param>
 /// <param name="fontStyle">Which font to use</param>
 /// <param name="position">A vector x,y position</param>
 /// <param name="number">A number to draw</param>
 /// <param name="color">The color of the text</param>
 public static void Draw(RelativeSpriteBatch spriteBatch, FontStyle fontStyle,
                         Vector2 position, int number, Color color)
 {
     Draw(spriteBatch, fontStyle, (int)position.X, (int)position.Y,
          number.ToString(), color);
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Draws the specified marble
 /// </summary>
 /// <param name="spriteBatch">The sprite batch to use</param>
 public void Draw(RelativeSpriteBatch spriteBatch)
 {
     Draw2DMarble(spriteBatch);
 }
Ejemplo n.º 13
0
		/// <summary>
		/// Draws the game board and all child objects
		/// </summary>
		/// <param name="spriteBatch">a sprite batch to use to draw any sprites</param>
		public void Draw(RelativeSpriteBatch spriteBatch)
		{
			if (spriteBatch == null)
				return;

			foreach (Marble marble in Marbles)
			{
				if (marble != null)
				{
					marble.Draw(spriteBatch);
				}
			}

			if (!GameOver)
			{
				//Draw the cursor
				spriteBatch.Draw(marbleCursorTexture, BoardToScreen(cursorX, cursorY),
								 Color.White);
			}

			if (!GameOver)
			{
				if (totalSelected > 0)
				{
					Vector2 position = BoardToScreen(cursorX, cursorY) + scoreOffset;
					Color color = Color.White;

					if (AnimationState == Animation.Breaking)
					{
						//Slide the score up and fade it
						position -= new Vector2(0, scoreFadeFactor * scoreFadeDistance);
						color = new Color(255, 255, 255,
										  (byte)(255 * (1f - scoreFadeFactor)));
					}

					Font.Draw(spriteBatch, FontStyle.Large, position,
							  Score(totalSelected), color);
				}
			}
		}
Ejemplo n.º 14
0
 /// <summary>
 /// Draws some text from the given font
 /// </summary>
 /// <param name="spriteBatch">The sprite batch to use</param>
 /// <param name="fontStyle">Which font to use</param>
 /// <param name="x">X position in screen pixel space</param>
 /// <param name="y">Y position in screen pixel space</param>
 /// <param name="number">The number to draw</param>
 public static void Draw(RelativeSpriteBatch spriteBatch, FontStyle fontStyle,
                         int x, int y, int number)
 {
     //No color - use 'white' i.e. use whatever is in the file
     Draw(spriteBatch, fontStyle, x, y, number.ToString(), Color.White);
 }
Ejemplo n.º 15
0
 /// <summary>
 /// Draws the specified marble
 /// </summary>
 /// <param name="spriteBatch">The sprite batch to use</param>
 public void Draw(RelativeSpriteBatch spriteBatch)
 {
     Draw2DMarble(spriteBatch);
 }
Ejemplo n.º 16
0
        /// <summary>
        /// Draws some text from the given font
        /// </summary>
        /// <param name="spriteBatch">The sprite batch to use</param>
        /// <param name="fontStyle">Which font to use</param>
        /// <param name="x">X position in screen pixel space</param>
        /// <param name="y">Y position in screen pixel space</param>
        /// <param name="digits">The characters to draw</param>
        /// <param name="color">The color to draw it in</param>
        public static void Draw(RelativeSpriteBatch spriteBatch, FontStyle fontStyle,
            int x, int y, string digits, Color color)
        {
            float xPosition = x;
            FontInfo thisFont = fontInfo[(int)fontStyle];

            for (int i = 0; i < digits.Length; i++)
            {
                //Don't draw anything if its a space character
                if (digits[i] != ' ')
                {
                    //Look up the character position
                    int character = thisFont.Characters.IndexOf(digits[i]);

                    //Draw the correct character at the correct position
                    spriteBatch.Draw(fontTextures[(int)fontStyle],
                                     new Vector2(xPosition, (float)y),
                        new Rectangle(character * thisFont.CharacterSpacing +
                                      thisFont.StartOffset, 0, thisFont.CharacterWidth,
                                      thisFont.CharacterHeight), color);
                }

                //Move the position of the next character.
                //If the character is a comma or colon then use a 'fudge factor' to make
                //the font look a little proportional
                xPosition += ((digits[i] == ',' || digits[i] == ':') ?
                              thisFont.CharacterWidth / 2 : thisFont.CharacterWidth);
            }
        }
Ejemplo n.º 17
0
        private void Draw2DMarble(RelativeSpriteBatch spriteBatch)
        {
            //Draw the 2d marble
            if(Animation == Animation.Breaking || Animation == Animation.Gone)
            {
                //Draw the correct frame.
                spriteBatch.Draw(breakTexture, Position, new Rectangle(frame * Width, 0,
                                 Width, Height), Color);
            }
            else
            {
                spriteBatch.Draw(marble, Position, Color);

                //Highlight selected marbles
                if(Selected)
                {
                    if(pulseFactor < 0.0)
                    {
                        //Make a new color with the correct transparency.
                        Color fade = Color.White * -pulseFactor;

                        //pulse the single ring
                        spriteBatch.Draw(glowRing1Texture, Position, fade);
                    }
                    else
                    {
                        //pulse the double ring

                        //Make a new color with the correct transparency.
                        Color fade = Color.White * pulseFactor;

                        spriteBatch.Draw(glowRing2Texture, Position, fade);
                    }
                }
            }
        }
Ejemplo n.º 18
0
 /// <summary>
 /// Draws some text from the given font
 /// </summary>
 /// <param name="spriteBatch">The sprite batch to use</param>
 /// <param name="fontStyle">Which font to use</param>
 /// <param name="x">X position in screen pixel space</param>
 /// <param name="y">Y position in screen pixel space</param>
 /// <param name="digits">The characters to draw</param>
 public static void Draw(RelativeSpriteBatch spriteBatch, FontStyle fontStyle,
                         int x, int y, string digits)
 {
     //No color - use 'white' i.e. use whatever is in the file
     Draw(spriteBatch, fontStyle, x, y, digits, Color.White);
 }