Exemplo n.º 1
0
        // FireShot Function.
        public void FireShot()
        {
            // Create new shot if enough time has passed since last shot (shotTimer).
            if (shotTimer >= minShotTimer)
            {
                // Create position form which shot will be fired.
                Vector2 fireLoc = Center;

                // Create direction in which shot will be fired and normalize it.
                Vector2 shotDirection = new Vector2(Mouse.GetState().X, Mouse.GetState().Y) - fireLoc;
                shotDirection.Normalize();

                // Fire shot.
                PlayerShotManager.FireShot(
                    Center + gunOffset, shotDirection, true);
                // Reset the shot timer.
                shotTimer = 0.0f;
                // Play firing sound
                firingSound.Play();
                PlayerArms.Fire();
            }
        }
Exemplo n.º 2
0
        // Update
        public void Update(GameTime gameTime)
        {
            EnemyShotManager.Update(gameTime);

            for (int i = Enemies.Count - 1; i >= 0; i--)
            {
                Enemies[i].Update(gameTime);
                if (Enemies[i].IsActive() == false)
                {
                    Enemies.RemoveAt(i);
                }

                else
                {
                    // Make a random chance that a shot is fired.
                    if ((float)rand.Next(0, 1000) / 10 <= shipShotChance)
                    {
                        // Location from which shot should be fired.
                        Vector2 fireLoc = Enemies[i].EnemySprite.Position;
                        fireLoc += Enemies[i].GunOffset;

                        //  Direction in which shot whould be fired.
                        Vector2 shotDirection = playerManager.Center - fireLoc;
                        shotDirection.Normalize();

                        // Fire shot.
                        EnemyShotManager.FireShot(fireLoc, shotDirection, false);
                        // Play firing sound.
                        firingSound.Play();
                    }
                }
            }

            if (Active)
            {
                updateWaveSpawns(gameTime);
            }
        }