Ejemplo n.º 1
0
        public void Initialize(MainWindow window)
        {
            ImageBrush imgBrush = new ImageBrush(new BitmapImage(new Uri(IMAGE_PATH + "lightsaber1" + ".png", UriKind.Relative)));

            // added 3 Media Player objects, they handle the sound for the bat class such as,
            // lightsaber loop, the turning of the lightsaber, and the lighsaber swing.
            lightsaberStart = new MediaPlayer();
            lightsaberLoop = new MediaPlayer();
            lightsaberSwing = new MediaPlayer();

            // Setting the volume of each sound.
            lightsaberStart.Volume = .45;
            lightsaberLoop.Volume = .15;
            lightsaberSwing.Volume = .40;

            // Opening each mp3 file that goes with each media player.
            lightsaberStart.Open(new Uri(SOUND_PATH + "lightsaber_start.mp3", UriKind.Relative));
            lightsaberLoop.Open(new Uri(SOUND_PATH + "lightsaber_loop.mp3", UriKind.Relative));
            lightsaberSwing.Open(new Uri(SOUND_PATH + "lightsaber_swing.mp3", UriKind.Relative));

            // have to create a event handler in order to loop the lightsaber_loop sound.
            lightsaberLoop.MediaEnded += LightsaberLoop_MediaEnded;

            // Plays the startup sound for the lightsaber.
            lightsaberStart.Play();
            // You have to reset the position of the media sound after you play it.
            lightsaberStart.Position = new TimeSpan();

            // Creates the bat to be drawn on display.
            eLine = window.myBat;

            eLine.Stroke = Brushes.Black;
            eLine.X1 = window.TheCanvas.Width / 1.40;
            eLine.X2 = window.TheCanvas.Width / 1.40;
            eLine.Y1 = window.TheCanvas.Height / 1.25;
            eLine.Y2 = eLine.Y1 - 225;
            eLine.StrokeThickness = 100;
            eLine.Stroke = imgBrush;
            eLine.RenderTransform = new RotateTransform(startAngle, eLine.X1, eLine.Y1);
            batState = BatState.Ready;
            i = startAngle;

            lightsaberLoop.Play();

            swung = false;
        }
Ejemplo n.º 2
0
        public void Initialize(MainWindow parentWindow)
        {
            ImageBrush imgBrush = new ImageBrush(new BitmapImage(new Uri(IMAGE_PATH + "deathstar.png", UriKind.Relative)));
            hitSound = new MediaPlayer();
            hitSound.Open(new Uri(SOUND_PATH + "lightsaber_hit.mp3", UriKind.Relative));

            // Create a Line Element
            myLine = parentWindow.myLine;
            myLine.Stroke = Brushes.Black;
            myLine.X1 = parentWindow.TheCanvas.Width / 2;
            myLine.X2 = parentWindow.TheCanvas.Width / 2;
            myLine.Y1 = 5;
            myLine.Y2 = parentWindow.TheCanvas.Width / 3.2;
            myLine.StrokeThickness = 6;
            myLine.Stroke = imgBrush;

            // Create a Ellipse.
            myEllipse = parentWindow.myEllipse;

            myEllipse.Fill = imgBrush;

            // Adds the two elements to the canvas.
            goingRight = false;
            recentlyHit = false;
            currentAngle = 0;
            incrementAngle = NORMAL_INCREMENT_ANGLE;
        }
Ejemplo n.º 3
0
 // Retarts bat to their initial positions, enables the ready phase,
 //  restarts the number of misses the player has to 0.
 public void Reset(MainWindow window)
 {
     eLine.X1 = window.Width / 1.40;
     eLine.X2 = window.Width / 1.40;
     eLine.Y1 = window.Height / 1.25;
     eLine.Y2 = eLine.Y1 - 225;
     eLine.RenderTransform = new RotateTransform(startAngle, eLine.X1, eLine.Y1);
     batState = BatState.Ready;
     numMissed = 0;
 }