SHOW:
|
|
- or go back to the newest paste.
| 1 | using System; | |
| 2 | using System.Collections.Generic; | |
| 3 | using System.Linq; | |
| 4 | using Microsoft.Xna.Framework; | |
| 5 | using Microsoft.Xna.Framework.Audio; | |
| 6 | using Microsoft.Xna.Framework.Content; | |
| 7 | using Microsoft.Xna.Framework.GamerServices; | |
| 8 | using Microsoft.Xna.Framework.Graphics; | |
| 9 | using Microsoft.Xna.Framework.Input; | |
| 10 | using Microsoft.Xna.Framework.Media; | |
| 11 | ||
| 12 | namespace CatTetris | |
| 13 | {
| |
| 14 | ||
| 15 | public class GCat : Microsoft.Xna.Framework.Game | |
| 16 | {
| |
| 17 | GraphicsDeviceManager graphics; | |
| 18 | ||
| 19 | //Wall sprites | |
| 20 | public static Sprite wallLeft; | |
| 21 | public static Sprite wallRight; | |
| 22 | ||
| 23 | //Sprites for purple block | |
| 24 | Sprite purpleCat1; | |
| 25 | Sprite purpleCat2; | |
| 26 | Sprite purpleCat3; | |
| 27 | Sprite purpleCat4; | |
| 28 | ||
| 29 | //PurpleBlock | |
| 30 | Block purpleBlock; | |
| 31 | ||
| 32 | public static int frameWidth = 600; | |
| 33 | public static int frameHeight = 600; | |
| 34 | ||
| 35 | SpriteBatch spriteBatch; | |
| 36 | SpriteBatch purpleBatch; | |
| 37 | ||
| 38 | public GCat() | |
| 39 | {
| |
| 40 | graphics = new GraphicsDeviceManager(this); | |
| 41 | Content.RootDirectory = "Content"; | |
| 42 | } | |
| 43 | ||
| 44 | /// <summary> | |
| 45 | /// Allows the game to perform any initialization it needs to before starting to run. | |
| 46 | /// This is where it can query for any required services and load any non-graphic | |
| 47 | /// related content. Calling base.Initialize will enumerate through any components | |
| 48 | /// and initialize them as well. | |
| 49 | /// </summary> | |
| 50 | protected override void Initialize() | |
| 51 | {
| |
| 52 | // TODO: Add your initialization logic here | |
| 53 | wallLeft = new Sprite(); | |
| 54 | wallRight = new Sprite(); | |
| 55 | ||
| 56 | purpleCat1 = new Sprite(); | |
| 57 | purpleCat2 = new Sprite(); | |
| 58 | purpleCat3 = new Sprite(); | |
| 59 | purpleCat4 = new Sprite(); | |
| 60 | ||
| 61 | purpleBlock = new Block(); | |
| 62 | ||
| 63 | InitGraphicsMode(frameWidth, frameHeight,false); | |
| 64 | ||
| 65 | base.Initialize(); | |
| 66 | } | |
| 67 | ||
| 68 | /// <summary> | |
| 69 | /// LoadContent will be called once per game and is the place to load | |
| 70 | /// all of your content. | |
| 71 | /// </summary> | |
| 72 | protected override void LoadContent() | |
| 73 | {
| |
| 74 | // Create a new SpriteBatch, which can be used to draw textures. | |
| 75 | spriteBatch = new SpriteBatch(GraphicsDevice); | |
| 76 | purpleBatch = new SpriteBatch(GraphicsDevice); | |
| 77 | ||
| 78 | wallLeft.LoadContent(this.Content, "WallLeft"); | |
| 79 | wallLeft.Position = new Vector2(0,0); | |
| 80 | ||
| 81 | wallRight.LoadContent(this.Content, "WallRight"); | |
| 82 | wallRight.Position = new Vector2(frameWidth - 150,0); | |
| 83 | ||
| 84 | purpleCat1.LoadContent(this.Content, "purpleCat1"); | |
| 85 | purpleCat2.LoadContent(this.Content, "purpleCat2"); | |
| 86 | purpleCat3.LoadContent(this.Content, "purpleCat3"); | |
| 87 | purpleCat4.LoadContent(this.Content, "purpleCat4"); | |
| 88 | ||
| 89 | //load up the sprites and positions for the purple block | |
| 90 | purpleBlock.LoadSprites(purpleCat1, purpleCat2, purpleCat3, purpleCat4, | |
| 91 | new Vector2(250, 50), new Vector2(250, 0), new Vector2(200, 50), new Vector2(300, 50)); | |
| 92 | } | |
| 93 | ||
| 94 | /// <summary> | |
| 95 | /// UnloadContent will be called once per game and is the place to unload | |
| 96 | /// all content. | |
| 97 | /// </summary> | |
| 98 | protected override void UnloadContent() | |
| 99 | {
| |
| 100 | // TODO: Unload any non ContentManager content here | |
| 101 | } | |
| 102 | ||
| 103 | /// <summary> | |
| 104 | /// Allows the game to run logic such as updating the world, | |
| 105 | /// checking for collisions, gathering input, and playing audio. | |
| 106 | /// </summary> | |
| 107 | /// <param name="gameTime">Provides a snapshot of timing values.</param> | |
| 108 | protected override void Update(GameTime gameTime) | |
| 109 | {
| |
| 110 | // Allows the game to exit | |
| 111 | if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) | |
| 112 | this.Exit(); | |
| 113 | ||
| 114 | purpleBlock.updateSprites(gameTime); | |
| 115 | ||
| 116 | base.Update(gameTime); | |
| 117 | } | |
| 118 | ||
| 119 | /// <summary> | |
| 120 | /// This is called when the game should draw itself. | |
| 121 | /// </summary> | |
| 122 | /// <param name="gameTime">Provides a snapshot of timing values.</param> | |
| 123 | protected override void Draw(GameTime gameTime) | |
| 124 | {
| |
| 125 | GraphicsDevice.Clear(Color.White); | |
| 126 | ||
| 127 | //This is the sprite batch for the walls | |
| 128 | spriteBatch.Begin(); | |
| 129 | ||
| 130 | wallLeft.Draw(this.spriteBatch); | |
| 131 | wallRight.Draw(this.spriteBatch); | |
| 132 | ||
| 133 | spriteBatch.End(); | |
| 134 | ||
| 135 | //Individual sprite batch for each block | |
| 136 | Matrix purpleMatrix = purpleBlock.rotationMatrix; | |
| 137 | ||
| 138 | purpleBatch.Begin(SpriteSortMode.BackToFront, null, null, null, null, null, purpleMatrix); | |
| 139 | ||
| 140 | purpleBlock.Draw(purpleBatch); | |
| 141 | ||
| 142 | purpleBatch.End(); | |
| 143 | ||
| 144 | base.Draw(gameTime); | |
| 145 | } | |
| 146 | ||
| 147 | private void InitGraphicsMode(int width, int height, bool fullScreen) | |
| 148 | {
| |
| 149 | if (!fullScreen) | |
| 150 | {
| |
| 151 | if ((width <= GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width) && | |
| 152 | (height <= GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height)) | |
| 153 | {
| |
| 154 | graphics.PreferredBackBufferWidth = width; | |
| 155 | graphics.PreferredBackBufferHeight = height; | |
| 156 | graphics.IsFullScreen = fullScreen; | |
| 157 | graphics.ApplyChanges(); | |
| 158 | } | |
| 159 | } | |
| 160 | else | |
| 161 | {
| |
| 162 | foreach (DisplayMode dm in GraphicsAdapter.DefaultAdapter.SupportedDisplayModes) | |
| 163 | {
| |
| 164 | //Check the width and height of each of the GPU's display modes against the passed values | |
| 165 | if ((dm.Width == width) && (dm.Height == height)) | |
| 166 | {
| |
| 167 | //the mode is supported so set the appropriate buffer formats and apply changes | |
| 168 | graphics.PreferredBackBufferWidth = width; | |
| 169 | graphics.PreferredBackBufferHeight = height; | |
| 170 | graphics.IsFullScreen = fullScreen; | |
| 171 | graphics.ApplyChanges(); | |
| 172 | } | |
| 173 | } | |
| 174 | ||
| 175 | } | |
| 176 | }// end InitGraphicsMode() | |
| 177 | } | |
| 178 | } |