示例#1
0
        private void WindowLoaded(object sender, EventArgs e)
        {
            playfield.ClipToBounds = true;

            this.myFallingThings = new FallingThings(MaxShapes, this.targetFramerate, NumIntraFrames);

            this.UpdatePlayfieldSize();

            this.myFallingThings.SetGravity(this.dropGravity);
            this.myFallingThings.SetDropRate(this.dropRate);
            this.myFallingThings.SetSize(this.dropSize);
            this.myFallingThings.SetPolies(PolyType.All);
            this.myFallingThings.SetGameMode(GameMode.Off);

            SensorChooser.KinectSensorChanged += this.SensorChooserKinectSensorChanged;

            this.popSound.Stream     = Properties.Resources.Pop_5;
            this.hitSound.Stream     = Properties.Resources.Hit_2;
            this.squeezeSound.Stream = Properties.Resources.Squeeze;

            this.popSound.Play();

            TimeBeginPeriod(TimerResolution);
            var myGameThread = new Thread(this.GameThread);

            myGameThread.SetApartmentState(ApartmentState.STA);
            myGameThread.Start();

            FlyingText.NewFlyingText(this.screenRect.Width / 30, new Point(this.screenRect.Width / 2, this.screenRect.Height / 2), "Shapes!");
        }
        private void AddToScore(int player, int points, System.Windows.Point center)
        {
            if (this.scores.ContainsKey(player))
            {
                this.scores[player] = this.scores[player] + points;
            }
            else
            {
                this.scores.Add(player, points);
            }

            FlyingText.NewFlyingText(this.sceneRect.Width / 300, center, "+" + points);
        }
示例#3
0
        private void HandleGameTimer(int param)
        {
            // Draw new Wpf scene by adding all objects to canvas
            playfield.Children.Clear();
            foreach (var player in this.players)
            {
                player.Value.Draw(playfield.Children);
            }
            //BannerText.Draw(playfield.Children);
            FlyingText.Draw(playfield.Children);

            this.CheckPlayers();
        }
示例#4
0
        private void SubtractFromScore(int player, int points, System.Windows.Point center)
        {
            if (this.scores.ContainsKey(player))
            {
                this.scores[player] = this.scores[player] - points;
            }
            else
            {
                this.scores.Add(player, MaxPoints - points);
            }

            FlyingText.NewFlyingText(this.sceneRect.Width / 300, center, "-" + points);
        }
示例#5
0
        public void AddToScore(int player, int points, System.Windows.Point center)
        {
            //if (this.scores.ContainsKey(player))
            //{
            //    this.scores[player] = this.scores[player] + points;
            //}
            //else
            //{
            //    this.scores.Add(player, points);
            //}

            this.score += points;

            FlyingText.NewFlyingText(this.sceneRect.Width / 300, center, "+" + points);
        }
示例#6
0
        public static void Draw(UIElementCollection children)
        {
            for (int i = 0; i < FlyingTexts.Count; i++)
            {
                FlyingText flyout = FlyingTexts[i];
                if (flyout.alpha <= 0)
                {
                    FlyingTexts.Remove(flyout);
                    i--;
                }
            }

            foreach (var flyout in FlyingTexts)
            {
                flyout.Advance();
                children.Add(flyout.label);
            }
        }
示例#7
0
        private void HandleGameTimer(int param)
        {
            // Every so often, notify what our actual framerate is
            if ((this.frameCount % 100) == 0)
            {
                this.myFallingThings.SetFramerate(1000.0 / this.actualFrameTime);
            }

            // Advance animations, and do hit testing.
            for (int i = 0; i < NumIntraFrames; ++i)
            {
                foreach (var pair in this.players)
                {
                    HitType hit = this.myFallingThings.LookForHits(pair.Value.Segments, pair.Value.GetId());
                    if ((hit & HitType.Squeezed) != 0)
                    {
                        this.squeezeSound.Play();
                    }
                    else if ((hit & HitType.Popped) != 0)
                    {
                        this.popSound.Play();
                    }
                    else if ((hit & HitType.Hand) != 0)
                    {
                        this.hitSound.Play();
                    }
                }

                this.myFallingThings.AdvanceFrame();
            }

            // Draw new Wpf scene by adding all objects to canvas
            playfield.Children.Clear();
            this.myFallingThings.DrawFrame(this.playfield.Children);
            foreach (var player in this.players)
            {
                player.Value.Draw(playfield.Children);
            }

            BannerText.Draw(playfield.Children);
            FlyingText.Draw(playfield.Children);

            this.CheckPlayers();
        }
示例#8
0
        private void AddToScore(int player, int points, System.Windows.Point center)
        {
            if (this.scores.ContainsKey(player))
            {
                if (this.scores[player] >= 20)
                {
                    FlyingText.NewFlyingText(this.sceneRect.Width / 30, new Point(this.sceneRect.Width / 2, this.sceneRect.Height / 2), "Player " + player + " WIN!");
                    this.SetDropRate(0);
                    this.SetGravity(0);
                    //MainWindow.restartButton.Height = 50;
                    //MainWindow.show_button();
                }
                else
                {
                    this.scores[player] = this.scores[player] + points;
                }
            }
            else
            {
                this.scores.Add(player, points);
            }

            FlyingText.NewFlyingText(this.sceneRect.Width / 300, center, "+" + points);
        }
示例#9
0
        private void RecognizerSaidSomething(object sender, SpeechRecognizer.SaidSomethingEventArgs e)
        {
            FlyingText.NewFlyingText(this.screenRect.Width / 30, new Point(this.screenRect.Width / 2, this.screenRect.Height / 2), e.Matched);
            switch (e.Verb)
            {
            case SpeechRecognizer.Verbs.Pause:
                this.myFallingThings.SetDropRate(0);
                this.myFallingThings.SetGravity(0);
                break;

            case SpeechRecognizer.Verbs.Resume:
                this.myFallingThings.SetDropRate(this.dropRate);
                this.myFallingThings.SetGravity(this.dropGravity);
                break;

            case SpeechRecognizer.Verbs.Reset:
                this.dropRate    = DefaultDropRate;
                this.dropSize    = DefaultDropSize;
                this.dropGravity = DefaultDropGravity;
                this.myFallingThings.SetPolies(PolyType.All);
                this.myFallingThings.SetDropRate(this.dropRate);
                this.myFallingThings.SetGravity(this.dropGravity);
                this.myFallingThings.SetSize(this.dropSize);
                this.myFallingThings.SetShapesColor(System.Windows.Media.Color.FromRgb(0, 0, 0), true);
                this.myFallingThings.Reset();
                break;

            case SpeechRecognizer.Verbs.DoShapes:
                this.myFallingThings.SetPolies(e.Shape);
                break;

            case SpeechRecognizer.Verbs.RandomColors:
                this.myFallingThings.SetShapesColor(System.Windows.Media.Color.FromRgb(0, 0, 0), true);
                break;

            case SpeechRecognizer.Verbs.Colorize:
                this.myFallingThings.SetShapesColor(e.RgbColor, false);
                break;

            case SpeechRecognizer.Verbs.ShapesAndColors:
                this.myFallingThings.SetPolies(e.Shape);
                this.myFallingThings.SetShapesColor(e.RgbColor, false);
                break;

            case SpeechRecognizer.Verbs.More:
                this.dropRate *= 1.5;
                this.myFallingThings.SetDropRate(this.dropRate);
                break;

            case SpeechRecognizer.Verbs.Fewer:
                this.dropRate /= 1.5;
                this.myFallingThings.SetDropRate(this.dropRate);
                break;

            case SpeechRecognizer.Verbs.Bigger:
                this.dropSize *= 1.5;
                if (this.dropSize > MaxShapeSize)
                {
                    this.dropSize = MaxShapeSize;
                }

                this.myFallingThings.SetSize(this.dropSize);
                break;

            case SpeechRecognizer.Verbs.Biggest:
                this.dropSize = MaxShapeSize;
                this.myFallingThings.SetSize(this.dropSize);
                break;

            case SpeechRecognizer.Verbs.Smaller:
                this.dropSize /= 1.5;
                if (this.dropSize < MinShapeSize)
                {
                    this.dropSize = MinShapeSize;
                }

                this.myFallingThings.SetSize(this.dropSize);
                break;

            case SpeechRecognizer.Verbs.Smallest:
                this.dropSize = MinShapeSize;
                this.myFallingThings.SetSize(this.dropSize);
                break;

            case SpeechRecognizer.Verbs.Faster:
                this.dropGravity *= 1.25;
                if (this.dropGravity > 4.0)
                {
                    this.dropGravity = 4.0;
                }

                this.myFallingThings.SetGravity(this.dropGravity);
                break;

            case SpeechRecognizer.Verbs.Slower:
                this.dropGravity /= 1.25;
                if (this.dropGravity < 0.25)
                {
                    this.dropGravity = 0.25;
                }

                this.myFallingThings.SetGravity(this.dropGravity);
                break;
            }
        }
示例#10
0
        private void RecognizerSaidSomething(object sender, SpeechRecognizer.SaidSomethingEventArgs e)
        {
            switch (e.Verb)
            {
            case SpeechRecognizer.Verbs.Protego:
                if (gamePaused)
                {
                    return;
                }
                FlyingText.NewFlyingText(this.screenRect.Width / 30, new Point(this.screenRect.Width / 2, this.screenRect.Height / 2), "Protego");
                double averageXWristPosition = this.rightWristXPosition.Sum() / FRAME_SIZE;
                double averageYWristPosition = this.rightWristYPosition.Sum() / FRAME_SIZE;
                double averageXBodyPosition  = this.shoulderCenterXPosition.Sum() / FRAME_SIZE;
                double averageYBodyPosition  = this.shoulderCenterYPosition.Sum() / FRAME_SIZE;
                double squaredDist           = Math.Pow(averageXWristPosition - averageXBodyPosition, 2) + Math.Pow(averageYWristPosition - averageYBodyPosition, 2);
                // Wrist must be within sqrt(3000) distance of shoulder center (sternum)
                if (squaredDist < 3000)
                {
                    this.myFallingThings.moveThingsAway();
                    this.myFallingThings.DrawShape(PolyType.Circle, MaxShapeSize, System.Windows.Media.Color.FromRgb(255, 255, 255));
                    this.protegoDuration = 300;     // Shield is displayed for 300 frames
                    this.hitSound.Play();
                }
                break;

            case SpeechRecognizer.Verbs.Expelliarmus:
                if (gamePaused)
                {
                    return;
                }
                FlyingText.NewFlyingText(this.screenRect.Width / 30, new Point(this.screenRect.Width / 2, this.screenRect.Height / 2), "Expelliarmus");
                // We take the oldest 1/3 of frames within our window to compensate for delay of speech recognition
                double averageXVelocity = this.rightWristXVelocity.Take(Convert.ToInt32(FRAME_SIZE / 3)).Sum() * 3 / FRAME_SIZE;
                double xMoved           = Math.Abs(this.rightWristXPosition[Convert.ToInt32(FRAME_SIZE / 2)] - this.rightWristXPosition[0]);
                // Must be moving left to right, and must have moved a specified minimum distance
                if (averageXVelocity > 0 && xMoved > 10)
                {
                    this.myFallingThings.removeThings();
                    this.myFallingThings.AddToScore(0, 10, new Point(this.shoulderCenterXPosition.Sum() / FRAME_SIZE, this.shoulderCenterYPosition.Sum() / FRAME_SIZE));
                    this.popSound.Play();
                }
                break;

            case SpeechRecognizer.Verbs.Stupefy:
                if (gamePaused)
                {
                    return;
                }
                FlyingText.NewFlyingText(this.screenRect.Width / 30, new Point(this.screenRect.Width / 2, this.screenRect.Height / 2), "Stupefy");
                double averageYVelocity = this.rightWristYVelocity.Sum() / FRAME_SIZE;
                // Must be moving up to down
                if (averageYVelocity > 0)
                {
                    this.myFallingThings.SetSpinRate(0);
                    this.myFallingThings.SetGravity(0);
                    this.myFallingThings.AddToScore(0, 5, new Point(this.shoulderCenterXPosition.Sum() / FRAME_SIZE, this.shoulderCenterYPosition.Sum() / FRAME_SIZE));
                    this.hitSound.Play();
                }
                break;

            case SpeechRecognizer.Verbs.Reset:
                FlyingText.NewFlyingText(this.screenRect.Width / 30, new Point(this.screenRect.Width / 2, this.screenRect.Height / 2), "Reset");
                this.dropRate    = DefaultDropRate;
                this.dropSize    = DefaultDropSize;
                this.dropGravity = DefaultDropGravity;
                this.myFallingThings.SetPolies(PolyType.All);
                this.myFallingThings.SetDropRate(this.dropRate);
                this.myFallingThings.SetGravity(this.dropGravity);
                this.myFallingThings.SetSize(this.dropSize);
                this.myFallingThings.SetShapesColor(System.Windows.Media.Color.FromRgb(0, 0, 0), true);
                this.myFallingThings.Reset();
                this.gamePaused = false;
                break;
            }
        }
示例#11
0
        private void HandleGameTimer(int param)
        {
            // Every so often, notify what our actual framerate is
            if ((this.frameCount % 100) == 0)
            {
                this.myFallingThings.SetFramerate(1000.0 / this.actualFrameTime);
            }

            // Advance animations, save current skeleton state, and do hit testing.
            for (int i = 0; i < NumIntraFrames; ++i)
            {
                BoneData rightShoulderData = new BoneData();
                foreach (var pair in this.players) // Although our game is designed for one player, this gives us the potential for multiplayer
                {
                    Bone     rightArm = new Bone(JointType.WristRight, JointType.ElbowRight);
                    BoneData rightArmData;
                    pair.Value.Segments.TryGetValue(rightArm, out rightArmData);
                    Bone rightShoulder = new Bone(JointType.ShoulderCenter, JointType.ShoulderRight);

                    pair.Value.Segments.TryGetValue(rightShoulder, out rightShoulderData);
                    this.rightWristXPosition.RemoveAt(0);
                    this.rightWristXPosition.Add(rightArmData.Segment.X1);
                    this.rightWristXVelocity.RemoveAt(0);
                    this.rightWristXVelocity.Add(rightArmData.XVelocity);
                    this.rightWristYPosition.RemoveAt(0);
                    this.rightWristYPosition.Add(rightArmData.Segment.Y1);
                    this.rightWristYVelocity.RemoveAt(0);
                    this.rightWristYVelocity.Add(rightArmData.YVelocity);
                    this.shoulderCenterXPosition.RemoveAt(0);
                    this.shoulderCenterXPosition.Add(rightShoulderData.Segment.X1);
                    this.shoulderCenterYPosition.RemoveAt(0);
                    this.shoulderCenterYPosition.Add(rightShoulderData.Segment.Y1);

                    // Decrement protegoDuration each frame until 0, at which point
                    if (this.protegoDuration > 0)
                    {
                        this.protegoDuration -= 1;
                    }
                    else
                    {
                        this.myFallingThings.RemoveShape(PolyType.Circle);
                    }


                    bool hit = this.myFallingThings.CheckPlayerHit(pair.Value.Segments, pair.Value.GetId());
                    if (hit)
                    {
                        // Game over
                        this.myFallingThings.PauseGame();
                        this.gamePaused = true;
                        FlyingText.NewFlyingText(this.screenRect.Width / 30, new Point(this.screenRect.Width / 2, this.screenRect.Height / 2), "Game over!", System.Windows.Media.Color.FromArgb(255, 255, 0, 0));
                        this.squeezeSound.Play();
                    }
                }

                this.myFallingThings.AdvanceFrame(rightShoulderData.Segment.X1, rightShoulderData.Segment.Y1);
            }

            // Draw new Wpf scene by adding all objects to canvas
            playfield.Children.Clear();
            this.myFallingThings.DrawFrame(this.playfield.Children);
            foreach (var player in this.players)
            {
                player.Value.Draw(playfield.Children);
            }

            FlyingText.Draw(playfield.Children);

            this.CheckPlayers();
        }
示例#12
0
 private void FlyText(string str)
 {
     FlyingText.NewFlyingText(this.screenRect.Width / 30, new Point(this.screenRect.Width / 2, this.screenRect.Height / 2), str);
 }