All pastes #589873 Raw Edit

Anonymous

public text v1 · immutable
#589873 ·published 2007-06-26 07:36 UTC
rendered paste body
TILE.CS MAIN XNA FILE

#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 Tiles
{
    /// <summary>
    /// This is the main type for your game
    /// </summary>
    public class Tiles : Microsoft.Xna.Framework.Game
    {
        GraphicsDeviceManager graphics;
        ContentManager content;

        Tile grass;
        Tile cloud;
        AnimatedSprite plasma;
        public SpriteBatch spriteBatch;

        public Tiles()
        {
            //Determines proper screen size
            graphics = new GraphicsDeviceManager(this);
            graphics.PreferredBackBufferWidth = 800;
            graphics.PreferredBackBufferHeight = 600;
            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()
        {
            //Sets properties for the sprites
            spriteBatch = new SpriteBatch(graphics.GraphicsDevice);

            grass = new Tile();
            grass.Position = Vector2.Zero;
            grass.Color = Color.White;
            grass.Layer = .8f;

            cloud = new Tile();
            cloud.Position = Vector2.Zero;
            cloud.Color = Color.White;
            cloud.Layer = 1.0f;

            plasma = new AnimatedSprite(120, graphics);

            for (int i = 1; i < 120; i++)
            {
                plasma.textures.Add(content.Load<Texture2D>(@"Textures/plasmaSplash/000"+i));
            }
            plasma.Layer = 1.0f;
            plasma.Color = Color.White;

            

            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)
            {
                //Loads the sprites and calls the initialize
                grass.Texture = content.Load<Texture2D>(@"Textures/grass");
                cloud.Texture = content.Load<Texture2D>(@"Textures/cloud");
                grass.Initialize();
                cloud.Initialize();
            }

            // 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 update code.
            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.Black);

            spriteBatch.Begin();
           // grass.Draw(spriteBatch);
            //cloud.Draw(spriteBatch);
            plasma.Draw(spriteBatch);
            spriteBatch.End();

            base.Draw(gameTime);
        }
    }
}



--------------------

ANIMATEDSPRITE.CS

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;

namespace Tiles
{
    class AnimatedSprite
    {
        public AnimatedSprite(int frameCount, GraphicsDeviceManager graphics)
        {
            frames = frameCount;
            Graphics = graphics;
        }
        private GraphicsDeviceManager Graphics;
        private Texture2D texture;
        private Color color;
        public List<Texture2D> textures = new List<Texture2D>();
        private Vector2 position;

        private float layer;
        private int frames;

        #region Properties

        public Texture2D Texture
        {
            get { return texture; }
            set { texture = value; }
        }

        public Vector2 Position
        {
            get { return position; }
            set { position = value; }
        }

        public Color Color
        {
            get { return color; }
            set { color = value; }
        }

        public float Layer
        {
            get { return layer; }
            set { layer = value; }
        }
        #endregion

        public void Draw(SpriteBatch spriteBatch)
        {
            foreach (Texture2D sprite in textures)
            {
                Graphics.GraphicsDevice.Clear(Color.Black);
                Rectangle sourceRectangle = new Rectangle(0, 0, 320, 240);
                spriteBatch.Draw(sprite,
                                 new Vector2(50,50),
                                sourceRectangle,
                                color,
                                0.0f,
                                new Vector2(0, 0),
                                1.0f,
                                SpriteEffects.None,
                                layer);
            }
        }

    }
}