コード例 #1
0
ファイル: Level2.cs プロジェクト: kolpime/Asteroids
        public override void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen)
        {
            try
            {
                if (paused == false)
                {
                    #region Game
                    base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen);
                    KeyboardState keyb = Keyboard.GetState();

                    #region Asteroids are Defeated
                    if (asteroidsonscreen == 0 || (keyb.IsKeyDown(Keys.N)))
                    {
                        this.Content.Unload();
                        this.ExitScreen();
                        LoadingScreen.Load(ScreenManager, true, null, new textScreen(3,Score));
                    }
                    #endregion

                    #region Player Dead

                    if (dead == true)
                    {
                        this.Content.Unload();
                        this.ExitScreen();
                        LoadingScreen.Load(ScreenManager, false, null, new GameOverBackgroundScreen(), new GameOverScreen());
                    }
                    #endregion

                    timer = Input(gameTime, timer);

                    #region Bullet Timeout
                    for (int j = 0; j <= noBullets - 1; j++)
                    {
                        BulletList[j].AmmoModelPosition += BulletList[j].AmmoVelocity;
                        ufoBulletList[j].AmmoModelPosition += ufoBulletList[j].AmmoVelocity;

                        ufoBulletList[j].timer += (float)gameTime.ElapsedGameTime.TotalMilliseconds;
                        BulletList[j].timer += (float)gameTime.ElapsedGameTime.TotalMilliseconds;

                        if (ufoBulletList[j].timer > interval)
                        {
                            ufoBulletList[j].timer = 0.0f;
                            ufoBulletList[j].AmmoFlying = false;
                        }

                        if (BulletList[j].timer > interval)
                        {
                            BulletList[j].timer = 0.0f;
                            BulletList[j].AmmoFlying = false;
                        }

                    }

                    #endregion

                    DetectCollisions();

                    #region asteroidroll
                    #region Asteroid1
                    for (int j = 0; j <= NumAsteroid1 - 1; j++)
                    {
                        if (asteroid1List[j].isAlive)
                        {
                            asteroid1List[j].rotation += 0.005f;
                            asteroid1List[j].position += new Vector3(3.75f, 3.75f, 0);
                        }
                    }
                    #endregion

                    #region Asteroid2
                    for (int i = 0; i <= NumAsteroid2 - 1; i++)
                    {
                        Vector3 roll = Vector3.Zero;
                        if (i == 1 || i == 3 || i == 5 || i == 7 || i == 9 || i == 11 || i == 13 || i == 15)
                        {
                            roll = new Vector3(-4.75f, 6.75f, 0.0f);
                        }
                        if (i == 0 || i == 2 || i == 4 || i == 6 || i == 8 || i == 10 || i == 12 || i == 14)
                        {
                            roll = new Vector3(6.75f, -4.75f, 0.0f);
                        }

                        if (asteroid2List[i].isAlive)
                        {
                            asteroid2List[i].position += roll;
                            asteroid2List[i].rotation += 0.01f;
                        }
                    }
                    #endregion

                    #region Asteroid3
                    for (int i = 0; i <= NumAsteroid3 - 1; i++)
                    {
                        Vector3 roll = Vector3.Zero;
                        if (i == 1 || i == 3 || i == 5 || i == 7 || i == 9 || i == 11 || i == 13 || i == 15)
                        {
                            roll = new Vector3(-8.75f, 6.75f, 0.0f);
                        }
                        if (i == 0 || i == 2 || i == 4 || i == 6 || i == 8 || i == 10 || i == 12 || i == 14)
                        {
                            roll = new Vector3(9.75f, -6.75f, 0.0f);
                        }

                        if (asteroid3List[i].isAlive)
                        {
                            asteroid3List[i].position += roll;
                            asteroid3List[i].rotation += 0.015f;
                        }
                    }
                    #endregion
                    #endregion

                    #region UFO
                    ufoTimer += (float)gameTime.ElapsedGameTime.Milliseconds;
                    if (que <= 2)
                    {
                        if (ufoque[que] == ufoTimer)
                        {

                            Random y = new Random();
                            saucer = new UFO(ufo, new Vector3(-4500, y.Next(-3500, 3500), 0), 0.0f, 5, true);
                            que = que + 1;
                            ufoTimer = 0.0f;
                        }
                    }
                    #endregion

                    VenusRotation += 0.0005f;
                    saucer.position.X += 15.0f;
                    saucer.rotation += 0.15f;
                    spawntimer += (float)gameTime.ElapsedGameTime.Milliseconds;
                    #endregion
                }
                if (paused == true)
                {

                    PausedInput();
                }
            }
            catch(Exception ex)
            {
            }
        }
コード例 #2
0
ファイル: Level2.cs プロジェクト: kolpime/Asteroids
        //Detect Collisions for everything
        private void DetectCollisions()
        {
            #region Player vs Asteroids
            if (spawntimer >= spawninterval)
            {
                #region Asteroid1
                for (int i = 0; i <= NumAsteroid1 - 1; i++)
                {

                    collide = collision.playerCollide(myModel, Asteroid1, asteroid1List[i].position, play.position, Content);
                    if (collide == true)
                    {
                        spawntimer = 0;
                        while (collide == true)
                        {
                            Random x = new Random();
                            Random y = new Random();
                            play.position.X = x.Next(-2000, 2000);
                            play.position.Y = y.Next(-2000, 2000);
                            collide = collision.playerCollide(myModel, Asteroid1, asteroid1List[i].position, play.position, Content);
                        }
                        collide = false;
                        play.Lives -= 1;
                        if (play.Lives == 0)
                        {
                            dead = true;
                        }
                    }
                }
                #endregion
            }
            if (spawntimer >= spawninterval)
            {
                #region Asteroid2
                for (int i = 0; i <= NumAsteroid2 - 1; i++)
                {

                    collide = collision.playerCollide(myModel, Asteroid2, asteroid2List[i].position, play.position, Content);
                    if (collide == true)
                    {
                        spawntimer = 0;
                        while (collide == true)
                        {
                            Random x = new Random();
                            Random y = new Random();
                            play.position.X = x.Next(-2000, 2000);
                            play.position.Y = y.Next(-2000, 2000);
                            collide = collision.playerCollide(myModel, Asteroid2, asteroid2List[i].position, play.position, Content);
                        }
                        collide = false;
                        play.Lives -= 1;
                        if (play.Lives == 0)
                        {
                            dead = true;
                        }
                    }
                }
                #endregion
            }
            if (spawntimer >= spawninterval)
            {
                #region Asteroid3
                for (int i = 0; i <= NumAsteroid3 - 1; i++)
                {

                    collide = collision.playerCollide(myModel, Asteroid3, asteroid3List[i].position, play.position, Content);
                    if (collide == true)
                    {
                        spawntimer = 0;
                        while (collide == true)
                        {
                            Random x = new Random();
                            Random y = new Random();
                            play.position.X = x.Next(-2000, 2000);
                            play.position.Y = y.Next(-2000, 2000);
                            collide = collision.playerCollide(myModel, Asteroid3, asteroid3List[i].position, play.position, Content);
                        }
                        collide = false;
                        play.Lives -= 1;
                        if (play.Lives == 0)
                        {
                            dead = true;
                        }
                    }
                }
                #endregion
            }

            #endregion

            #region Asteroids vs Bullets

            #region Asteroid1
            for (int i = 0; i <= NumAsteroid1 - 1; i++)
            {
                bulletCollide = collision.BulletsCollide(ammo, Asteroid1, asteroid1List[i].position, BulletList[0].AmmoModelPosition, Content);
                if (bulletCollide == true)
                {
                    Score += 10;
                    #region Remove bullets
                    bulletCollide = false;
                    BulletList[0].AmmoModelPosition = new Vector3(5000, 5000f, 0.0f);
                    BulletList[0].AmmoFlying = false;
                    asteroid1List[i].lives -= 1;
                    #endregion

                    #region Out of lives
                        if (asteroid1List[i].lives == 0)
                        {
                            SpawnAsteroids(asteroid1List[i].asteroidModel, asteroid1List[i].position);

                            Score += 100;
                            asteroid1List[i] = new Asteroid(Asteroid1, new Vector3(8000, 8000, 0), 0.0f, false, 0);

                            asteroidsonscreen -= 1;
                            Explosion.Play(0.5F);
                        }

                    #endregion
                }
            }
            #endregion

            #region Asteroid 2
            for (int i = 0; i <= NumAsteroid2 - 1; i++)
            {
                bulletCollide2 = collision.BulletsCollide(ammo, Asteroid2, asteroid2List[i].position, BulletList[0].AmmoModelPosition, Content);
                if (bulletCollide2 == true)
                {
                    Score += 10;
                    #region Remove bullets
                    BulletList[0].AmmoModelPosition = new Vector3(5000f, 5000f, 0.0f);
                    BulletList[0].AmmoFlying = false;
                    bulletCollide2 = false;
                    asteroid2List[i].lives -= 1;
                    #endregion

                    #region Out of lives
                    if (asteroid2List[i].lives == 0)
                    {
                        SpawnAsteroids(asteroid2List[i].asteroidModel, asteroid2List[i].position);

                        Score += 50;
                        asteroid2List[i] = new Asteroid(Asteroid2, new Vector3(8000, 8000, 0), 0.0f, false, 0);
                        asteroidsonscreen -= 1;

                        Explosion.Play(0.5F);

                    }
                    #endregion
                }
            }
            #endregion

            #region Asteroid3
            for (int i = 0; i <= NumAsteroid3 - 1; i++)
            {
                bulletCollide3 = collision.BulletsCollide(ammo, Asteroid3, asteroid3List[i].position, BulletList[0].AmmoModelPosition, Content);
                if (bulletCollide3 == true)
                {
                    Score += 10;
                    #region Remove bullets
                    BulletList[0].AmmoModelPosition = new Vector3(5000f, 5000f, 0.0f);
                    BulletList[0].AmmoFlying = false;
                    bulletCollide3 = false;
                    asteroid3List[i].lives -= 1;
                    #endregion

                    #region Out of lives
                    if (asteroid3List[i].lives == 0)
                    {
                        Score += 20;
                        asteroid3List[i] = new Asteroid(Asteroid3, new Vector3(8000, 8000, 0), 0.0f, false, 0);
                        asteroidsonscreen -= 1;
                        //just using asteroidlist1 at the moment, adapt for all models

                        Explosion.Play(0.5F);

                    }
                    #endregion
                }
            }
            #endregion

            #endregion

            #region UFO and bullets
            for (int i = 0; i <= noBullets - 1; i++)
            {
                collide = collision.pBulletsCollide(ammo, ufo, saucer.position, BulletList[0].AmmoModelPosition, Content);
                if (collide == true)
                {
                    Score += 10;
                    #region Remove bullets
                    collide = false;
                    BulletList[0].AmmoModelPosition = new Vector3(5000, 5000f, 0.0f);
                    BulletList[0].AmmoFlying = false;
                    #endregion

                    collide = false;
                    saucer.Lives -= 1;

                    if (saucer.Lives == 0)
                    {
                        Explosion.Play(0.5F);
                        Score += 500;
                        saucer = new UFO(ufo, new Vector3(9000, 9000, 0), 0, 0, false);
                        saucer.isAlive = false;
                    }
                }
            }
            #endregion

            if (spawntimer >= spawninterval)
            {
                #region Ufo and player
                collide = collision.PlayersvPlayer(myModel, ufo, play.position, saucer.position, Content);
                if (collide == true)
                {
                    spawntimer = 0;
                    Random x = new Random();
                    Random y = new Random();
                    play.position.X = x.Next(-2000, 2000);
                    play.position.Y = y.Next(-2000, 2000);
                    collide = false;
                    play.Lives -= 1;
                    saucer.Lives -= 1;
                    if (play.Lives == 0)
                    {
                        dead = true;
                    }
                    if (saucer.Lives == 0)
                    {
                        Explosion.Play(0.5F);
                        saucer = new UFO(ufo, new Vector3(9000, 9000, 0), 0, 0, false);
                        saucer.isAlive = false;
                    }
                }
                #endregion
            }

            if (spawntimer >= spawninterval)
            {
                #region player vs ufo bullets

                for (int i = 0; i <= noBullets - 1; i++)
                {
                    collide = collision.pBulletsCollide(ammo, myModel, play.position, ufoBulletList[0].AmmoModelPosition, Content);
                    if (collide == true)
                    {
                        spawntimer = 0;
                        #region Remove bullets
                        bulletCollide = false;
                        ufoBulletList[0].AmmoModelPosition = new Vector3(5000, 5000f, 0.0f);
                        ufoBulletList[0].AmmoFlying = false;
                        #endregion

                        Random x = new Random();
                        Random y = new Random();
                        play.position.X = x.Next(-2000, 2000);
                        play.position.Y = y.Next(-2000, 2000);

                        collide = false;
                        play.Lives -= 1;

                        if (play.Lives == 0)
                        {
                            dead = true;
                        }
                    }
                }
                #endregion
            }
        }
コード例 #3
0
ファイル: Level2.cs プロジェクト: kolpime/Asteroids
        public override void LoadContent()
        {
            if (Content == null)
                Content = new ContentManager(ScreenManager.Game.Services, "Content");

            #region loaded content

            myModel = Content.Load<Model>("Model\\fighter");
            Asteroid1 = Content.Load<Model>("Model\\Asteroid1");
            Asteroid2 = Content.Load<Model>("Model\\Asteroid2");
            Asteroid3 = Content.Load<Model>("Model\\Asteroid3");
            ammo = Content.Load<Model>("Model\\ammo");
            ufo = Content.Load<Model>("Model\\UFO");
            venus = Content.Load<Model>("Model\\venus");

            Explosion = Content.Load<SoundEffect>("Audio\\explosion3");

            dataScreen = Content.Load<Texture2D>("Images\\DataScreen");
            BackGround = Content.Load<Texture2D>("Images\\background2");
            panel = Content.Load<Texture2D>("Images\\panel");
            hypButton = Content.Load<Texture2D>("Images\\p1hyp");
            hypButtonClk = Content.Load<Texture2D>("Images\\p1hypclk");

            ufoFire = Content.Load<SoundEffect>("Audio\\tx0_fire1");
            Engine = Content.Load<SoundEffect>("Audio\\engine_3");
            WeaponFire = Content.Load<SoundEffect>("Audio\\pdp1_fire");

            defaultFont = Content.Load<SpriteFont>("Fonts\\defaultFont");
            HyperSpace = Content.Load<SoundEffect>("Audio\\hax2_fire_alt");

            play = new Player(myModel, Initial, 0.0f, 3);
            saucer = new UFO(ufo, new Vector3(9000, 9000, 0), 0.0f, 5, false);

            Projectile bullet = new Projectile(ammo, Initial, 0.0f, Initial, false, Initial);

            ufoque = new float[] { 4000, 36000, 36000 };
            BulletList = new Projectile[noBullets];
            ufoBulletList = new Projectile[noBullets];

            #endregion

            #region Graphic Device and screen elements
            screenWidth = ScreenManager.GraphicsDevice.PresentationParameters.BackBufferWidth;
            screenHeight = ScreenManager.GraphicsDevice.PresentationParameters.BackBufferHeight;
            aspectRatio = ScreenManager.GraphicsDevice.Viewport.AspectRatio;
            #endregion

            #region initialise Asteroids
            AP1.X = -2000;
            AP1.Y = screenHeight;

            AP2.X = -screenWidth;
            AP2.Y = -2000;

            AP3.X = 500;
            AP3.Y = -screenHeight;

            AP4.X = screenWidth;
            AP4.Y = 750;

            asteroid1List[0] = new Asteroid(Asteroid1, AP1, 0.5f, true, 5);
            asteroid1List[1] = new Asteroid(Asteroid1, AP2, 1.25f, true, 5);
            asteroid1List[2] = new Asteroid(Asteroid1, AP3, 2.005f, true, 5);

            asteroid2List[0] = new Asteroid(Asteroid2, AP4, 0.005f, true, 3);

            for (int i = 1; i < NumAsteroid2; i++)
                asteroid2List[i] = new Asteroid(Asteroid2, new Vector3(4000, 4000, 0), 0.005f, false, 3);

            for (int i = 0; i < NumAsteroid3; i++)
                asteroid3List[i] = new Asteroid(Asteroid3, new Vector3(4000, 4000, 0), 0.005f, false, 1);

            #endregion

            #region initialise bullet list
            for (int i = 0; i < noBullets; i++)
            {
                BulletList[i] = new Projectile(ammo, new Vector3(5000, 5000, 0), 0.0f, Initial, false, Initial);
                ufoBulletList[i] = new Projectile(ammo, new Vector3(5000, 5000, 0), 0.0f, Initial, false, Initial);
            }
            #endregion
        }