Ejemplo n.º 1
0
        /// <summary>
        /// Allows the game component to update itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        public override void Update(GameTime gameTime)
        {
            KeyboardState ks = Keyboard.GetState();


            string message = "Life:" + ship.Lives;

            lives.Message = message;
            string scoreMessage = "Score:" + score;

            scoreString.Message = scoreMessage;
            if (CollisionManager.Destroyed1)
            {
                score += 100;
                CollisionManager.Destroyed1 = false;
            }
            if (timer % 80 == 0 && score < 200)
            {
                Texture2D enemyTex   = this.Game.Content.Load <Texture2D>("Images/enemy1");
                Random    r          = new Random();
                Vector2   enemyPos   = new Vector2(Shared.stage.X + enemyTex.Width, r.Next(enemyTex.Height / 4, 401 - enemyTex.Height / 4));
                Vector2   enemySpeed = new Vector2(-10, 0);
                this.enemyShip = new EnemyShip(this.Game, spriteBatch, enemyTex, enemyPos, enemySpeed);
                enemyList.Add(enemyShip);
                this.Components.Add(enemyShip);

                CollisionManager cm = new CollisionManager(this.Game, bulletList, ship, enemyBullet, enemyShip.EnemyBulletList, enemyList, boss1, boss1.Boss1BulletList);
                this.Components.Add(cm);
            }

            else if (bossTimer > 200 && !EnemyBoss1.boss1Appear)
            {
                this.Components.Add(boss1);

                EnemyBoss1.boss1Appear = true;
            }
            if (score >= 200)
            {
                bossTimer++;
            }


            if (bulletList.Count < 3)
            {
                if (ks.IsKeyDown(Keys.Space) & oldState.IsKeyUp(Keys.Space))
                {
                    bullet = new ShipBullet(this.Game, spriteBatch, ship.Position + new Vector2(0, -4), 15, 0, this.Game.Content.Load <Texture2D>("Images/bullet1"), Color.White);
                    bulletList.Add(Bullet);
                    this.Game.Components.Add(bullet);
                }
            }
            oldState = ks;


            timer++;
            // TODO: Add your update code here
            base.Update(gameTime);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Allows the game component to update itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        public override void Update(GameTime gameTime)
        {
            timerSpawn++;
            string message = "Life:" + ship.Lives;

            lives.Message = message;
            string scoreMessage = "Score:" + (score2 + ActionScene1.score);

            scoreString.Message = scoreMessage;
            if (timerSpawn >= 120)
            {
                enemy2Timer++;
                KeyboardState ks = Keyboard.GetState();
                //boss2.RotationFactor += MathHelper.Pi / 60;



                if (CollisionManager2.Destroyed2)
                {
                    score2 += 100;
                    CollisionManager2.Destroyed2 = false;
                }
                if (timer % 50 == 0 && score2 < 1000)
                {
                    Texture2D enemyTex2   = this.Game.Content.Load <Texture2D>("Images/enemy2");
                    Random    r           = new Random();
                    Random    s           = new Random();
                    Vector2   enemyPos2   = new Vector2(Shared.stage.X + enemyTex2.Width, r.Next(enemyTex2.Height, 401 - enemyTex2.Height / 4));
                    Vector2   enemySpeed2 = new Vector2(-10, s.Next(-10, 10));
                    this.enemyShip21 = new EnemyShip2(this.Game, spriteBatch, enemyTex2, enemyPos2, enemySpeed2);
                    enemyList2.Add(enemyShip21);
                    this.enemyShip22 = new EnemyShip2(this.Game, spriteBatch, enemyTex2, enemyPos2, enemySpeed2);
                    enemyList2.Add(enemyShip22);
                    this.enemyShip23 = new EnemyShip2(this.Game, spriteBatch, enemyTex2, enemyPos2, enemySpeed2);
                    enemyList2.Add(enemyShip23);
                    this.enemyShip24 = new EnemyShip2(this.Game, spriteBatch, enemyTex2, enemyPos2, enemySpeed2);
                    enemyList2.Add(enemyShip24);
                    this.enemyShip25 = new EnemyShip2(this.Game, spriteBatch, enemyTex2, enemyPos2, enemySpeed2);
                    enemyList2.Add(enemyShip25);
                    CollisionManager2 cm2 = new CollisionManager2(this.Game, bulletList, ship, enemyList2, boss2, boss2.Boss2BulletList);
                    this.Components.Add(cm2);
                }
                else if (bossTimer > 150 && !EnemyBoss2.boss2Appear)
                {
                    this.Components.Add(boss2);

                    EnemyBoss2.boss2Appear = true;
                }
                if (score2 >= 1000)
                {
                    bossTimer++;
                }


                if (score2 < 1000)
                {
                    if (enemy2Timer == 5)
                    {
                        Components.Add(enemyShip21);
                    }
                    else if (enemy2Timer == 8)
                    {
                        Components.Add(enemyShip22);
                    }
                    else if (enemy2Timer == 11)
                    {
                        Components.Add(enemyShip23);
                    }
                    else if (enemy2Timer == 14)
                    {
                        Components.Add(enemyShip24);
                    }
                    else if (enemy2Timer == 17)
                    {
                        Components.Add(enemyShip25);
                    }
                    else if (enemy2Timer == 50)
                    {
                        enemy2Timer = 0;
                    }
                }



                if (bulletList.Count < 3)
                {
                    if (ks.IsKeyDown(Keys.Space) & oldState.IsKeyUp(Keys.Space))
                    {
                        bullet = new ShipBullet(this.Game, spriteBatch, ship.Position + new Vector2(0, -4), 15, 0, this.Game.Content.Load <Texture2D>("Images/bullet1"), Color.White);
                        bulletList.Add(Bullet);
                        this.Game.Components.Add(bullet);
                    }
                }
                oldState = ks;


                timer++;
            }
            // TODO: Add your update code here
            base.Update(gameTime);
        }