Beispiel #1
0
        public override IGState Update(GameTime gameTime, BaseGame game)
        {
            Timer.Update(gameTime.ElapsedGameTime);
            Wait.Update(gameTime.ElapsedGameTime);
            if (Game.KeyboardInput.TypedKey(Keys.Escape))
            {
                NextComponent = new MainMenu(Game, null, (Color == Color.Black) ? Color.White : Color.Black);
            }
            if (Timer.IsComplete)
            {
                TapTimer.Update(gameTime.ElapsedGameTime);
                if (TapTimer.IsComplete)
                {
                    TapTimer.Reset();
                    if (Location != new Vector2(-10, -10))
                    {
                        if (Marco)
                        {
                            Game.Audio.Say("Marco", pan);
                        }
                        else
                        {
                            Game.Audio.Say("Polo", pan);
                        }
                    }
                    Marco = !Marco;
                }
                if (state > 0 && state < 3)
                {
                    woosh.Update(gameTime.ElapsedGameTime);
                    if (woosh.IsComplete)
                    {
                        woosh.Reset();
                        game.Audio.Play(Cues.Swish);
                    }
                }
                switch (state)
                {
                case 0:
                {
                    Location = new Vector2(BaseGame.Random.Next((int)Width), BaseGame.Random.Next((int)Height));
                    pan      = MathHelper.Clamp((Location.X / (Width / 2f)) - 1f, -.8f, .8f);
                    state    = 1;
                    break;
                }

                case 1:
                {
                    Tap = new Vector2(-10, -10);

                    state = 2;
                    break;
                }

                case 2:
                {
                    if (Tap != new Vector2(-10, -10))
                    {
                        var d = VectorHelpers.Hypot(Location, Tap);                            //Math.Abs(Vector2.Distance(Location, Tap));
                        var m = VectorHelpers.Hypot(Vector2.Zero, new Vector2(Width, Height)); //Math.Abs(Vector2.Distance(new Vector2(0, 0), new Vector2(Width, Height)));

                        var p = d / m;
                        if (lastDistance == -1f)
                        {
                            lastDistance = p;
                        }
                        var c = MathHelper.Distance(p, lastDistance);
                        if (d < 40f)
                        {
                            lastDistance = -1f;
                            game.Audio.Say("You Got Me");
                            Wait.Reset();
                            state = 3;
                        }
                        else
                        {
                            //If within proximity of last the hotter colder warmer
                            if (c < CloseD)
                            {
                                if (p < HotD)
                                {
                                    if (p < lastDistance)
                                    {
                                        if (lastDistance < HotD)
                                        {
                                            game.Audio.Say("hotter", pan);
                                        }
                                        else
                                        {
                                            game.Audio.Say("hot", pan);
                                        }
                                    }
                                    else
                                    {
                                        game.Audio.Say("hot", pan);
                                    }
                                }
                                else if (p < WarmD)
                                {
                                    if (p < lastDistance)
                                    {
                                        if (lastDistance < WarmD)
                                        {
                                            game.Audio.Say("warmer", pan);
                                        }
                                        else
                                        {
                                            game.Audio.Say("warm", pan);
                                        }
                                    }
                                    else
                                    {
                                        game.Audio.Say("warm", pan);
                                    }
                                }
                                else if (p < ColdD)
                                {
                                    if (p < lastDistance)
                                    {
                                        game.Audio.Say("cooler", pan);
                                    }
                                    else
                                    {
                                        game.Audio.Say("cold", pan);
                                    }
                                }
                                else
                                {
                                    game.Audio.Say("freezing", pan);
                                }
                            }
                            else
                            {
                                lastDistance = -1f;
                                if (p < HotD)
                                {
                                    game.Audio.Say("hot", pan);
                                }
                                else if (p < WarmD)
                                {
                                    game.Audio.Say("warm", pan);
                                }
                                else if (p < ColdD)
                                {
                                    game.Audio.Say("cold", pan);
                                }
                                else
                                {
                                    game.Audio.Say("freezing", pan);
                                }
                            }


                            lastDistance = p;
                        }
                    }
                    Tap = new Vector2(-10, -10);
                    break;
                }

                case 3:
                {
                    Wait = new Tween(new TimeSpan(0, 0, 0, 1, 500), 0, 1);
                    Game.Audio.Say("Swipe up to play again, Down to leave");
                    DragFrom = Game.UnifiedInput.DragFrom;
                    state    = 4;
                    break;
                }

                case 4:
                {
                    break;
                }

                case 5:
                {
                    Wait  = new Tween(new TimeSpan(0, 0, 0, 1), 0, 1);
                    state = 0;

                    if (Wait.IsComplete)
                    {
                        NextComponent = new MainMenu(Game, null, (Color == Color.Black) ? Color.White : Color.Black);
                    }
                    break;
                }

                default:
                {
                    state = 0;
                    break;
                }
                }
            }
            return(NextComponent ?? this);
        }