// draws shit.
        void DrawGameObject(GameObject gameobject)
        {
            foreach (ModelMesh mesh in gameobject.model.Meshes)
            {
                foreach (BasicEffect effect in mesh.Effects)
                {
                    effect.EnableDefaultLighting();
                    effect.PreferPerPixelLighting = true;

                    effect.World =  // TBH no f*****g idea whats up here.
                        Matrix.CreateFromYawPitchRoll(
                        gameobject.rotation.Y,
                        gameobject.rotation.X,
                        gameobject.rotation.Z) *

                        Matrix.CreateScale(gameobject.scale) *

                        Matrix.CreateTranslation(gameobject.position);

                    effect.Projection = cameraProjectionMatrix;
                    effect.View = cameraViewMatrix;
                }
                mesh.Draw();
            }
        }
        /// <summary>
        /// Load graphics content for the game.
        /// </summary>
        public override void LoadContent()
        {
            if (content == null)
                content = new ContentManager(ScreenManager.Game.Services, "Content");

            gameFont = content.Load<SpriteFont>("gamefont");

            // A real game would probably have more content than this sample, so
            // it would take longer to load. We simulate that by delaying for a
            // while, giving you a chance to admire the beautiful loading screen.
            //Thread.Sleep(1000);

            // once the load has finished, we use ResetElapsedTime to tell the game's
            // timing mechanism that we have just finished a very long frame, and that
            // it should not try to catch up.
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(ScreenManager.GraphicsDevice);

            //sound crap.
            //audioEngine = new AudioEngine("Content\\Audio\\ProjectAudio.xap");
            //waveBank = new WaveBank(audioEngine, "Content\\Audio\\Wave Bank.xwb");
            //soundBank = new SoundBank(audioEngine, "Content\\Audio\\Sound Bank.xsb");
            #region GameObjects
            ship.model = content.Load<Model>(
                "Models\\Ship"); // loading the ship model
            ship.scale = 20.0f;
            ship.alive = true;
            ship.projType = 5;
            ship.special = 5; //hit points

            bullets = new GameObject[maxBullets]; // loads up the spread cannon.
            for (int i = 0; i < maxBullets; i++)
            {
                bullets[i] = new GameObject();
                bullets[i].model =
                    content.Load<Model>("Models\\bullet");
                bullets[i].scale = 3.0f;
                bullets[i].special = 0; //Doesn't currently use special, but that's ok
                bullets[i].projType = 1;
            }

            lasers = new GameObject[maxLasers]; // loads up the laser cannon.
            for (int i = 0; i < maxLasers; i++)
            {
                lasers[i] = new GameObject();
                lasers[i].model =
                    content.Load<Model>("Models\\laser");
                lasers[i].scale = 3.0f;
                lasers[i].rotation.X = MathHelper.PiOver2;
                lasers[i].special = 0;
                lasers[i].projType = 2;
            }

            missiles = new GameObject[maxMissiles];
            for (int i = 0; i < maxMissiles; i++)
            {
                missiles[i] = new GameObject();
                missiles[i].model =
                    content.Load<Model>("Models\\missile");
                missiles[i].scale = 6f;
                missiles[i].projType = 3;
            }
            shields = new GameObject[maxShields];
            for (int i = 0; i < maxShields; i++)
            {
                shields[i] = new GameObject();
                shields[i].model = content.Load<Model>("Models\\bullet"); //TODO: New graphic?
                shields[i].scale = 2.0f;
                shields[i].projType = 4;
            }
            #region enemydeclarations

            enemyShields = new GameObject[maxEnemyShields];
            for (int i = 0; i < maxEnemyShields; i++)
            {
                enemyShields[i] = new GameObject();
                enemyShields[i].model = content.Load<Model>(
                    "Models\\bullet");
                enemyShields[i].scale = 2f;

            }

            enemySquares = new GameObject[maxBadGuy];
            for (int i = 0; i < maxBadGuy; i++)
            {
                enemySquares[i] = new GameObject();
                enemySquares[i].model = content.Load<Model>(
                    "Models\\Diamond");
                enemySquares[i].scale = 7.0f;
            }

            enemyCubePacks = new GameObject[maxBadGuy];
            for (int i = 0; i < maxBadGuy; i++)
            {
                enemyCubePacks[i] = new GameObject();
                enemyCubePacks[i].model = content.Load<Model>(
                    "Models\\BevelCubes");
                enemyCubePacks[i].scale = 12.0f;
            }

            enemyCubes = new GameObject[maxCubes];
            for (int i = 0; i < maxCubes; i++)
            {
                enemyCubes[i] = new GameObject();
                enemyCubes[i].model = content.Load<Model>(
                    "Models\\BevelCube");
                enemyCubes[i].scale = 10.0f;
                enemyCubes[i].special = 0;
            }

            enemyChargers = new GameObject[maxBadGuy];
            for (int i = 0; i < maxBadGuy; i++)
            {
                enemyChargers[i] = new GameObject();
                enemyChargers[i].model = content.Load<Model>(
                    "Models\\LCharger");
                enemyChargers[i].scale = 10.0f;
                enemyChargers[i].special = 0;
                //enemyChargers[i].rotation.X = -90;
                //enemyChargers[i].rotation.Z = -45;
                enemyChargers[i].projType = i;
            }

            enemyReflectors = new GameObject[maxBadGuy];
            for (int i = 0; i < maxBadGuy; i++)
            {
                enemyReflectors[i] = new GameObject();
                enemyReflectors[i].model = content.Load<Model>("Models\\RingShape");
                enemyReflectors[i].scale = 5.0f;
                enemyReflectors[i].special = 0;
            }
            enemyDodgers= new GameObject[maxBadGuy];
            for (int i = 0; i < maxBadGuy; i++)
            {
                enemyDodgers[i]  = new GameObject();
                enemyDodgers[i].model = content.Load<Model>("Models\\RingShape");
                enemyDodgers[i].scale = 5.0f;
                enemyDodgers[i].special = 0;
            }
            enemySnakes= new GameObject[maxBadGuy];
            for (int i = 0; i < maxBadGuy; i++)
            {
                enemySnakes[i]  = new GameObject();
                enemySnakes[i].model = content.Load<Model>("Models\\RingShape");
                enemySnakes[i].scale = 5.0f;
                enemySnakes[i].special = 0;
            }
            enemyCowards= new GameObject[maxBadGuy];
            for (int i = 0; i < maxBadGuy; i++)
            {
                enemyCowards[i]  = new GameObject();
                enemyCowards[i].model = content.Load<Model>("Models\\RingShape");
                enemyCowards[i].scale = 5.0f;
                enemyCowards[i].special = 0;
            }
            enemyFood= new GameObject[maxBadGuy];
            for (int i = 0; i < maxBadGuy; i++)
            {
                enemyFood[i]  = new GameObject();
                enemyFood[i].model = content.Load<Model>("Models\\RingShape");
                enemyFood[i].scale = 5.0f;
                enemyFood[i].special = 0;
            }
            enemyPlaceholder1 = new GameObject[maxBadGuy];
            for (int i = 0; i < maxBadGuy; i++)
            {
                enemyPlaceholder1[i]  = new GameObject();
                enemyPlaceholder1[i].model = content.Load<Model>("Models\\RingShape");
                enemyPlaceholder1[i].scale = 5.0f;
                enemyPlaceholder1[i].special = 0;
            }
            enemyPlaceholder2 = new GameObject[maxBadGuy];
            for (int i = 0; i < maxBadGuy; i++)
            {
                enemyPlaceholder2[i] = new GameObject();
                enemyPlaceholder2[i].model = content.Load<Model>("Models\\RingShape");
                enemyPlaceholder2[i].scale = 5.0f;
                enemyPlaceholder2[i].special = 0;
            }
            enemyPlaceholder3 = new GameObject[maxBadGuy];
            for (int i = 0; i < maxBadGuy; i++)
            {
                enemyPlaceholder3[i] = new GameObject();
                enemyPlaceholder3[i].model = content.Load<Model>("Models\\RingShape");
                enemyPlaceholder3[i].scale = 5.0f;
                enemyPlaceholder3[i].special = 0;
            }
            enemyPlaceholder4 = new GameObject[maxBadGuy];
            for (int i = 0; i < maxBadGuy; i++)
            {
                enemyPlaceholder4[i] = new GameObject();
                enemyPlaceholder4[i].model = content.Load<Model>("Models\\RingShape");
                enemyPlaceholder4[i].scale = 5.0f;
                enemyPlaceholder4[i].special = 0;
            }

            #endregion

            stars = new GameObject[maxStars];
            for (int i = 0; i < maxStars; i++)
            {
                stars[i] = new GameObject();
                stars[i].model = content.Load<Model>(
                    "Models\\star");
            }
            #endregion

            messageQueue = new string[maxMQueue];
            messageTicks = new int[maxMQueue];
            messagePos = new Vector2[maxMQueue];
            for (int i = 0; i < maxMQueue; i++)
            {
                messageQueue[i] = "";
                messageTicks[i] = 0;
                messagePos[i] = new Vector2(0, 0);
            }

            font = content.Load<SpriteFont>("Fonts\\GameFont");
            // Necessary ? (vpRect)
            viewportRect = new Rectangle(0, 0,
                ScreenManager.GraphicsDevice.Viewport.Width,
                ScreenManager.GraphicsDevice.Viewport.Height);

            ScreenManager.Game.ResetElapsedTime();
        }
 void DetonateMissile(GameObject missile)
 {
     if (missile.special < 0)
     {
         missile.alive = true;
     }
     else if (missileLvl > 1)
     {
         missile.alive = true;
         missile.model =
                 content.Load<Model>("Models\\bullet"); //placeholder
         missile.special = -10;
         missile.velocity = Vector3.Zero;
     }
 }
        void testCollision(GameObject bullet)
        {
            BoundingSphere bulletsphere =
                bullet.model.Meshes[0].BoundingSphere;
            bulletsphere.Center = bullet.position;
            bulletsphere.Radius += bullet.scale;

            foreach (GameObject shield in enemyShields)
            {
                if (shield.alive)
                {
                    if (shield.special > 0)
                    {
                        BoundingSphere squaresphere =
                        shield.model.Meshes[0].BoundingSphere;
                        squaresphere.Center = new Vector3 (shield.position.X, shield.position.Y, 0);

                        squaresphere.Radius += (shield.scale * 4);//shields detect at larger radius than they exist

                        if (squaresphere.Intersects(bulletsphere))
                        {
                            bullet.alive = false;
                            if (bullet.projType == 4) //projectile is shield
                            {

                                bullet.alive = true;
                                DamageShields(1f);
                                shield.alive = false;

                            }
                            else if (bullet.projType == 5) //projectile is SHIP!!
                            {
                                ShipHit();

                            }
                            else if (bullet.projType == 3)//projectile is missile
                            {
                                DetonateMissile(bullet);
                            }
                            break;
                        }
                    }
                }
            }

            foreach (GameObject square in enemySquares)
            {
                if (square.alive)
                {
                    BoundingSphere squaresphere =
                        square.model.Meshes[0].BoundingSphere;
                    squaresphere.Center = square.position;
                    squaresphere.Radius += (square.scale * 2);

                    if (squaresphere.Intersects(bulletsphere))
                    {
                        //play sound
                        score ++;
                        checkLevelUP();
                        bullet.alive = false;
                        if (bullet.projType == 4) //projectile is shield
                        {

                            bullet.alive = true;
                            DamageShields(10f);

                        }
                        else if (bullet.projType == 5) //projectile is SHIP!!
                        {
                            ShipHit();
                            score--;
                        }
                        else if (bullet.projType == 3)//projectile is missile
                        {
                            DetonateMissile(bullet);
                        }
                        square.alive = false;
                        break;
                    }
                }
            }
            foreach (GameObject cubePack in enemyCubePacks)
            {
                if (cubePack.alive)
                {
                    BoundingSphere cubePackssphere =
                        cubePack.model.Meshes[0].BoundingSphere;
                    cubePackssphere.Center = cubePack.position;
                    cubePackssphere.Radius += (cubePack.scale * 2);

                    if (cubePackssphere.Intersects(bulletsphere))
                    {
                        score += 3;
                        checkLevelUP();
                        bullet.alive = false;
                        cubePack.alive = false;
                        if (bullet.projType == 4) //projectile is shield
                        {
                            DamageShields(10f);
                            bullet.alive = true;
                        }
                        else if (bullet.projType == 3)//projectile is missile
                        {
                            DetonateMissile(bullet);
                        }
                        else if (bullet.projType == 5) //projectile is SHIP!!
                        {
                            score -= 3;
                            ShipHit();
                        }

                        Vector3 scatterRot = new Vector3 (MathHelper.Lerp(0f, 1f, (float)r.NextDouble()),
                            MathHelper.Lerp(0f, 1f, (float)r.NextDouble()), 0f);

                        for (int i = 0; i < 8; i++)
                        {
                            float angle = (float)(MathHelper.PiOver4 * i);
                            enemyCubes[cubeNumber].special = 600;
                            enemyCubes[cubeNumber].scale = 10.0f;
                            enemyCubes[cubeNumber].alive = true;
                            enemyCubes[cubeNumber].position = cubePack.position;

                            enemyCubes[cubeNumber].velocity = Vector3.Normalize(Vector3.Transform(scatterRot, Matrix.CreateRotationZ(angle)));
                            cubeNumber++;
                            if (cubeNumber == maxCubes)
                            {
                                cubeNumber = 0;
                            }
                        }

                    }
                }
            }
            foreach (GameObject cube in enemyCubes)
            {
                if (cube.alive && bullet.alive)
                {
                    BoundingSphere cubesphere =
                        cube.model.Meshes[0].BoundingSphere;
                    cubesphere.Center = cube.position;
                    cubesphere.Radius += (cube.scale * 2);

                    if (cubesphere.Intersects(bulletsphere))
                    {
                        //SCORE
                        bullet.alive = false;
                        if (bullet.projType == 2) //projectile is laser
                        {
                            if (cube.special < 590) //lasers can't kill the cubes at the same time they spawn
                            {
                                cube.alive = false;
                            }
                            else
                            {
                                bullet.alive = true;
                            }

                        }
                        else if (bullet.projType == 3)//projectile is missile
                        {
                            DetonateMissile(bullet);
                        }
                        else if (bullet.projType == 4) //projectile is shield
                        {
                            bullet.alive = true;
                            if (cube.special < 595) //So shield doesn't kill all the cubes on spawn
                            {
                                cube.alive = false;
                                DamageShields(10f);
                            }
                        }
                        else if (bullet.projType == 5) //projectile is SHIP!!
                        {
                            ShipHit();
                            cube.alive = false;
                        }

                    }
                }
            }
            foreach (GameObject charger in enemyChargers)
            {
                if (charger.alive)
                {
                    BoundingSphere squaresphere =
                        charger.model.Meshes[0].BoundingSphere;
                    squaresphere.Center = charger.position;
                    squaresphere.Radius += (charger.scale * 2);

                    if (squaresphere.Intersects(bulletsphere))
                    {
                        //play sound
                        score++;
                        checkLevelUP();
                        bullet.alive = false;
                        if (bullet.projType == 4) //projectile is shield
                        {

                            bullet.alive = true;
                            DamageShields(10f);

                        }
                        else if (bullet.projType == 5) //projectile is SHIP!!
                        {
                            ShipHit();
                            score--;
                        }
                        else if (bullet.projType == 3)//projectile is missile
                        {
                            DetonateMissile(bullet);
                        }
                        charger.alive = false;
                        foreach (GameObject shield in enemyShields)
                        {
                            if (shield.projType == charger.projType)
                            {
                                if (shield.special >= 0)
                                {
                                    shield.alive = false;
                                }
                            }
                        }
                        break;
                    }
                }
            }
            foreach (GameObject reflector in enemyReflectors)
            {
                if (reflector.alive)
                {
                    BoundingSphere squaresphere =
                        reflector.model.Meshes[0].BoundingSphere;
                    squaresphere.Center = reflector.position;
                    squaresphere.Radius += (reflector.scale * 2);

                    if (squaresphere.Intersects(bulletsphere))
                    {
                        //play sound
                        score++;
                        checkLevelUP();
                        bullet.alive = false;
                        if (bullet.projType == 4) //projectile is shield
                        {

                            bullet.alive = true;
                            DamageShields(10f);

                        }
                        else if (bullet.projType == 5) //projectile is SHIP!!
                        {
                            ShipHit();
                            score--;
                        }
                        else if (bullet.projType == 3)//projectile is missile
                        {
                            DetonateMissile(bullet);
                        }
                        reflector.alive = false;
                        break;
                    }
                }
            }
            foreach (GameObject dodger in enemyDodgers)
            {
                if (dodger.alive)
                {
                    BoundingSphere squaresphere =
                        dodger.model.Meshes[0].BoundingSphere;
                    squaresphere.Center = dodger.position;
                    squaresphere.Radius += (dodger.scale * 2);

                    if (squaresphere.Intersects(bulletsphere))
                    {
                        //play sound
                        score++;
                        checkLevelUP();
                        bullet.alive = false;
                        if (bullet.projType == 4) //projectile is shield
                        {

                            bullet.alive = true;
                            DamageShields(10f);

                        }
                        else if (bullet.projType == 5) //projectile is SHIP!!
                        {
                            ShipHit();
                            score--;
                        }
                        else if (bullet.projType == 3)//projectile is missile
                        {
                            DetonateMissile(bullet);
                        }
                        dodger.alive = false;
                        break;
                    }
                }
            }
            foreach (GameObject snake in enemySnakes)
            {
                if (snake.alive)
                {
                    BoundingSphere squaresphere =
                        snake.model.Meshes[0].BoundingSphere;
                    squaresphere.Center = snake.position;
                    squaresphere.Radius += (snake.scale * 2);

                    if (squaresphere.Intersects(bulletsphere))
                    {
                        //play sound
                        score++;
                        checkLevelUP();
                        bullet.alive = false;
                        if (bullet.projType == 4) //projectile is shield
                        {

                            bullet.alive = true;
                            DamageShields(10f);

                        }
                        else if (bullet.projType == 5) //projectile is SHIP!!
                        {
                            ShipHit();
                            score--;
                        }
                        else if (bullet.projType == 3)//projectile is missile
                        {
                            DetonateMissile(bullet);
                        }
                        snake.alive = false;
                        break;
                    }
                }
            }
            foreach (GameObject coward in enemyCowards)
            {
                if (coward.alive)
                {
                    BoundingSphere squaresphere =
                        coward.model.Meshes[0].BoundingSphere;
                    squaresphere.Center = coward.position;
                    squaresphere.Radius += (coward.scale * 2);

                    if (squaresphere.Intersects(bulletsphere))
                    {
                        //play sound
                        score++;
                        checkLevelUP();
                        bullet.alive = false;
                        if (bullet.projType == 4) //projectile is shield
                        {

                            bullet.alive = true;
                            DamageShields(10f);

                        }
                        else if (bullet.projType == 5) //projectile is SHIP!!
                        {
                            ShipHit();
                            score--;
                        }
                        else if (bullet.projType == 3)//projectile is missile
                        {
                            DetonateMissile(bullet);
                        }
                        coward.alive = false;
                        break;
                    }
                }
            }
            foreach (GameObject food in enemyFood)
            {
                if (food.alive)
                {
                    BoundingSphere squaresphere =
                        food.model.Meshes[0].BoundingSphere;
                    squaresphere.Center = food.position;
                    squaresphere.Radius += (food.scale * 2);

                    if (squaresphere.Intersects(bulletsphere))
                    {
                        //play sound
                        score++;
                        checkLevelUP();
                        bullet.alive = false;
                        if (bullet.projType == 4) //projectile is shield
                        {

                            bullet.alive = true;
                            DamageShields(10f);

                        }
                        else if (bullet.projType == 5) //projectile is SHIP!!
                        {
                            ShipHit();
                            score--;
                        }
                        else if (bullet.projType == 3)//projectile is missile
                        {
                            DetonateMissile(bullet);
                        }
                        food.alive = false;
                        break;
                    }
                }
            }
            foreach (GameObject placeholder in enemyPlaceholder1)
            {
                if (placeholder.alive)
                {
                    BoundingSphere squaresphere =
                        placeholder.model.Meshes[0].BoundingSphere;
                    squaresphere.Center = placeholder.position;
                    squaresphere.Radius += (placeholder.scale * 2);

                    if (squaresphere.Intersects(bulletsphere))
                    {
                        //play sound
                        score++;
                        checkLevelUP();
                        bullet.alive = false;
                        if (bullet.projType == 4) //projectile is shield
                        {

                            bullet.alive = true;
                            DamageShields(10f);

                        }
                        else if (bullet.projType == 5) //projectile is SHIP!!
                        {
                            ShipHit();
                            score--;
                        }
                        else if (bullet.projType == 3)//projectile is missile
                        {
                            DetonateMissile(bullet);
                        }
                        placeholder.alive = false;
                        break;
                    }
                }
            }
            foreach (GameObject placeholder in enemyPlaceholder2)
            {
                if (placeholder.alive)
                {
                    BoundingSphere squaresphere =
                        placeholder.model.Meshes[0].BoundingSphere;
                    squaresphere.Center = placeholder.position;
                    squaresphere.Radius += (placeholder.scale * 2);

                    if (squaresphere.Intersects(bulletsphere))
                    {
                        //play sound
                        score++;
                        checkLevelUP();
                        bullet.alive = false;
                        if (bullet.projType == 4) //projectile is shield
                        {

                            bullet.alive = true;
                            DamageShields(10f);

                        }
                        else if (bullet.projType == 5) //projectile is SHIP!!
                        {
                            ShipHit();
                            score--;
                        }
                        else if (bullet.projType == 3)//projectile is missile
                        {
                            DetonateMissile(bullet);
                        }
                        placeholder.alive = false;
                        break;
                    }
                }
            }
            foreach (GameObject placeholder in enemyPlaceholder3)
            {
                if (placeholder.alive)
                {
                    BoundingSphere squaresphere =
                        placeholder.model.Meshes[0].BoundingSphere;
                    squaresphere.Center = placeholder.position;
                    squaresphere.Radius += (placeholder.scale * 2);

                    if (squaresphere.Intersects(bulletsphere))
                    {
                        //play sound
                        score++;
                        checkLevelUP();
                        bullet.alive = false;
                        if (bullet.projType == 4) //projectile is shield
                        {

                            bullet.alive = true;
                            DamageShields(10f);

                        }
                        else if (bullet.projType == 5) //projectile is SHIP!!
                        {
                            ShipHit();
                            score--;
                        }
                        else if (bullet.projType == 3)//projectile is missile
                        {
                            DetonateMissile(bullet);
                        }
                        placeholder.alive = false;
                        break;
                    }
                }
            }
            foreach (GameObject placeholder in enemyPlaceholder4)
            {
                if (placeholder.alive)
                {
                    BoundingSphere squaresphere =
                        placeholder.model.Meshes[0].BoundingSphere;
                    squaresphere.Center = placeholder.position;
                    squaresphere.Radius += (placeholder.scale * 2);

                    if (squaresphere.Intersects(bulletsphere))
                    {
                        //play sound
                        score++;
                        checkLevelUP();
                        bullet.alive = false;
                        if (bullet.projType == 4) //projectile is shield
                        {

                            bullet.alive = true;
                            DamageShields(10f);

                        }
                        else if (bullet.projType == 5) //projectile is SHIP!!
                        {
                            ShipHit();
                            score--;
                        }
                        else if (bullet.projType == 3)//projectile is missile
                        {
                            DetonateMissile(bullet);
                        }
                        placeholder.alive = false;
                        break;
                    }
                }
            }
        }