コード例 #1
0
 public void BeginExplosion(sfxManager sfx)
 {
     if (state != ShipState.Exploding)
     {
         state = ShipState.Exploding;
         explosion.Initialize(explosionTexture, position, 8, 65f, 1.0f, false);
         sfx.Effect("enemyexplosion").Play();
     }
 }
コード例 #2
0
        /// <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()
        {
            // TODO: Add your initialization logic here
            player       = new Player();
            starfield    = new Starfield();
            projectiles  = new ProjectileManager();
            enemies      = new EnemyManager();
            soundEffects = new sfxManager();

            gameState = GameState.TitleMenu;

            base.Initialize();
        }
コード例 #3
0
        public void Update(GameTime gameTime, Player player, ProjectileManager pm, sfxManager sfx)
        {
            enemies.RemoveAll(e => e.state == ShipState.Dead);

            if (gameTime.TotalGameTime.Subtract(lastSpawn) > TimeSpan.FromMilliseconds(rnd.Next((int)frequency / 3, (int)frequency)))
            {
                enemies.Add(new Enemy(new Vector2(rnd.Next(0, 550), -50), textures["red"], Color.Crimson, textures["explosion"]));
                lastSpawn = gameTime.TotalGameTime;
            }

            foreach (Enemy en in enemies)
            {
                if (en.state == ShipState.Active)
                {
                    if (player.position.X < en.currentOrigin.X && player.position.X + player.width > en.currentOrigin.X)
                    {
                        en.equippedWeapon.Fire(gameTime, pm, null, player);
                    }

                    // check for collision with player ship
                    if (en.Collision(player))
                    {
                        en.BeginExplosion(sfx);
                        player.crashed = true;
                    }

                    // check for collision with a projectile
                    foreach (Projectile p in pm.projectiles)
                    {
                        if (en.Collision(p) && p.fromPlayer)
                        {
                            en.BeginExplosion(sfx);
                            p.isActive = false;
                            player.score++;
                            if (player.score > player.highScore)
                            {
                                player.highScore = player.score;
                            }
                        }
                    }
                }

                en.Update(gameTime);
            }
        }