2D Game for XBOX 360 using C#
9 or10
#region Using Statements08
07
#region Using Statements
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Storage;
#endregion
namespace _0090118.game
{
    /// <summary>
    /// This is the main type for your game
    /// </summary>
    public class Game1 : Microsoft.Xna.Framework.Game
    {
        GraphicsDeviceManager graphics;
        ContentManager content;
        //20090119.02
        private SpriteBatch mSpriteBatch;
        private Texture2D mRoad;
        //20090119.03
        private float mVelocityY;
        private int[] mRoadY = new int[3];
        //20090119.04
        private Texture2D mCar;
        private Rectangle mCarPosition;
        //20090119.05
        private KeyboardState mPreviousKeyboardState;
        private int mMoveCarX;
        //20090119.06
        private GamePadState mPreviousGamePadState;
        //20090119.07
        private Texture2D mHazard;
        private Rectangle mHazardPosition;
        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            content = new ContentManager(Services);
        }
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
       
/// related content.  Calling base.Initialize will enumerate
through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here
            base.Initialize();
            //20090119.03
            StartGame();
        }
        /// <summary>
        /// Load your graphics content.  If loadAllContent is true, you should
        /// load content from both ResourceManagementMode pools.  Otherwise, just
        /// load ResourceManagementMode.Manual content.
        /// </summary>
        /// <param name="loadAllContent">Which type of content to load.</param>
        protected override void LoadGraphicsContent(bool loadAllContent)
        {
            if (loadAllContent)
            {
               
// TODO: Load any ResourceManagementMode.Automatic content
                //20090119.02
               
mSpriteBatch = new SpriteBatch(graphics.GraphicsDevice);
               
mRoad = content.Load<Texture2D>("Road");
                //20090119.04
               
mCar = content.Load<Texture2D>("Car");
                //20090119.07
               
mHazard = content.Load<Texture2D>("Hazard");
            }
            // TODO: Load any ResourceManagementMode.Manual content
        }
        /// <summary>
        /// Unload your graphics content.  If unloadAllContent is true, you should
        /// unload content from both ResourceManagementMode pools.  Otherwise, just
        /// unload ResourceManagementMode.Manual content.  Manual content will get
        /// Disposed by the GraphicsDevice during a Reset.
        /// </summary>
       
/// <param name="unloadAllContent">Which type of content to
unload.</param>
        protected override void UnloadGraphicsContent(bool unloadAllContent)
        {
            if (unloadAllContent)
            {
               
// TODO: Unload any ResourceManagementMode.Automatic content
                content.Unload();
            }
            // TODO: Unload any ResourceManagementMode.Manual content
        }
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
           
if (GamePad.GetState(PlayerIndex.One).Buttons.Back ==
ButtonState.Pressed)
                this.Exit();
            // TODO: Add your update logic here
            //20090119.05
            //KeyboardState aCurrentKeyboardState = Keyboard.GetState();
            //if (aCurrentKeyboardState.IsKeyDown(Keys.Escape) == true)
            //{
            //    this.Exit();
            //}
           
//if (aCurrentKeyboardState.IsKeyDown(Keys.Space) == true &&
           
//    mPreviousKeyboardState.IsKeyDown(Keys.Space) ==
false)
            //{
            //    mCarPosition.X += mMoveCarX;
            //    mMoveCarX *= -1;
            //}
            //mPreviousKeyboardState = aCurrentKeyboardState;
            //20090119.06
            KeyboardState aCurrentKeyboardState =
            Keyboard.GetState();
            GamePadState aCurrentGamePadState =
                GamePad.GetState(PlayerIndex.One);
            if (aCurrentKeyboardState.IsKeyDown(Keys.Escape)
                == true ||
                aCurrentGamePadState.Buttons.Back ==
                ButtonState.Pressed)
            {
                this.Exit();
            }
            if
               
((aCurrentKeyboardState.IsKeyDown(Keys.Space)
                == true &&
               
mPreviousKeyboardState.IsKeyDown(Keys.Space)
               
== false) || (aCurrentGamePadState.Buttons.X
                == ButtonState.Pressed &&
                mPreviousGamePadState.Buttons.X ==
                ButtonState.Released))
            {
                mCarPosition.X += mMoveCarX;
                mMoveCarX *= -1;
            }
            mPreviousKeyboardState = aCurrentKeyboardState;
            mPreviousGamePadState = aCurrentGamePadState;
            //20090119.03
            ScrollRoad(gameTime);
            base.Update(gameTime);
        }
        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            // TODO: Add your drawing code here
            //20090119.02
            //graphics.GraphicsDevice.Clear(Color.CornflowerBlue);
            graphics.GraphicsDevice.Clear(Color.SaddleBrown);
            //mSpriteBatch.Begin();
            ////Vector2(0,0) is the upper left corner of the screen
            //mSpriteBatch.Draw(mRoad, new Vector2(0, 0),Color.White);
            //mSpriteBatch.End();
            //20090119.03
            mSpriteBatch.Begin();
            for (int aIndex = 0; aIndex < mRoadY.Length;
                aIndex++)
            {
                mSpriteBatch.Draw(mRoad,
               
new Vector2(0, mRoadY[aIndex]), Color.White);
            }
            //20090119.04
            mSpriteBatch.Draw(mCar, mCarPosition, Color.White);
            //20090119.07
            mSpriteBatch.Draw(mHazard, mHazardPosition,Color.White);
            mSpriteBatch.End();
            //20090119.02
            base.Draw(gameTime);
        }
        //20090119.03
        protected void StartGame()
        {
            mRoadY[0] = 0;
            mRoadY[1] = mRoadY[0] + -mRoad.Height + 2;
            mRoadY[2] = mRoadY[1] + -mRoad.Height + 2;
            mVelocityY = 0.3F;
            //20090119.04
           
mCarPosition = new Rectangle(280, 440, (int)(mCar.Width * 0.2f),
                                        
(int)(mCar.Height * 0.2f));
            //20090119.05
            mMoveCarX = 160;
            //20090119.07
           
mHazardPosition = new Rectangle(280, 0,(int)(mHazard.Width * 0.4f),
                                           
(int)(mHazard.Height * 0.4f));
        }
        private void ScrollRoad(GameTime theTime)
        {
            //Loop the road
            for (int aIndex = 0; aIndex < mRoadY.Length;
                aIndex++)
            {
                if (mRoadY[aIndex] >=
                   
this.Window.ClientBounds.Height)
                {
                   
int aLastRoadIndex = aIndex;
                   
for (int aCounter = 0; aCounter <
                       
mRoadY.Length; aCounter++)
                    {
                       
if (mRoadY[aCounter] <
                           
mRoadY[aLastRoadIndex])
                       
{
                           
aLastRoadIndex = aCounter;
                       
}
                    }
                   
mRoadY[aIndex] =
                       
mRoadY[aLastRoadIndex] -
                       
mRoad.Height + 2;
                }
            }
            //Move the road
            for (int aIndex = 0; aIndex < mRoadY.Length;
                aIndex++)
            {
                mRoadY[aIndex] += (int)(mVelocityY *
               
theTime.ElapsedGameTime.TotalMilliseconds
                    );
            }
        }
    }
}
06
#region Using Statements05
#region Using Statements
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Storage;
#endregion
namespace _0090118.game
{
    /// <summary>
    /// This is the main type for your game
    /// </summary>
    public class Game1 : Microsoft.Xna.Framework.Game
    {
        GraphicsDeviceManager graphics;
        ContentManager content;
        //20090119.02
        private SpriteBatch mSpriteBatch;
        private Texture2D mRoad;
        //20090119.03
        private float mVelocityY;
        private int[] mRoadY = new int[3];
        //20090119.04
        private Texture2D mCar;
        private Rectangle mCarPosition;
        //20090119.05
        private KeyboardState mPreviousKeyboardState;
        private int mMoveCarX;
        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            content = new ContentManager(Services);
        }
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
       
/// related content.  Calling base.Initialize will enumerate
through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here
            base.Initialize();
            //20090119.03
            StartGame();
        }
        /// <summary>
        /// Load your graphics content.  If loadAllContent is true, you should
        /// load content from both ResourceManagementMode pools.  Otherwise, just
        /// load ResourceManagementMode.Manual content.
        /// </summary>
        /// <param name="loadAllContent">Which type of content to load.</param>
        protected override void LoadGraphicsContent(bool loadAllContent)
        {
            if (loadAllContent)
            {
               
// TODO: Load any ResourceManagementMode.Automatic content
                //20090119.02
               
mSpriteBatch = new SpriteBatch(graphics.GraphicsDevice);
               
mRoad = content.Load<Texture2D>("Road");
                //20090119.04
               
mCar = content.Load<Texture2D>("Car");
            }
            // TODO: Load any ResourceManagementMode.Manual content
        }
        /// <summary>
        /// Unload your graphics content.  If unloadAllContent is true, you should
        /// unload content from both ResourceManagementMode pools.  Otherwise, just
        /// unload ResourceManagementMode.Manual content.  Manual content will get
        /// Disposed by the GraphicsDevice during a Reset.
        /// </summary>
       
/// <param name="unloadAllContent">Which type of content to
unload.</param>
        protected override void UnloadGraphicsContent(bool unloadAllContent)
        {
            if (unloadAllContent)
            {
               
// TODO: Unload any ResourceManagementMode.Automatic content
                content.Unload();
            }
            // TODO: Unload any ResourceManagementMode.Manual content
        }
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
           
if (GamePad.GetState(PlayerIndex.One).Buttons.Back ==
ButtonState.Pressed)
                this.Exit();
            // TODO: Add your update logic here
            //20090119.05
            KeyboardState aCurrentKeyboardState = Keyboard.GetState();
            if (aCurrentKeyboardState.IsKeyDown(Keys.Escape) == true)
            {
                this.Exit();
            }
           
if (aCurrentKeyboardState.IsKeyDown(Keys.Space) == true &&
               
mPreviousKeyboardState.IsKeyDown(Keys.Space) == false)
            {
                mCarPosition.X += mMoveCarX;
                mMoveCarX *= -1;
            }
            mPreviousKeyboardState = aCurrentKeyboardState;
            //20090119.03
            ScrollRoad(gameTime);
            base.Update(gameTime);
        }
        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            // TODO: Add your drawing code here
            //20090119.02
            //graphics.GraphicsDevice.Clear(Color.CornflowerBlue);
            graphics.GraphicsDevice.Clear(Color.SaddleBrown);
            //mSpriteBatch.Begin();
            ////Vector2(0,0) is the upper left corner of the screen
            //mSpriteBatch.Draw(mRoad, new Vector2(0, 0),Color.White);
            //mSpriteBatch.End();
            //20090119.03
            mSpriteBatch.Begin();
            for (int aIndex = 0; aIndex < mRoadY.Length;
                aIndex++)
            {
                mSpriteBatch.Draw(mRoad,
               
new Vector2(0, mRoadY[aIndex]), Color.White);
            } 
            mSpriteBatch.Draw(mCar, mCarPosition, Color.White);
            mSpriteBatch.End();
            //20090119.04
            
            base.Draw(gameTime);
        }
        //20090119.03
        protected void StartGame()
        {
            mRoadY[0] = 0;
            mRoadY[1] = mRoadY[0] + -mRoad.Height + 2;
            mRoadY[2] = mRoadY[1] + -mRoad.Height + 2;
            mVelocityY = 0.3F;
            //20090119.04
           
mCarPosition = new Rectangle(280, 440, (int)(mCar.Width * 0.2f),
                                        
(int)(mCar.Height * 0.2f));
            //20090119.05
            mMoveCarX = 160;
        }
        private void ScrollRoad(GameTime theTime)
        {
            //Loop the road
            for (int aIndex = 0; aIndex < mRoadY.Length;
                aIndex++)
            {
                if (mRoadY[aIndex] >=
                   
this.Window.ClientBounds.Height)
                {
                   
int aLastRoadIndex = aIndex;
                   
for (int aCounter = 0; aCounter <
                       
mRoadY.Length; aCounter++)
                    {
                       
if (mRoadY[aCounter] <
                           
mRoadY[aLastRoadIndex])
                       
{
                           
aLastRoadIndex = aCounter;
                       
}
                    }
                   
mRoadY[aIndex] =
                       
mRoadY[aLastRoadIndex] -
                       
mRoad.Height + 2;
                }
            }
            //Move the road
            for (int aIndex = 0; aIndex < mRoadY.Length;
                aIndex++)
            {
                mRoadY[aIndex] += (int)(mVelocityY *
               
theTime.ElapsedGameTime.TotalMilliseconds
                    );
            }
        }
    }
}
04
#region Using Statements
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Storage;
#endregion
namespace _0090118.game
{
    /// <summary>
    /// This is the main type for your game
    /// </summary>
    public class Game1 : Microsoft.Xna.Framework.Game
    {
        GraphicsDeviceManager graphics;
        ContentManager content;
        //20090119.02
        private SpriteBatch mSpriteBatch;
        private Texture2D mRoad;
        //20090119.03
        private float mVelocityY;
        private int[] mRoadY = new int[3];
        //20090119.04
        private Texture2D mCar;
        private Rectangle mCarPosition;
        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            content = new ContentManager(Services);
        }
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
       
/// related content.  Calling base.Initialize will enumerate
through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here
            base.Initialize();
            //20090119.03
            StartGame();
        }
        /// <summary>
        /// Load your graphics content.  If loadAllContent is true, you should
        /// load content from both ResourceManagementMode pools.  Otherwise, just
        /// load ResourceManagementMode.Manual content.
        /// </summary>
        /// <param name="loadAllContent">Which type of content to load.</param>
        protected override void LoadGraphicsContent(bool loadAllContent)
        {
            if (loadAllContent)
            {
               
// TODO: Load any ResourceManagementMode.Automatic content
                //20090119.02
               
mSpriteBatch = new SpriteBatch(graphics.GraphicsDevice);
               
mRoad = content.Load<Texture2D>("Road");
                //20090119.04
               
mCar = content.Load<Texture2D>("Car");
            }
            // TODO: Load any ResourceManagementMode.Manual content
        }
        /// <summary>
        /// Unload your graphics content.  If unloadAllContent is true, you should
        /// unload content from both ResourceManagementMode pools.  Otherwise, just
        /// unload ResourceManagementMode.Manual content.  Manual content will get
        /// Disposed by the GraphicsDevice during a Reset.
        /// </summary>
       
/// <param name="unloadAllContent">Which type of content to
unload.</param>
        protected override void UnloadGraphicsContent(bool unloadAllContent)
        {
            if (unloadAllContent)
            {
               
// TODO: Unload any ResourceManagementMode.Automatic content
                content.Unload();
            }
            // TODO: Unload any ResourceManagementMode.Manual content
        }
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
           
if (GamePad.GetState(PlayerIndex.One).Buttons.Back ==
ButtonState.Pressed)
                this.Exit();
            // TODO: Add your update logic here
            //20090119.03
            ScrollRoad(gameTime);
            base.Update(gameTime);
        }
        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            // TODO: Add your drawing code here
            //20090119.02
            //graphics.GraphicsDevice.Clear(Color.CornflowerBlue);
            graphics.GraphicsDevice.Clear(Color.SaddleBrown);
            //mSpriteBatch.Begin();
            ////Vector2(0,0) is the upper left corner of the screen
            //mSpriteBatch.Draw(mRoad, new Vector2(0, 0),Color.White);
            //mSpriteBatch.End();
            //20090119.03
            mSpriteBatch.Begin();
            for (int aIndex = 0; aIndex < mRoadY.Length;
                aIndex++)
            {
                mSpriteBatch.Draw(mRoad,
               
new Vector2(0, mRoadY[aIndex]), Color.White);
            } 
            mSpriteBatch.Draw(mCar, mCarPosition, Color.White);
            mSpriteBatch.End();
            //20090119.04
            base.Draw(gameTime);
        }
        //20090119.03
        protected void StartGame()
        {
            mRoadY[0] = 0;
            mRoadY[1] = mRoadY[0] + -mRoad.Height + 2;
            mRoadY[2] = mRoadY[1] + -mRoad.Height + 2;
            mVelocityY = 0.3F;
            //20090119.04
           
mCarPosition = new Rectangle(280, 440, (int)(mCar.Width * 0.2f),
                                        
(int)(mCar.Height * 0.2f));
        }
        private void ScrollRoad(GameTime theTime)
        {
            //Loop the road
            for (int aIndex = 0; aIndex < mRoadY.Length;
                aIndex++)
            {
                if (mRoadY[aIndex] >=
                   
this.Window.ClientBounds.Height)
                {
                   
int aLastRoadIndex = aIndex;
                   
for (int aCounter = 0; aCounter <
                       
mRoadY.Length; aCounter++)
                    {
                       
if (mRoadY[aCounter] <
                           
mRoadY[aLastRoadIndex])
                       
{
                           
aLastRoadIndex = aCounter;
                       
}
                    }
                   
mRoadY[aIndex] =
                       
mRoadY[aLastRoadIndex] -
                       
mRoad.Height + 2;
                }
            }
            //Move the road
            for (int aIndex = 0; aIndex < mRoadY.Length;
                aIndex++)
            {
                mRoadY[aIndex] += (int)(mVelocityY *
               
theTime.ElapsedGameTime.TotalMilliseconds
                    );
            }
        }
    }
}
03
#region Using Statements
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Storage;
#endregion
namespace _0090118.game
{
/// <summary>
/// This is the main type for your game
/// </summary>
public class Game1 : Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics;
ContentManager content;
//20090119.02
private SpriteBatch mSpriteBatch;
private Texture2D mRoad;
//20090119.03
private float mVelocityY;
private int[] mRoadY = new int[3];
public Game1()
{
graphics = new GraphicsDeviceManager(this);
content = new ContentManager(Services);
}
/// <summary>
/// Allows the game to perform any initialization it needs to before starting to run.
/// This is where it can query for any required services and load any non-graphic
/// related content. Calling base.Initialize will enumerate through any components
/// and initialize them as well.
/// </summary>
protected override void Initialize()
{
// TODO: Add your initialization logic here
base.Initialize();
//20090119.03
StartGame();
}
/// <summary>
/// Load your graphics content. If loadAllContent is true, you should
/// load content from both ResourceManagementMode pools. Otherwise, just
/// load ResourceManagementMode.Manual content.
/// </summary>
/// <param name="loadAllContent">Which type of content to load.</param>
protected override void LoadGraphicsContent(bool loadAllContent)
{
if (loadAllContent)
{
// TODO: Load any ResourceManagementMode.Automatic content
//20090119.02
mSpriteBatch = new SpriteBatch(graphics.GraphicsDevice);
mRoad = content.Load<Texture2D>("Road");
}
// TODO: Load any ResourceManagementMode.Manual content
}
/// <summary>
/// Unload your graphics content. If unloadAllContent is true, you should
/// unload content from both ResourceManagementMode pools. Otherwise, just
/// unload ResourceManagementMode.Manual content. Manual content will get
/// Disposed by the GraphicsDevice during a Reset.
/// </summary>
/// <param name="unloadAllContent">Which type of content to unload.</param>
protected override void UnloadGraphicsContent(bool unloadAllContent)
{
if (unloadAllContent)
{
// TODO: Unload any ResourceManagementMode.Automatic content
content.Unload();
}
// TODO: Unload any ResourceManagementMode.Manual content
}
/// <summary>
/// Allows the game to run logic such as updating the world,
/// checking for collisions, gathering input and playing audio.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
protected override void Update(GameTime gameTime)
{
// Allows the game to exit
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
this.Exit();
// TODO: Add your update logic here
//20090119.03
ScrollRoad(gameTime);
base.Update(gameTime);
}
/// <summary>
/// This is called when the game should draw itself.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
protected override void Draw(GameTime gameTime)
{
// TODO: Add your drawing code here
//20090119.02
//graphics.GraphicsDevice.Clear(Color.CornflowerBlue);
graphics.GraphicsDevice.Clear(Color.SaddleBrown);
//mSpriteBatch.Begin();
////Vector2(0,0) is the upper left corner of the screen
//mSpriteBatch.Draw(mRoad, new Vector2(0, 0),Color.White);
//mSpriteBatch.End();
//20090119.03
mSpriteBatch.Begin();
for (int aIndex = 0; aIndex < mRoadY.Length;
aIndex++)
{
mSpriteBatch.Draw(mRoad,
new Vector2(0, mRoadY[aIndex]), Color.White);
}
mSpriteBatch.End();
base.Draw(gameTime);
}
//20090119.03
protected void StartGame()
{
mRoadY[0] = 0;
mRoadY[1] = mRoadY[0] + -mRoad.Height + 2;
mRoadY[2] = mRoadY[1] + -mRoad.Height + 2;
mVelocityY = 0.3F;
}
private void ScrollRoad(GameTime theTime)
{
//Loop the road
for (int aIndex = 0; aIndex < mRoadY.Length;
aIndex++)
{
if (mRoadY[aIndex] >=
this.Window.ClientBounds.Height)
{
int aLastRoadIndex = aIndex;
for (int aCounter = 0; aCounter <
mRoadY.Length; aCounter++)
{
if (mRoadY[aCounter] <
mRoadY[aLastRoadIndex])
{
aLastRoadIndex = aCounter;
}
}
mRoadY[aIndex] =
mRoadY[aLastRoadIndex] -
mRoad.Height + 2;
}
}
//Move the road
for (int aIndex = 0; aIndex < mRoadY.Length;
aIndex++)
{
mRoadY[aIndex] += (int)(mVelocityY *
theTime.ElapsedGameTime.TotalMilliseconds
);
}
}
}
}
02
#region Using Statements
01
#region Using Statements
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Storage;
#endregion
namespace _0090118.game
{
/// <summary>
/// This is the main type for your game
/// </summary>
public class Game1 : Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics;
ContentManager content;
public Game1()
{
graphics = new GraphicsDeviceManager(this);
content = new ContentManager(Services);
}
/// <summary>
/// Allows the game to perform any initialization it needs to before starting to run.
/// This is where it can query for any required services and load any non-graphic
/// related content. Calling base.Initialize will enumerate through any components
/// and initialize them as well.
/// </summary>
protected override void Initialize()
{
// TODO: Add your initialization logic here
base.Initialize();
}
/// <summary>
/// Load your graphics content. If loadAllContent is true, you should
/// load content from both ResourceManagementMode pools. Otherwise, just
/// load ResourceManagementMode.Manual content.
/// </summary>
/// <param name="loadAllContent">Which type of content to load.</param>
protected override void LoadGraphicsContent(bool loadAllContent)
{
if (loadAllContent)
{
// TODO: Load any ResourceManagementMode.Automatic content
}
// TODO: Load any ResourceManagementMode.Manual content
}
/// <summary>
/// Unload your graphics content. If unloadAllContent is true, you should
/// unload content from both ResourceManagementMode pools. Otherwise, just
/// unload ResourceManagementMode.Manual content. Manual content will get
/// Disposed by the GraphicsDevice during a Reset.
/// </summary>
/// <param name="unloadAllContent">Which type of content to unload.</param>
protected override void UnloadGraphicsContent(bool unloadAllContent)
{
if (unloadAllContent)
{
// TODO: Unload any ResourceManagementMode.Automatic content
content.Unload();
}
// TODO: Unload any ResourceManagementMode.Manual content
}
/// <summary>
/// Allows the game to run logic such as updating the world,
/// checking for collisions, gathering input and playing audio.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
protected override void Update(GameTime gameTime)
{
// Allows the game to exit
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
this.Exit();
// TODO: Add your update logic here
base.Update(gameTime);
}
/// <summary>
/// This is called when the game should draw itself.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
protected override void Draw(GameTime gameTime)
{
graphics.GraphicsDevice.Clear(Color.CornflowerBlue);
// TODO: Add your drawing code here
base.Draw(gameTime);
}
}
}
Reference:
Raw Images 2009-01-19

Source:
http://www.code-magazine.com/article.aspx?quickid=0709051&page=1