Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- 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 Rings
- {
- class GameScreen : Screen
- {
- //TEMPORARY VARIABLE DECLARATIONS AND ASSIGNMENTS
- List<Ring> rings = new List<Ring>(); //A list of all of the rings in the game screen
- Texture2D myWedge; //A texture for all wedges. Will be completely redone later
- Vector2 textureOrigin; //A Vector2 that represents the origin of the myWedge texture
- Vector2 screenCenter; //A Vector2 that represents the center of the screen
- Factory factory; //A factory which will be responsible for generating rings, wedges, and balls
- Random nextRand = new Random();
- bool drawWedges = true; //A bool that represents whether or not anything should be drawn on screen
- public int Level { get; set; } //A property that represents the current level in the game
- /// <summary>
- /// The 'standard' constructor
- /// </summary>
- /// <param name="graphics">The game's graphics device manage</param>
- /// <param name="content">The game's content pipeline</param>
- /// <param name="spriteBatch">The game's spritebatch</param>
- /// <param name="theGame">The game itself (used for exiting the application</param>
- public GameScreen(GraphicsDeviceManager graphics, ContentManager content, SpriteBatch spriteBatch, Game1 theGame) : base(graphics, content, spriteBatch, theGame)
- {
- //TEMPORARY CODE
- Initialize();
- LoadContent();
- }
- /// <summary>
- /// This function initializes the variables used by the GameScreen class
- /// </summary>
- protected override void Initialize()
- {
- base.Initialize();
- //Sets the initial level to 1
- this.Level = 1;
- //Creates a new Factory, which is responsible for creating balls, wedges, and rings
- factory = new Factory(this);
- //Creates the list of rings which will be drawn to the screen
- rings = factory.CreateRings();
- //A Vector2 that represents the center of the screen
- screenCenter = new Vector2(graphics.PreferredBackBufferWidth / 2, graphics.PreferredBackBufferHeight / 2);
- }
- /// <summary>
- /// This function loads the GameScreen content into the game's ContentManager
- /// </summary>
- protected override void LoadContent()
- {
- base.LoadContent();
- myWedge = Content.Load<Texture2D>("wedge6");
- textureOrigin = new Vector2(myWedge.Width, myWedge.Height / 2);
- }
- /// <summary>
- /// This function updates the game logic for the GameScreen class
- /// </summary>
- /// <param name="gameTime">Provides a snapshot of timing values</param>
- public override void Update(GameTime gameTime)
- {
- //return;
- //Grabs the current keyboard state
- KeyboardState currentKeyboardState = Keyboard.GetState();
- //Updates the rotation on all visible rings
- for (int i = 0; i < rings.Count; i++)
- {
- //rings[i].Rotation++;
- if (rings[i].Visible == true)
- {
- rings[i].Rotation -= 2;
- }
- }
- //Quits the game if the escape key is pressed
- if (currentKeyboardState.IsKeyDown(Keys.Escape))
- theGame.Exit();
- //toggles whether or not to draw wedges
- if (currentKeyboardState.IsKeyDown(Keys.Space) && !oldKeyboardState.IsKeyDown(Keys.Space))
- drawWedges = !drawWedges;
- //Updates the old keyboard state to what the keyboard state was for this update
- oldKeyboardState = currentKeyboardState;
- }
- /// <summary>
- /// Draws the GameScreen
- /// </summary>
- /// <param name="gameTime"></param>
- public override void Draw(GameTime gameTime)
- {
- base.Draw(gameTime);
- //return;
- //TEMPORARY CODE
- //These variables will be used so that values don't have to constantly be retrieved from objects
- Position wedgePosition;
- int ringCount;
- int wedgeCount;
- //END TEMPORARY CODE
- //If wedges should be drawn, do this
- if (drawWedges)
- {
- //Grabs the count of rings from the rings list
- ringCount = rings.Count;
- //loops through all of the rings
- for (int i = 0; i < ringCount; i++)
- {
- //Grabs the number of wedges in each ring
- wedgeCount = rings[i].Wedges.Count;
- //Loops through all of the wedges in the ring
- for (int j = 0; j < wedgeCount; j++)
- {
- //If the wedges is visible, draw it
- if (rings[i].Wedges[j].Visible)
- {
- //Grabs the wedge's current position once, so it doesn't have to be repeatedly retrieved
- wedgePosition = rings[i].getWedgePosition(j);
- //draw the wedge to the screen at the proper rotation
- spriteBatch.Draw(myWedge, screenCenter + wedgePosition.LocationVector, null, Color.White, wedgePosition.Radians, textureOrigin, 1f, SpriteEffects.None, 0f);
- }//ends the if (rings[i].Wedges[j].Visible) block
- }//ends the for (int j = 0; j < wedgeCount; j++) loop
- }//ends the for (int i = 0; i < ringCount; i++) loop
- }//ends the if (drawWedges) block
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment