Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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;
- namespace CatTetris
- {
- public class GCat : Microsoft.Xna.Framework.Game
- {
- GraphicsDeviceManager graphics;
- //Wall sprites
- public static Sprite wallLeft;
- public static Sprite wallRight;
- //Sprites for purple block
- Sprite purpleCat1;
- Sprite purpleCat2;
- Sprite purpleCat3;
- Sprite purpleCat4;
- //PurpleBlock
- Block purpleBlock;
- public static int frameWidth = 600;
- public static int frameHeight = 600;
- SpriteBatch spriteBatch;
- SpriteBatch purpleBatch;
- public GCat()
- {
- graphics = new GraphicsDeviceManager(this);
- Content.RootDirectory = "Content";
- }
- /// <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
- wallLeft = new Sprite();
- wallRight = new Sprite();
- purpleCat1 = new Sprite();
- purpleCat2 = new Sprite();
- purpleCat3 = new Sprite();
- purpleCat4 = new Sprite();
- purpleBlock = new Block();
- InitGraphicsMode(frameWidth, frameHeight,false);
- base.Initialize();
- }
- /// <summary>
- /// LoadContent will be called once per game and is the place to load
- /// all of your content.
- /// </summary>
- protected override void LoadContent()
- {
- // Create a new SpriteBatch, which can be used to draw textures.
- spriteBatch = new SpriteBatch(GraphicsDevice);
- purpleBatch = new SpriteBatch(GraphicsDevice);
- wallLeft.LoadContent(this.Content, "WallLeft");
- wallLeft.Position = new Vector2(0,0);
- wallRight.LoadContent(this.Content, "WallRight");
- wallRight.Position = new Vector2(frameWidth - 150,0);
- purpleCat1.LoadContent(this.Content, "purpleCat1");
- purpleCat2.LoadContent(this.Content, "purpleCat2");
- purpleCat3.LoadContent(this.Content, "purpleCat3");
- purpleCat4.LoadContent(this.Content, "purpleCat4");
- //load up the sprites and positions for the purple block
- purpleBlock.LoadSprites(purpleCat1, purpleCat2, purpleCat3, purpleCat4,
- new Vector2(250, 50), new Vector2(250, 0), new Vector2(200, 50), new Vector2(300, 50));
- }
- /// <summary>
- /// UnloadContent will be called once per game and is the place to unload
- /// all content.
- /// </summary>
- protected override void UnloadContent()
- {
- // TODO: Unload any non ContentManager content here
- }
- /// <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();
- purpleBlock.updateSprites(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)
- {
- GraphicsDevice.Clear(Color.White);
- //This is the sprite batch for the walls
- spriteBatch.Begin();
- wallLeft.Draw(this.spriteBatch);
- wallRight.Draw(this.spriteBatch);
- spriteBatch.End();
- //Individual sprite batch for each block
- Matrix purpleMatrix = purpleBlock.rotationMatrix;
- purpleBatch.Begin(SpriteSortMode.BackToFront, null, null, null, null, null, purpleMatrix);
- purpleBlock.Draw(purpleBatch);
- purpleBatch.End();
- base.Draw(gameTime);
- }
- private void InitGraphicsMode(int width, int height, bool fullScreen)
- {
- if (!fullScreen)
- {
- if ((width <= GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width) &&
- (height <= GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height))
- {
- graphics.PreferredBackBufferWidth = width;
- graphics.PreferredBackBufferHeight = height;
- graphics.IsFullScreen = fullScreen;
- graphics.ApplyChanges();
- }
- }
- else
- {
- foreach (DisplayMode dm in GraphicsAdapter.DefaultAdapter.SupportedDisplayModes)
- {
- //Check the width and height of each of the GPU's display modes against the passed values
- if ((dm.Width == width) && (dm.Height == height))
- {
- //the mode is supported so set the appropriate buffer formats and apply changes
- graphics.PreferredBackBufferWidth = width;
- graphics.PreferredBackBufferHeight = height;
- graphics.IsFullScreen = fullScreen;
- graphics.ApplyChanges();
- }
- }
- }
- }// end InitGraphicsMode()
- }
- }
Add Comment
Please, Sign In to add comment