public void PlayMusic(object d)
        {
            bool play = true;
            while (play)
            {
                System.Diagnostics.Trace.WriteLine("Creating new AudioPlayback object.");
                using (AudioPlayback Playback = new AudioPlayback())
                {
                    if (_Mute)
                    {
                        Playback.Volume = 0;
                    }
                    else
                    {
                        Playback.Volume = 1;
                    }

                    String File = RandomFile("Music");
                    System.Diagnostics.Trace.WriteLine("Loading music file: " + File);
                    _CurrentlyPlaying = File;

                    Playback.Load(File);
                    Playback.Play();

                    while (Playback.GetPlaybackState() == NAudio.Wave.PlaybackState.Playing)
                    {

                        if(Playback.IsTrackOver())
                        {
                            System.Diagnostics.Trace.WriteLine("Track is over. Playing next song.");
                            break;
                        }

                        if (_Mute)
                        {
                            Playback.Volume = 0;
                        }
                        else
                        {
                            Playback.Volume = 1;
                        }

                        if (_PlayNext)
                        {
                            System.Diagnostics.Trace.WriteLine("Play next requested. Playing next song.");
                            this._PlayNext = false;
                            break;
                        }
                    }
                }
            }
        }
예제 #2
0
        private void DoAnimation()
        {
            List<ModelVisual3D> Enemies = new List<ModelVisual3D>();
            List<ModelVisual3D> Lasers = new List<ModelVisual3D>();
            double LowestEnemy = 10000;

            DisplayScore();
            DisplayAmmo();
            this.Question.Text = this.CurrentWord.Question.Replace("ő","ö").Replace("ű","ü");

            if ((DateTime.Now - LevelStartedTime).Seconds > 4 && !this.GameOver)
            {
                this.BigTextPanel.Visibility = System.Windows.Visibility.Hidden;
                this.QAPanel.Visibility = System.Windows.Visibility.Visible;
            }

            Answer.Text = AnswerTextBox.Text.Replace(" ", "_").Replace("ő","ö").Replace("ű","ű");
            AnswerTextBox.Focus();

            lock (this.view1.Children)
            {
                TimeSpan DeltaTime = DateTime.Now - LastAnimation;
                LastAnimation = DateTime.Now;

                List<ModelVisual3D> ToRemove = new List<ModelVisual3D>();

                foreach (ModelVisual3D Model in this.view1.Children.ToList())
                {

                    if (Model.GetName() != null && Model.GetName().Equals("DeadEnemy"))
                    {
                        if (OpacityDictionary.ContainsKey(Model))
                        {
                            if ((OpacityDictionary[Model]) > 0)
                            {
                                OpacityDictionary[Model] -= DeltaTime.TotalMilliseconds * 0.003;
                            }
                            else
                            {
                                OpacityDictionary[Model] = 0;
                                ToRemove.Add(Model);
                            }
                        }
                        else
                        {
                            OpacityDictionary.Add(Model, 1);
                        }

                        Model3DGroup DeadEnemy = (Model3DGroup)Model.Content;
                        foreach (var Child in DeadEnemy.Children)
                        {
                            var DeadEnemyModel = ((GeometryModel3D)Child);
                            DeadEnemyModel.BackMaterial = MaterialHelper.CreateMaterial(Colors.Yellow, OpacityDictionary[Model]);
                            DeadEnemyModel.Material = MaterialHelper.CreateMaterial(Colors.Red, OpacityDictionary[Model] / 2.0);
                        }
                    }

                    if (Model.GetName() != null && Model.GetName().Equals("Enemy"))
                    {
                        var Enemy = Model;
                        Enemies.Add(Enemy);
                        ((TranslateTransform3D)((Transform3DGroup)Enemy.Transform).Children[1]).OffsetY -= DeltaTime.Milliseconds * 0.00007 * (1 + Level / 3.2);

                        double EnemyPosition = ((TranslateTransform3D)((Transform3DGroup)Enemy.Transform).Children[1]).OffsetY;

                        if(EnemyPosition < LowestEnemy)
                        {
                            LowestEnemy = EnemyPosition;
                        }
                    }

                    if (Model.GetName() != null && Model.GetName().Equals("Laser"))
                    {
                        var Laser = Model;
                        Lasers.Add(Laser);

                        ((TranslateTransform3D)((Transform3DGroup)Laser.Transform).Children[1]).OffsetY += DeltaTime.Milliseconds * 0.005;

                        if (((TranslateTransform3D)((Transform3DGroup)Laser.Transform).Children[1]).OffsetY > 25)
                        {
                            ToRemove.Add(Laser);
                        }
                    }
                }

                if(LowestEnemy < -5.2)
                {
                    if (GameOver == false)
                    {
                        this.GameOver = true;
                        this.GameOverTime = DateTime.Now;
                        this.ship.SetName("DeadEnemy");
                        this.BigTextPanel.Visibility = System.Windows.Visibility.Visible;
                        this.QAPanel.Visibility = System.Windows.Visibility.Hidden;
                        this.BigText.Text = "GAME OVER";
                        if (GameOverSound != null)
                        {
                            GameOverSound.Stop();
                            GameOverSound.Dispose();
                        }

                        GameOverSound = new AudioPlayback();
                        GameOverSound.Load("Sounds/Gameover.mp3");
                        GameOverSound.Play();

                        Task.Factory.StartNew(this.SubmitHighscore, this.Dispatcher, source.Token);
                    }
                }

                foreach (var laser in Lasers)
                {
                    var LaserLocation = laser.FindBounds(laser.Transform).Location;

                    foreach (var enemy in Enemies)
                    {

                        var EnemyBound = enemy.FindBounds(enemy.Transform);
                        double Scale = ((ScaleTransform3D)((Transform3DGroup)enemy.Transform).Children[0]).ScaleX;

                        if (EnemyBound.Location.DistanceTo(LaserLocation) < 42 * Scale)
                        {
                            enemy.SetName("DeadEnemy");
                            ToRemove.Add(laser);

                            if (ExplosionSound != null)
                            {
                                ExplosionSound.Stop();
                                ExplosionSound.Dispose();
                            }

                            ExplosionSound = new AudioPlayback();
                            ExplosionSound.Load("Sounds/Explosions/Explosion01.mp3");
                            ExplosionSound.Play();

                            this.Score += 1000;

                        }
                    }
                }

                // Remove far lasers & Dead enemies
                foreach (var item in ToRemove)
                {
                    this.view1.Children.Remove(item);
                }

                if (Math.Abs(ShipPosition.OffsetX - _ShipXCoord) > 0.05)
                {
                    ShipPosition.OffsetX -= (ShipPosition.OffsetX - _ShipXCoord) / (2000.0 / (double)DeltaTime.Milliseconds);
                }

                if (Enemies.Count == 0)
                {

                    if (IsEndOfLevel == false)
                    {
                        IsEndOfLevel = true;
                        EndOfLevel = DateTime.Now;
                        // this.QAPanel.Visibility = System.Windows.Visibility.Hidden;
                    }

                    var TimeSinceEndOfLevel = DateTime.Now - EndOfLevel;

                    if (IsEndOfLevel && TimeSinceEndOfLevel.Seconds > 3)
                    {
                        NextLevel();
                    }
                }
            }
        }
예제 #3
0
        internal void ShootLaser()
        {
            var DeltaTime = DateTime.Now - LastShootTime;

            if ((DeltaTime.Milliseconds > 250) && (!this.GameOver) && (LaserAmmoCount>0))
            {
                LastShootTime = DateTime.Now;
                LaserAmmoCount--;

                if(LaserSound != null)
                {
                    LaserSound.Stop();
                    LaserSound.Dispose();
                }

                LaserSound = new AudioPlayback();
                LaserSound.Load("Sounds/Laser.mp3");
                LaserSound.Play();

                // Create Laser
                var LaserModel = CreateLaser(ShipPosition.OffsetX, ShipPosition.OffsetY, ShipPosition.OffsetZ);
                LaserModel.SetName("Laser");

                lock (this.view1.Children)
                {
                    this.view1.Children.Add(LaserModel);
                }
            }
            else
                if ((DeltaTime.Milliseconds > 250) && (!this.GameOver) && (LaserAmmoCount == 0))
                {
                    LastShootTime = DateTime.Now;
                    if (LaserSound != null)
                    {
                        LaserSound.Stop();
                        LaserSound.Dispose();
                    }

                    LaserSound = new AudioPlayback();
                    LaserSound.Load("Sounds/LaserError.mp3");
                    LaserSound.Play();
                }
        }