context: 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 Unity1918
  {
      public class Game1 : Microsoft.Xna.Framework.Game
      {
          GraphicsDeviceManager graphics;
          SpriteBatch spriteBatch;
          KeyboardState keyState;
          KeyboardState prevKeyState;
  
          SpriteFont menuFont, bea, sissy, michael, stan, sunna, hart, mary, man1, man2, glen;
          Texture2D mainMenu, testSun, realSun, blackScreen, trainScene, graveyardScene, stansHouseScene, beasHouseScene, townScene, wheatFieldScene, background, player;
          SoundEffect footstep, gravelFootstep, clothFootstep, grassFootstep, sandFootstep, stoneFootstep, woodFootstep;
          Song chior;
  
          // List of random values for positioning dialogue.
          List<int> randomXValues = new List<int>();
          List<int> randomYValues = new List<int>();
          Random random = new Random();
  
          // Sprite variables.
          Rectangle destRect, sourceRect;
          float elapsed;
          int spriteFrames = 0;
  
          // Speed of the sprite animation.
          float spriteDelay = 250f;
  
          // Stores the texts' alphas as percentages (0 to 1).
          List<float> textAlphas = new List<float>();
  
          // Stores ending quotes
          List<string> quotes = new List<string>();
  
          // Displacements for text outline.
          int xDisp = 0;
          int yDisp = 0;
          Color textColour;
  
          Color fade, gameFade;
  
          int screenNumber;
          double gameTickMin, gameTickSec, imageAlpha, fadeInc, fadeDelay, timerAlpha, postTimer;
          double startLoc, exitLoc, pointerLoc;
          double sunX, sunY, playerX, speed;
          string endQuote;
          bool toggleKey, fadeScreen, sunUp, death, finalTimer,firstPlay;
  
          public Game1()
          {
              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()
          {
              graphics.PreferredBackBufferWidth = 1280;
              graphics.PreferredBackBufferHeight = 720;
              graphics.ApplyChanges();
              //graphics.ToggleFullScreen();
              //testPlayerSprite = new AnimatedSprite.AnimatedTexture(new Vector2(0 + playerState * 64, 128), 0, 2, Convert.ToSingle(0.5));
  
              // Sprite's destination rectangle: looking right.
              destRect = new Rectangle(0, Window.ClientBounds.Height - 150, 104, 150);
  
              // Starting alpha values for the texts.
              // Specifies the maxmimum number of fading texts we can have on one screen.
              for (int i = 0; i < 30; i++)
              {
                  textAlphas.Add(1);
              }
  
              // Specifies number of random values.
              // Specifies the maximum x and y values for the text.
              for (int i = 0; i < 500; i++)
              {
                  randomXValues.Add(random.Next(0, 600));
                  randomYValues.Add(random.Next(0, 600));
              }
  
              intQuotes();
  
              screenNumber = 1;
  
              imageAlpha = 1;
              timerAlpha = 1;
              fadeInc = 3;
              fadeDelay = 0.035;
  
              startLoc = 600;
              exitLoc = 620;
              pointerLoc = startLoc;
              sunX = -50;
              sunY = 50;
              speed = 283;
              playerX = 50;
              postTimer = 0;
              sunUp = true;
              toggleKey = false;
              fadeScreen = false;
              finalTimer = false;
              death = false;
              firstPlay = 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()
          {
              spriteBatch = new SpriteBatch(GraphicsDevice);
  
              menuFont = Content.Load<SpriteFont>("Fonts/SpriteFont1");
              bea = Content.Load<SpriteFont>("Fonts/Bea's Font");
              sissy = Content.Load<SpriteFont>("Fonts/Sissy's Font");
              michael = Content.Load<SpriteFont>("Fonts/Michael's Font");
              stan = Content.Load<SpriteFont>("Fonts/Stan's Font");
              sunna = Content.Load<SpriteFont>("Fonts/Sunna's Font");
              hart = Content.Load<SpriteFont>("Fonts/Hart's Font");
              mary = Content.Load<SpriteFont>("Fonts/Mary's Font");
              man1 = Content.Load<SpriteFont>("Fonts/Man 1 Font");
              man2 = Content.Load<SpriteFont>("Fonts/Man 2 Font");
              glen = Content.Load<SpriteFont>("Fonts/Glen's Font");
  
              testSun = Content.Load<Texture2D>("Images/TestSun");
              realSun = Content.Load<Texture2D>("Images/sun");
              trainScene = Content.Load<Texture2D>("Images/Train Station");
              graveyardScene = Content.Load<Texture2D>("Images/Graveyard");
              stansHouseScene = Content.Load<Texture2D>("Images/Stan's House");
              beasHouseScene = Content.Load<Texture2D>("Images/Bea's House");
              townScene = Content.Load<Texture2D>("Images/Town");
              wheatFieldScene = Content.Load<Texture2D>("Images/Wheat Field");
              blackScreen = Content.Load<Texture2D>("Images/BlackScreen");
              mainMenu = Content.Load<Texture2D>("Images/MainMenu");
  
              player = Content.Load<Texture2D>("Walking Sprite Sheet");
              gravelFootstep = Content.Load<SoundEffect>("Footstep Sounds/Gravel Footstep");
              clothFootstep = Content.Load<SoundEffect>("Footstep Sounds/Cloth Footstep");
              grassFootstep = Content.Load<SoundEffect>("Footstep Sounds/Grass Footstep");
              sandFootstep = Content.Load<SoundEffect>("Footstep Sounds/Sand Footstep");
              stoneFootstep = Content.Load<SoundEffect>("Footstep Sounds/Stone Footstep");
              woodFootstep = Content.Load<SoundEffect>("Footstep Sounds/Wood Footstep");
              chior = Content.Load<Song>("Footstep Sounds/Ukrainian Chior");
          }
  
          protected override void UnloadContent()
          {
  
          }
  
          protected override void Update(GameTime gameTime)
          {
              // Allows the game to exit
              if (Keyboard.GetState().IsKeyDown(Keys.Escape))
                  this.Exit();
              if (!firstPlay)
              {
                  MediaPlayer.Play(chior);
                  firstPlay = true;
              }
  
              if (screenNumber > 1)
              {
                  elapsed += (float)gameTime.ElapsedGameTime.TotalMilliseconds;
                  animatePlayer(death);
              }
  
              prevKeyState = keyState;
              keyState = Keyboard.GetState();
  
              gameTickMin = gameTime.ElapsedGameTime.TotalMinutes;
              gameTickSec = gameTime.ElapsedGameTime.TotalSeconds;
  
              if (fadeScreen)
                  autoFade();
  
              if (screenNumber == 1)
                  mainMenuControls();
  
              if (death == true && screenNumber != 14)
              {
                  autoFade();
                  screenNumber = 14;
              }
  
              if (death == true)
              {
                  background = blackScreen;
                  footstep = null;
                  destRect.X += 1;
              }
  
              if (screenNumber > 1)
              {
                  moveSun();
                  gameFadeTimer();
              }
              if (screenNumber == 2)
              {
                  background = stansHouseScene;
                  footstep = stoneFootstep;
              }
              if (screenNumber == 3)
              {
                  background = wheatFieldScene;
                  footstep = grassFootstep;
              }
              if (screenNumber == 4)
              {
                  background = beasHouseScene;
                  footstep = sandFootstep;
              }
              if (screenNumber == 5)
              {
                  background = trainScene;
                  footstep = gravelFootstep;
              }
              if (screenNumber == 6)
              {
                  background = beasHouseScene;
                  footstep = sandFootstep;
              }
              if (screenNumber == 7)
              {
                  background = trainScene;
                  footstep = gravelFootstep;
              }
              if (screenNumber == 8)
              {
                  background = blackScreen;
                  footstep = woodFootstep;
              }
              if (screenNumber == 9)
              {
                  background = townScene;
                  footstep = sandFootstep;
              }
              if (screenNumber == 10)
              {
                  background = graveyardScene;
                  footstep = grassFootstep;
              }
              if (screenNumber == 11)
              {
                  background = stansHouseScene;
                  footstep = stoneFootstep;
              }
              if (screenNumber == 12)
              {
                  background = townScene;
                  footstep = sandFootstep;
              }
              if (screenNumber == 13)
              {
                  background = graveyardScene;
                  footstep = grassFootstep;
              }
              if (screenNumber > 13)
                  death = true;
  
              if (destRect.X > Window.ClientBounds.Width)
                  fadeScreen = true;
  
              if (sunX >= Window.ClientBounds.Width)
              {
                  death = true;
                  textColour.A = 0;
              }
              endQuote = quotes[sunSet()];
  
              if ((death && textColour.A == 100) || finalTimer)
              {
                  finalTimer = true;
                  postTimer += gameTickSec;
              }
  
              if (postTimer > 3)
              {
                  // Sprite's destination rectangle: looking right.
                  destRect = new Rectangle(0, Window.ClientBounds.Height - 150, 104, 150);
  
                  screenNumber = 1;
  
                  imageAlpha = 1;
                  timerAlpha = 1;
                  fadeInc = 3;
                  fadeDelay = 0.035;
  
                  startLoc = 600;
                  exitLoc = 620;
                  pointerLoc = startLoc;
                  sunX = -50;
                  sunY = 50;
                  speed = 283;
                  playerX = 50;
                  postTimer = 0;
                  finalTimer = false;
                  sunUp = true;
                  toggleKey = false;
                  fadeScreen = false;
                  death = false;
                  firstPlay = false;
              }
  
              base.Update(gameTime);
          }
  
          protected override void Draw(GameTime gameTime)
          {
              GraphicsDevice.Clear(Color.CornflowerBlue);
  
              // TODO: Add your drawing code here
              spriteBatch.Begin();
                  
              if (screenNumber == 1)
              {
                  spriteBatch.Draw(mainMenu, new Rectangle(0, 0, Window.ClientBounds.Width, Window.ClientBounds.Height), Color.White);
                  spriteBatch.DrawString(menuFont, "START", new Vector2(100, Convert.ToSingle(startLoc)), Color.White);
                  spriteBatch.DrawString(menuFont, "EXIT", new Vector2(100, Convert.ToSingle(exitLoc)), Color.White);
                  spriteBatch.DrawString(menuFont, ">", new Vector2(80, Convert.ToSingle(pointerLoc)), Color.White);
              }
  
              // Draw sun.
              if (screenNumber > 1)
              {
                  spriteBatch.Draw(realSun, new Rectangle(Convert.ToInt32(sunX), Convert.ToInt32(sunY), testSun.Width, testSun.Height), Color.White);
                  spriteBatch.Draw(background, new Rectangle(0, 0, Window.ClientBounds.Width, Window.ClientBounds.Height), Color.White);
              }
  
              // Draw player.
              if (!death && screenNumber != 1)
                  spriteBatch.Draw(player, destRect, sourceRect, Color.White);
              if (death)
                  spriteBatch.Draw(player, destRect, sourceRect, textColour);
  
              if (screenNumber != 1)
                  spriteBatch.Draw(blackScreen, new Vector2(0, 0), gameFade);
              if (fadeScreen)
                  spriteBatch.Draw(blackScreen, new Vector2(0, 0), fade);
  
              if (screenNumber == 2)
              {
                  dialogue(0, 100, stan, "Goddammit Ardell! Jesus.", death);
                  dialogue(1, 200, stan, "Well...", death);
                  dialogue(2, 400, stan, "What the hell...", death);
                  dialogue(3, 700, stan, "Oh, Jesus! Ardell? Ardell?", death);
                  dialogue(4, 1100, stan, "Even now...", death);
              }
  
              if (screenNumber == 3)
              {
                  dialogue(0, 100, michael, "Ah! See this day? This is a good day!", death);
                  dialogue(1, 200, sissy, "You're cold.", death);
                  dialogue(2, 300, michael, "Am not.", death);
                  dialogue(3, 450, michael, "Huh? What do you do?", death);
                  dialogue(4, 550, sissy, "Just suck on it. It'll warm you up.", death);
                  dialogue(5, 750, michael, "The end of the world doesn't scare you?", death);
                  dialogue(6, 850, sissy, "Not if it's this year.", death);
                  dialogue(7, 1000, michael, "What are you doing?", death);
                  dialogue(8, 1100, sissy, "Keeping you inside your skin for a little longer.", death);
              }
  
              if (screenNumber == 4)
              {
                  dialogue(0, 100, bea, "You'll get him sent back home.", death);
                  dialogue(1, 200, sissy, "There's more important things right now.", death);
                  dialogue(2, 300, bea, "The end of the world?", death);
                  dialogue(3, 400, sissy, "The end of the world.", death);
                  dialogue(4, 550, bea, "You know, a woman can be a slacker too.", death);
                  dialogue(5, 650, sissy, "Slacker?", death);
                  dialogue(6, 750, bea, "Ow! Sissy! Don't!", death);
                  dialogue(7, 900, sissy, "There's a soldier on the next train.", death);
                  dialogue(8, 1000, bea, "Glen?", death);
                  dialogue(9, 1100, sissy, "Let's go.", death);
              }
              if (screenNumber == 5)
              {
                  dialogue(0, 100, hart, "Hello?", death);
                  dialogue(1, 250, hart, "Hello?", death);
                  dialogue(2, 350, stan, "Jesus!", death);
                  dialogue(3, 450, mary, "Let me help you up.", death);
                  dialogue(4, 600, sissy, "Are you all right?", death);
                  dialogue(5, 750, hart, "I'm fine, I'm fine. Thank you. Thank you.", death);
                  dialogue(6, 850, stan, "You're in Unity, son.", death);
                  dialogue(7, 950, hart, "Yes, they called it out on the train.", death);
                  dialogue(8, 1100, hart, "It's not quite as flat as I was told it would be.", death);
              }
              if (screenNumber == 6)
              {
                  dialogue(0, 100, michael, "Look at that moon!", death);
                  dialogue(1, 150, sissy, "Listen", death);
                  dialogue(2, 200, michael, "Yeah.", death);
                  dialogue(3, 250, sissy, "Hear it?", death);
                  dialogue(4, 300, michael, "Yeah.", death);
                  dialogue(5, 350, sissy, "Silence.", death);
                  dialogue(6, 400, michael, "Yeah.", death);
                  dialogue(7, 500, sissy, "It's all ours.", death);
                  dialogue(8, 600, michael, "Do you like being scared?", death);
                  dialogue(9, 650, sissy, "Yeah. Do you?", death);
                  dialogue(10, 750, michael, "Yeah. Everything changes in the dark.", death);
                  dialogue(11, 900, michael, "I think it's scarier being in here!", death);
                  dialogue(12, 950, sissy, "I know.", death);
                  dialogue(13, 1000, michael, "They're like ghosts.", death);
                  dialogue(14, 1050, sissy, "I know.", death);
                  dialogue(15, 1150, sissy, "Michael.", death);
              }
              if (screenNumber == 7)
              {
                  dialogue(0, 100, bea, "I'm sorry. I'm sorry. Oh, Sissy.", death);
                  dialogue(1, 150, bea, "Oh, Sissy. My poor Sissy.", death);
                  dialogue(2, 300, sissy, "You're happy.", death);
                  dialogue(3, 350, bea, "Sissy?", death);
                  dialogue(4, 450, sissy, "All you've ever wanted was for me to lose.", death);
                  dialogue(5, 500, bea, "Sissy...", death);
                  dialogue(6, 600, sissy, "You're glad he's dead.", death);
                  dialogue(7, 650, bea, "Oh, Sissy. I am not.", death);
                  dialogue(8, 700, sissy, "You are.", death);
                  dialogue(9, 750, bea, "No.", death);
                  dialogue(10, 850, sissy, "Well, guess what. So am I.", death);
                  dialogue(11, 900, sissy, "And you can't take him away from me.", death);
                  dialogue(12, 950, sissy, "Because he's mine.", death);
                  dialogue(13, 1000, sissy, "Too bad, Beatrice. I'm not joining you there.", death);
                  dialogue(14, 1050, bea, "Where?", death);
                  dialogue(15, 1150, bea, "Sissy? Where?", death);
              }
              if (screenNumber == 8)
              {
                  dialogue(0, 100, hart, "Sunna? Sunna? Out again.", death);
                  dialogue(1, 200, hart, "There's something dripping.", death);
                  dialogue(2, 300, hart, "You've got a leak somewhere, young lady.", death);
                  dialogue(3, 350, hart, "And I'm going to find it.", death);
                  dialogue(4, 450, hart, "Ooo, that's the wall.", death);
                  dialogue(5, 600, hart, "There's the stove and it's still going strong.", death);
                  dialogue(6, 700, hart, "Aw, shit. What the hell was in there?", death);
                  dialogue(7, 800, hart, "Christ! Okay, okay, okay.", death);
                  dialogue(8, 850, hart, "Let's get our story straight.", death);
                  dialogue(9, 950, hart, "Cat snuck in, did cat things. Don't blame the blind.", death);
                  dialogue(10, 1050, hart, "Sorry Sunna.", death);
                  dialogue(11, 1150, hart, "You'll have to fix your own drip.", death);
              }
              if (screenNumber == 9)
              {
                  dialogue(0, 100, man1, "Fred?", death);
                  dialogue(1, 150, man2, "Who's that?", death);
                  dialogue(2, 200, man1, "Is that you, Fred?", death);
                  dialogue(3, 250, man2, "Ted?", death);
                  dialogue(4, 300, man1, "Fred!", death);
                  dialogue(5, 350, man2, "Ted! Geez, how are you?", death);
                  dialogue(6, 400, man1, "Oh, real good.", death);
                  dialogue(7, 450, man2, "You done threshing then?", death);
                  dialogue(8, 500, man1, "Oh yeah, you?", death);
                  dialogue(9, 550, man2, "Oh, nearly, though.", death);
                  dialogue(10, 600, man1, "Well that'll be good, then.", death);
                  dialogue(11, 650, man1, "It's like a ghost town down here.", death);
                  dialogue(12, 700, man2, "Yup.", death);
                  dialogue(13, 800, man2, "Who was that?", death);
                  dialogue(14, 850, man1, "Wasn't that Gadfly's wife?", death);
                  dialogue(15, 900, man2, "Was it?", death);
                  dialogue(16, 950, man1, "I thought it was. Yep it's quiet down here.", death);
                  dialogue(17, 1000, man2, "I read that the flu is uh... might be the germans.", death);
                  dialogue(18, 1100, man1, "Is that right. I thought it might be the germs.", death);
              }
              if (screenNumber == 10)
              {
                  dialogue(0, 50, mary, "Where's Sissy?", death);
                  dialogue(1, 100, bea, "I don't know.", death);
                  dialogue(2, 150, mary, "She said she'd come.", death);
                  dialogue(3, 250, bea, "She's been acting strange. Let's start.", death);
                  dialogue(4, 350, mary, "Okay. Um... Dearly beloved,", death);
                  dialogue(6, 450, bea, "Sunna's looking at us.", death);
                  dialogue(7, 550, mary, "I don't care.", death);
  
gt:                 dialogue(10, 650, bea, "We should go.", death);