Strona główna

miniaturka
Game1.cs dla liczenia min. update timu

using System;

using System.Collections.Generic;

using System.Linq;

using Microsoft.Xna.Framework;

using Microsoft.Xna.Framework.Audio;

using Microsoft.Xna.Framework.Content;

using Microsoft.Xna.Framework.GamerServices;

using Microsoft.Xna.Framework.Graphics;

using Microsoft.Xna.Framework.Input;

using Microsoft.Xna.Framework.Media;

using Microsoft.Xna.Framework.Net;

using Microsoft.Xna.Framework.Storage;

 

namespace WindowsGame5

{

    /// <summary>

    /// This is the main type for your game

    /// </summary>

    public class Game1 : Microsoft.Xna.Framework.Game

    {

        GraphicsDeviceManager graphics;

        SpriteBatch spriteBatch;

        Interface1 interface1;

        Interface1 Interface1

        {

            get

            {

                if (interface1 == null)

                    interface1 = (Interface1)Services.GetService(typeof(Interface1));

                return interface1;

            }

        }

        #region checking_time_vars

        /*

        double elapsed;

        double minElapsed;

        */

        #endregion

 

        public Game1()

        {

            graphics = new GraphicsDeviceManager(this);

            Content.RootDirectory = "Content";

            //IsMouseVisible = true;

            graphics.SynchronizeWithVerticalRetrace = false;

        }

 

        protected override void Initialize()

        {

 

            // TODO: Add your initialization logic here

            graphics.IsFullScreen = true;

            graphics.PreferredBackBufferHeight = 600;

            graphics.PreferredBackBufferWidth = 800;

            graphics.ApplyChanges();

 

            GameComponent1 game_com = new GameComponent1(this);

            Components.Add(game_com);

            Services.AddService(typeof(Interface1), game_com);

 

            IsFixedTimeStep = true;

            TargetElapsedTime = TimeSpan.FromTicks(460);

 

            #region checking_time_vars_set

            //elapsed = 0;

            //minElapsed = 0;

            #endregion

 

            base.Initialize();

        }

 

        protected override void LoadContent()

        {

            // Create a new SpriteBatch, which can be used to draw textures.

            spriteBatch = new SpriteBatch(GraphicsDevice);

 

            // TODO: use this.Content to load your game content here

        }

 

        protected override void UnloadContent()

        {

            // TODO: Unload any non ContentManager content here

        }

 

        protected override void Update(GameTime gameTime)

        {

            // Allows the game to exit

            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)

                this.Exit();

 

            KeyboardState key = Keyboard.GetState();

 

            MouseState mouse = Mouse.GetState();

            if (mouse.LeftButton == ButtonState.Pressed)

            {

                Interface1.Add(mouse.X, mouse.Y, 0, Color.Black);

            }

 

            if (key.IsKeyDown(Keys.Escape))

                this.Exit();

 

            if (Keyboard.GetState().IsKeyDown(Keys.F1))

            {

                graphics.ToggleFullScreen();

            }

            #region checking_time

            /*

            elapsed = gameTime.ElapsedGameTime.TotalMilliseconds;

 

             if (graphics.IsFullScreen == true)

              {

            if (minElapsed == 0)

                minElapsed = elapsed;

 

            else if (elapsed < minElapsed)

                minElapsed = elapsed;

             }

            */

            #endregion

 

            base.Update(gameTime);

        }

 

        protected override void Draw(GameTime gameTime)

        {

            GraphicsDevice.Clear(Color.CornflowerBlue);

 

            // TODO: Add your drawing code here

 

            #region checking_time2

            /*

            string currentMinElapsedTime = minElapsed.ToString();

 

            Window.Title = "minElapsed: " + minElapsed;

            */

            #endregion

 

            base.Draw(gameTime);

        }

    }

}



miniaturka
GameComponent1.cs dla liczenia min. update timu

using System;

using System.Collections.Generic;

using System.Linq;

using Microsoft.Xna.Framework;

using Microsoft.Xna.Framework.Audio;

using Microsoft.Xna.Framework.Content;

using Microsoft.Xna.Framework.GamerServices;

using Microsoft.Xna.Framework.Graphics;

using Microsoft.Xna.Framework.Input;

using Microsoft.Xna.Framework.Media;

using Microsoft.Xna.Framework.Net;

using Microsoft.Xna.Framework.Storage;

 

 

namespace WindowsGame5

{

    /// <summary>

    /// This is a game component that implements IUpdateable.

    /// </summary>

    public class GameComponent1 : Microsoft.Xna.Framework.DrawableGameComponent , Interface1

    {

        List<VertexPositionColor> points;

 

        public GameComponent1(Game game)

            : base(game)

        {

            // TODO: Construct any child components here

        }

 

        /// <summary>

        /// Allows the game component to perform any initialization it needs to before starting

        /// to run.  This is where it can query for any required services and load content.

        /// </summary>

        public override void Initialize()

        {

            points = new List<VertexPositionColor>();

            // TODO: Add your initialization code here

            base.Game.IsMouseVisible = true;

            base.Initialize();

        }

 

        /// <summary>

        /// Allows the game component to update itself.

        /// </summary>

        /// <param name="gameTime">Provides a snapshot of timing values.</param>

        public override void Update(GameTime gameTime)

        {

            // TODO: Add your update code here

 

            base.Update(gameTime);

        }

 

        public void Add(int p, int p_2, int p_3, Color color)

        {

            points.Add(new VertexPositionColor(new Vector3(p, p_2, p_3), color));

        }

 

        public override void Draw(GameTime gameTime)

        {

            GraphicsDevice.RenderState.PointSize = 3;

 

            if (points.Count > 0)

            {

                VertexBuffer vB = new VertexBuffer(GraphicsDevice, VertexPositionColor.SizeInBytes * points.Count, BufferUsage.None);

                vB.SetData<VertexPositionColor>(points.ToArray());

                GraphicsDevice.VertexDeclaration = new VertexDeclaration(GraphicsDevice, VertexPositionColor.VertexElements);

                GraphicsDevice.Vertices[0].SetSource(vB, 0, VertexPositionColor.SizeInBytes);

                BasicEffect effect = new BasicEffect(GraphicsDevice, null);

                effect.VertexColorEnabled = true;

 

                #region Transform

                effect.VertexColorEnabled = true;

                effect.World = Matrix.Identity;

                effect.View = new Matrix(

                    1.0f, 0.0f, 0.0f, 0.0f,

                    0.0f, 1.0f, 0.0f, 0.0f,

                    0.0f, 0.0f, -1.0f, 0.0f,

                    0.0f, 0.0f, 0.0f, 1.0f

                );

                effect.Projection = Matrix.CreateOrthographicOffCenter(

                      0f, base.Game.Window.ClientBounds.Width,

                      base.Game.Window.ClientBounds.Height, 0f,

                      -10f, 10f

                );

                #endregion

 

                effect.Begin();

 

                foreach (EffectPass pass in effect.CurrentTechnique.Passes)

                {

                    pass.Begin();

                    GraphicsDevice.DrawPrimitives(PrimitiveType.PointList, 0, points.Count);

                    pass.End();

                }

                effect.End();

            }

 

            base.Draw(gameTime);

        }

    }

}



miniaturka
Interface1.cs dla liczenia min. update timu

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using Microsoft.Xna.Framework.Graphics;

 

namespace WindowsGame5

{

    interface Interface1

    {

        void Add(int p, int p_2, int p_3, Color color);

    }

}