Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// <summary>
- /// This screen implements the actual game logic.
- /// </summary>
- public class GameplayScreen : GameScreen
- {
- /// <summary>
- /// This screen implements the actual game logic.
- /// </summary>
- public class GameplayScreen : GameScreen
- {
- #region Fields
- Renderer myRenderer; // Renderer that draws particles to screen
- ParticleEffect myEffect; // Particle effect object to store the info about particle
- // GraphicsDevice graphicsDevice;
- // GraphicsDeviceManager graphics;
- private int _selectedStage; // Stage select
- private PowerupControl _powerUpControl;
- private KeyboardState _oldState;
- //// Turbo Stuff
- public float disableTurboCooldown;
- public int twoSecondBurst = 2000; // Two Seconds
- public int fiveSecondCoolDown = 5000; // Five seconds
- public int coolDown; // Cooldown Factor
- public int coolDownSpeed = 10;
- DebuggingTools debuggingTools; // Debugging tools screen
- // For shaders
- Effect gscaleEffect;
- KeyboardState current, previous;
- public bool gScaleActivated;
- public float ElapsedTime, percentscale, percent;
- private bool resetTimerInUse;
- private int resetTimer;
- // Graphics stuff
- private ContentManager contentManager;
- private SpriteFont arial;
- private HUD hud;
- private Menu menu;
- private Input input;
- private float pauseAlpha;
- private Random random;
- private SpriteBatch spriteBatch;
- private Texture2D backgroundTexture;
- private double screenLoadDelay; // The timer for when the menu will appear after a game resets
- // private static Game1 game;
- private Game game;
- public static GameplayScreen Instance;
- public static GameStates gamestate;
- public int screenHeight, screenWidth;
- public Ball ball;
- public Bat leftBat;
- public AIBat rightBat;
- public bool side, lastScored;
- /// <summary>
- /// Constructor.
- /// </summary>
- public GameplayScreen(Game game, int selectedStage):base(game)
- {
- TransitionOnTime = TimeSpan.FromSeconds(1.5);
- TransitionOffTime = TimeSpan.FromSeconds(0.5);
- this._selectedStage = selectedStage;
- }
- protected void Initialize(int selectedStage)
- {
- // Start the score off at 0
- lastScored = false;
- menu = new Menu(); // Draws text on the screen after the game to say who won
- resetTimerInUse = true;
- resetTimer = 0;
- SetUpSingle(); // Sets up a single player game
- ball = new Ball(contentManager,
- new Vector2(ScreenManager.Game.GraphicsDevice.Viewport.TitleSafeArea.Width,
- ScreenManager.Game.GraphicsDevice.Viewport.TitleSafeArea.Height),
- leftBat, rightBat);
- ParticleEmitter.AddEmitter(EmitterType.BlueParticle, ball.Position, ball);
- input = new Input();
- hud = new HUD(this);
- debuggingTools = new DebuggingTools(this,Game);
- gamestate = GameStates.Running;
- // Initializes the previously chosen stage
- this._selectedStage = selectedStage;
- // JEP 5/17 - draw code uses screenwidth/height
- screenWidth = ScreenManager.Game.GraphicsDevice.Viewport.TitleSafeArea.Width;
- screenHeight = ScreenManager.Game.GraphicsDevice.Viewport.TitleSafeArea.Height;
- // Sets the default percent scale for the black and white SlowMo effect
- percentscale = 0.01f;
- gScaleActivated = false;
- // Create new renderer and set its graphics devide to "this" device
- myRenderer = new SpriteBatchRenderer
- {
- GraphicsDeviceService = Game1.graphics
- };
- myEffect = new ParticleEffect();
- }
- /// <summary>
- /// Load graphics content for the game.
- /// </summary>
- public override void LoadContent()
- {
- if (contentManager == null)
- {
- contentManager = new ContentManager(ScreenManager.Game.Services, "Content");
- }
- this.Initialize(_selectedStage);
- arial = contentManager.Load<SpriteFont>(@"gfx/fonts/Arial"); // for game scores
- if (_selectedStage == 0)
- {
- //Load the 1st stage selected
- backgroundTexture = contentManager.Load<Texture2D>(@"gfx/Backgrounds/StageBackgroundScreen1");
- AudioManager.Instance.PlayStage1Music(); // Plays the music from AudioManager class
- }
- if (_selectedStage == 1)
- {
- backgroundTexture = contentManager.Load<Texture2D>(@"gfx/Backgrounds/StageBackgroundScreen2");
- AudioManager.Instance.PlayStage2Music(); // Plays the music from AudioManager class
- }
- if (_selectedStage == 2)
- {
- backgroundTexture = contentManager.Load<Texture2D>(@"gfx/Backgrounds/StageBackgroundScreen3");
- AudioManager.Instance.PlayStage3Music(); // Plays the music from AudioManager class
- }
- hud.LoadContent(contentManager);
- ScreenManager.Game.ResetElapsedTime();
- // For black and white shader. Starts off by default.
- gscaleEffect = contentManager.Load<Effect>(@"gfx/effects/hit");
- //percent = 1;
- debuggingTools.LoadContent(contentManager);
- spriteBatch = new SpriteBatch(ScreenManager.Game.GraphicsDevice);
- // Content for Mercury
- myEffect = contentManager.Load<ParticleEffect>("BasicExplosion");
- myEffect.LoadContent(contentManager);
- myEffect.Initialise();
- myRenderer.LoadContent(contentManager);
- }
- //////////////////////////////////// DRAW ///////////////////////////////////////////////////////
- /// <summary>
- /// Draws the gameplay screen.
- /// </summary>
- public override void Draw(GameTime gameTime)
- {
- ScreenManager.GraphicsDevice.Clear(ClearOptions.Target, Color.CornflowerBlue, 0, 0);
- SpriteBatch spriteBatch = ScreenManager.SpriteBatch;
- if (gamestate == GameStates.Running)
- {
- spriteBatch.Begin();
- // Draws background
- spriteBatch.Draw(backgroundTexture, new Rectangle(0, 0, screenWidth, screenHeight), Color.White);
- //// Slow mo stuff from Michael Harts
- //spriteBatch.Draw(rect, new Rectangle((int)position.X, (int)position.Y, 300, 300), Color.Red);
- //Draws the HUD
- hud.Draw(gameTime, spriteBatch);
- // Draws the bats and ball
- leftBat.Draw(spriteBatch);
- rightBat.Draw(spriteBatch);
- // Draw the ball
- ball.Draw(spriteBatch);
- // Draws the debugging tools
- debuggingTools.Draw(spriteBatch);
- // Draws Mercury
- myRenderer.RenderEffect(myEffect);
- base.Draw(gameTime);
- spriteBatch.End();
- }
- //////////////////////////////////////////// UPDATE ////////////////////////////////////////
- /// <summary>
- /// Lets the game respond to player input. Unlike the Update method,
- /// this will only be called when the gameplay screen is active.
- /// </summary>
- public override void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen)
- {
- base.Update(gameTime, otherScreenHasFocus, false);
- // Draws the debugging tools on sreen
- // get the latest mouse state
- MouseState ms = Mouse.GetState();
- if (ms.LeftButton == ButtonState.Pressed)
- {
- myEffect.Trigger(new Vector2(500,500));
- }
- // "Deltatime" ie, time since last update call
- float SecondsPassed = (float)gameTime.ElapsedGameTime.TotalSeconds;
- myEffect.Update(SecondsPassed);
- // Draws the debugging tols
- debuggingTools.Update(gameTime);
- //////////////////// If the game is *not* paused, then update the following: /////////////////////
- if (IsActive)
- {
- KeyboardState thisstate = Keyboard.GetState();
- _oldState = thisstate;
- if (thisstate.IsKeyDown(Keys.Space) && _oldState.IsKeyUp(Keys.Space))
- _powerUpControl.AddPower(10);
- // Updating the input
- input.Update();
- // Updating bat position
- leftBat.UpdatePosition(ball, gameTime);
- rightBat.UpdatePosition(ball, gameTime);
- // Updating the ball position
- ball.UpdatePosition(gameTime);
- }
- }
- }
- }
RAW Paste Data