コード例 #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)
 {
     // TODO: Add your update code here
     if (timer % 60 == 0)
     {
         bullet  = new EnemyBullet(this.Game, spriteBatch, new Vector2(position.X + tex.Width / 2 - 30, position.Y + tex.Height / 2 - 30), 5, 5, Game.Content.Load <Texture2D>("Images/bullet1"), Color.Yellow);
         bullet2 = new EnemyBullet(this.Game, spriteBatch, new Vector2(position.X + tex.Width / 2 - 30, position.Y - tex.Height / 2 + 30), 5, -5, Game.Content.Load <Texture2D>("Images/bullet1"), Color.Yellow);
         bullet3 = new EnemyBullet(this.Game, spriteBatch, new Vector2(position.X - tex.Width / 2 - 30, position.Y + tex.Height / 2 + 30), -5, 5, Game.Content.Load <Texture2D>("Images/bulletE"), Color.Yellow);
         bullet4 = new EnemyBullet(this.Game, spriteBatch, new Vector2(position.X - tex.Width / 2 + 30, position.Y - tex.Height / 2 + 30), -5, -5, Game.Content.Load <Texture2D>("Images/bulletE"), Color.Yellow);
         boss2BulletList.Add(bullet);
         Game.Components.Add(bullet);
         boss2BulletList.Add(bullet2);
         Game.Components.Add(bullet2);
         boss2BulletList.Add(bullet3);
         Game.Components.Add(bullet3);
         boss2BulletList.Add(bullet4);
         Game.Components.Add(bullet4);
     }
     rotationFactor += rotationChange;
     position        = position + speed;
     if (RotationFactor >= MathHelper.Pi * 2)
     {
         RotationFactor = 0;
     }
     if (position.Y < 0)
     {
         speed = new Vector2(speed.X, Math.Abs(speed.Y));
     }
     if (position.Y > Shared.stage.Y)
     {
         speed = new Vector2(speed.X, -Math.Abs(speed.Y));
     }
     if (position.X < 0)
     {
         speed = new Vector2(Math.Abs(speed.X), speed.Y);
     }
     if (position.X > Shared.stage.X)
     {
         speed = new Vector2(-Math.Abs(speed.X), speed.Y);
     }
     timer++;
     if (Boss2Live <= 0)
     {
         EnemyBoss2.dead = true;
         bullet.Visible  = false;
         bullet.Enabled  = false;
         bullet2.Visible = false;
         bullet2.Enabled = false;
         bullet3.Visible = false;
         bullet3.Enabled = false;
         bullet4.Visible = false;
         bullet4.Enabled = false;
         Visible         = false;
         Enabled         = false;
         position        = new Vector2(-2000, -2000);
         this.Dispose();
     }
     base.Update(gameTime);
 }
コード例 #2
0
ファイル: EnemyBoss1.cs プロジェクト: chaseqi7/SpaceShooterX
        /// <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)
        {
            //     TODO: Add your update code here
            if (position.X > 800)
            {
                position.X -= speed.X;
            }
            if (speed.Y > 0 & position.Y > Shared.stage.Y - tex.Height / 2)
            {
                speed.Y = -Math.Abs(speed.Y);
            }
            else if (speed.Y < 0 && position.Y <= tex.Height / 2)
            {
                speed.Y = Math.Abs(speed.Y);
            }

            position.Y += speed.Y;
            timer++;
            if (timer % 55 == 0)
            {
                bullet  = new EnemyBullet(this.Game, spriteBatch, new Vector2(position.X - tex.Width / 2, position.Y - 15), -10, 0, Game.Content.Load <Texture2D>("Images/bulletE"), Color.Yellow);
                bullet2 = new EnemyBullet(this.Game, spriteBatch, new Vector2(position.X - tex.Width / 2, position.Y + 35), -10, -5, Game.Content.Load <Texture2D>("Images/bulletE"), Color.Yellow);
                bullet3 = new EnemyBullet(this.Game, spriteBatch, new Vector2(position.X - tex.Width / 2, position.Y - 35), -10, 5, Game.Content.Load <Texture2D>("Images/bulletE"), Color.Yellow);
                bullet4 = new EnemyBullet(this.Game, spriteBatch, new Vector2(position.X - tex.Width / 2, position.Y + 15), -10, 0, Game.Content.Load <Texture2D>("Images/bulletE"), Color.Yellow);
                boss1BulletList.Add(bullet);
                Game.Components.Add(bullet);
                boss1BulletList.Add(bullet2);
                Game.Components.Add(bullet2);
                boss1BulletList.Add(bullet3);
                Game.Components.Add(bullet3);
                boss1BulletList.Add(bullet4);
                Game.Components.Add(bullet4);
            }
            if (boss1Live <= 0)
            {
                ActionScene1.score += 1000;
                EnemyBoss1.dead     = true;
                bullet.Visible      = false;
                bullet.Enabled      = false;
                bullet2.Visible     = false;
                bullet2.Enabled     = false;
                bullet3.Visible     = false;
                bullet3.Enabled     = false;
                bullet4.Visible     = false;
                bullet4.Enabled     = false;
                Visible             = false;
                Enabled             = false;
                position            = new Vector2(-2000, -2000);
                this.Dispose();
            }


            base.Update(gameTime);
        }
コード例 #3
0
 public CollisionManager(Game game,
                         List <ShipBullet> bulletList,
                         Ship ship,
                         EnemyBullet enemyBullet,
                         List <EnemyBullet> enemyBulletList,
                         List <EnemyShip> enemyList,
                         EnemyBoss1 boss1,
                         List <EnemyBullet> boss1BulletList)
     : base(game)
 {
     // TODO: Construct any child components here
     this.bulletList      = bulletList;
     this.enemyBulletList = enemyBulletList;
     this.ship            = ship;
     this.enemyBullet     = enemyBullet;
     this.enemyList       = enemyList;
     this.boss1           = boss1;
     this.boss1BulletList = boss1BulletList;
 }