Example #1
0
 public void Reset()
 {
     successful = false;
     reverse    = false;
     start      = true;
     pause      = false;
     gameOver   = false;
     Camera     = null;
     Game.Components.Remove(gameScore);
     Game.Components.Remove(countDown);
     countDown = null;
     Game.Components.Remove(bobEntity);
     space.Remove(stageMesh);
     Game.Components.Remove(stageMod);
     space.Remove(bobBox);
     Game.Components.Remove(bgMod);
     Game.Components.Remove(gamemenu);
     songInstance.Stop();
     if (engineInstance.State == SoundState.Playing)
     {
         engineInstance.Stop();
     }
     if (hyperspaceInsance.State == SoundState.Playing)
     {
         hyperspaceInsance.Stop();
     }
     Initialize();
 }
Example #2
0
        public override void Update(GameTime gameTime)
        {
            //100% cpu utilization with a i7-2820m, and it still not perform well
            //Thread trd = new Thread(new ThreadStart(this.boundingBoxTasks));
            //trd.IsBackground = true;
            //trd.Start();
            //boundingBoxTasks();

            //alternative solution: check if the bob collide with a fake/invisible box at the and of the track



            KeyboardState = Keyboard.GetState();
            MouseState    = Mouse.GetState();
            //codice per uscire dal gioco
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == Microsoft.Xna.Framework.Input.ButtonState.Pressed ||
                KeyboardState.IsKeyDown(Keys.Escape))
            {
                Game.Exit();
            }
            //aggiorno la telecamera
            Camera.Update((float)gameTime.ElapsedGameTime.TotalSeconds);
            //ricavo la direzione top-down del bob e applico un'accellerazione in questa direzione per tenerlo il piu' possibile incollato alla  pista
            Vector3 dw = bobBox.OrientationMatrix.Down;

            bobBox.LinearVelocity += (0.1f * dw - bobBox.LinearVelocity / 60) / 7;

            if (!pause && !start && !gameOver)
            {
                //gestione pausa
                if (KeyboardState.IsKeyDown(Keys.P) && prevStatePauseKey == false)
                {
                    pause            = true;
                    gamemenu.pause   = true;
                    gamemenu.Visible = true;
                    if (reverseTimer != null)
                    {
                        reverseTimer.pause = true;
                    }
                    if (gameScore != null)
                    {
                        gameScore.pause = true;
                    }
                }
                //aggiorno la fisica del gioco
                space.Update();

                if (bobBox.OrientationMatrix.Down.Y > 0.70 && !reverse)
                {
                    reverse      = true;
                    reverseTimer = new timeSprite(Game, 3000f, new Vector2(465, 220), timeFont, Color.Red, false, 0);
                    reverseTimer.stringToAppend = "reversed ";
                    Game.Components.Add(reverseTimer);
                }
                else if (bobBox.OrientationMatrix.Down.Y <= 0.70)
                {
                    reverse = false;
                    if (reverseTimer != null)
                    {
                        Game.Components.Remove(reverseTimer);
                    }
                }
                if (reverseTimer != null && reverseTimer.timeOver)
                {
                    Game.Components.Remove(reverseTimer);
                    reverseTimer      = null;
                    gameOver          = true;
                    gameScore.pause   = true;
                    gamemenu.gameOver = true;
                    gamemenu.Visible  = true;
                }

                if ((Game as Engine).usingBalanceBoard) //update with balance board
                {
                    float horizontaldelta = 0;
                    float verticaldelta   = 0;
                    float total           = 0;

                    for (int i = 0; i < balanceBoards.Count; i++)
                    {
                        BalanceBoardSensorsF balance = balanceBoards[i].WiimoteState.BalanceBoardState.SensorValuesKg;
                        //sommo tutti i contributi di tutte le balanceboards
                        horizontaldelta += (balance.BottomRight + balance.TopRight) - (balance.BottomLeft + balance.TopLeft);
                        verticaldelta   += (balance.TopLeft + balance.TopRight) - (balance.BottomLeft + balance.BottomRight);
                        total           += (balance.TopLeft + balance.TopRight) + (balance.BottomLeft + balance.BottomRight);
                    }
                    //faccio la media
                    horizontaldelta = horizontaldelta / balanceBoards.Count;
                    verticaldelta   = verticaldelta / balanceBoards.Count;
                    total           = total / balanceBoards.Count;


                    //logica di spostamento
                    if (total > 30) //per evitare spostamenti non voluti, visto che il corpo non sarà mai perfettamente fermo
                    {
                        //la percentuale di peso che si può spostare è limitata alla metà del peso corporeo
                        float forwardThreshold = 0.5f;
                        float lateralThreshold = 0.5f;
                        float forwardMovement  = (verticaldelta / total) / (Game as Engine).sensibility;
                        float lateralMovement  = (0.05f * horizontaldelta / total) / (Game as Engine).sensibility; //0.2 è per limitare il movimento laterale

                        //gestione dei trashold per evitare che ci siano movimenti esagerati
                        if (verticaldelta / total > forwardThreshold)
                        {
                            forwardMovement = forwardThreshold / (Game as Engine).sensibility;
                        }
                        if (verticaldelta / total < -forwardThreshold)
                        {
                            forwardMovement = -forwardThreshold / (Game as Engine).sensibility;
                        }
                        if (horizontaldelta / total > lateralThreshold)
                        {
                            lateralMovement = 0.5f * lateralThreshold / (Game as Engine).sensibility;
                        }
                        if (horizontaldelta / total < -lateralThreshold)
                        {
                            lateralMovement = -0.5f * lateralThreshold / (Game as Engine).sensibility;
                        }

                        //effettuo lo spostamento del bob, proporzionale ai valori della bb
                        if (forwardMovement >= 0.2)
                        {
                            Vector3 fw = bobBox.OrientationMatrix.Forward;
                            bobBox.LinearVelocity += (forwardMovement * fw + -bobBox.LinearVelocity / 60) / 7;
                        }

                        if (forwardMovement < -0.2)
                        {
                            Vector3 fw = bobBox.OrientationMatrix.Forward;
                            bobBox.LinearVelocity -= (-forwardMovement * fw - bobBox.LinearVelocity / 60) / 7;
                        }

                        if (lateralMovement < -0.2)
                        {
                            Vector3 left = bobBox.OrientationMatrix.Left;
                            bobBox.LinearVelocity  += (-lateralMovement * left - bobBox.LinearVelocity / 60) / 7;
                            bobBox.AngularVelocity += (0.5f * Vector3.One - bobBox.AngularVelocity / 60) / 7;
                        }

                        if (lateralMovement > 0.2)
                        {
                            Vector3 right = bobBox.OrientationMatrix.Right;
                            bobBox.LinearVelocity  += (lateralMovement * right - bobBox.LinearVelocity / 60) / 7;
                            bobBox.AngularVelocity -= (0.5f * Vector3.One - bobBox.LinearVelocity / 60) / 7;
                        }
                    }
                }
                else //update with keyboard
                {
                    //la stessa di prima la faccio se non sono in pausa e se non c'è il countdown alla pressione delle frecce
                    if (KeyboardState.IsKeyDown(Keys.Up))
                    {
                        Vector3 fw = bobBox.OrientationMatrix.Forward;
                        bobBox.LinearVelocity += (1.50f * fw - bobBox.LinearVelocity / 60) / 7;
                    }
                    if (KeyboardState.IsKeyDown(Keys.Down))
                    {
                        Vector3 fw = bobBox.OrientationMatrix.Forward;
                        bobBox.LinearVelocity -= (1.18f * fw - bobBox.LinearVelocity / 60) / 7;
                    }
                    if (KeyboardState.IsKeyDown(Keys.Left))
                    {
                        Vector3 left = bobBox.OrientationMatrix.Left;
                        //old behaviour
                        //bobBox.LinearVelocity += (0.7f * left - bobBox.LinearVelocity / 60) / 7;
                        //new mod
                        bobBox.LinearVelocity  += (0.7f * left - bobBox.LinearVelocity / 60) / 7;
                        bobBox.AngularVelocity += (0.1f * Vector3.One - bobBox.AngularVelocity / 60) / 7;
                    }
                    if (KeyboardState.IsKeyDown(Keys.Right))
                    {
                        Vector3 right = bobBox.OrientationMatrix.Right;
                        //old behaviour
                        //bobBox.LinearVelocity += (0.7f * right - bobBox.LinearVelocity / 60) / 7;
                        //new mod
                        bobBox.LinearVelocity  += (0.7f * right - bobBox.LinearVelocity / 60) / 7;
                        bobBox.AngularVelocity -= (0.1f * Vector3.One - bobBox.LinearVelocity / 60) / 7;
                    }
                }

                //engineInstance.Play();
                if (engineInstance.State != SoundState.Playing)
                {
                    engineInstance.IsLooped = true;
                    engineInstance.Play();
                }

                //update delle caratteristiche sonore
                actualForwardVelocity = Vector3.Dot(bobBox.LinearVelocity, bobBox.OrientationMatrix.Forward);

                //enginePitch += Vector3.Dot(bobBox.LinearVelocity, bobBox.OrientationMatrix.Forward) / 1000;
                enginePitch  += (actualForwardVelocity - previousForwardVelocity) / 10;
                engineVolume += (actualForwardVelocity - previousForwardVelocity) / 10;

                previousForwardVelocity = actualForwardVelocity;

                //engineVolume = Vector3.Dot(bobBox.LinearVelocity, bobBox.OrientationMatrix.Forward) / 30;
                //engine pitch must be bounded from -1.0f to 1.0f and volume from 0.0f to 1.0f;
                if (engineInstance.State == SoundState.Playing)
                {
                    if (enginePitch >= 1.0f)
                    {
                        enginePitch = 1.0f;
                        if (hyperspaceAlreadyPlayed == false)
                        {
                            hyperspaceInsance.Play();
                            hyperspaceAlreadyPlayed = true;
                        }
                    }
                    else
                    {
                        hyperspaceAlreadyPlayed = false;
                        if (enginePitch <= -1.0f)
                        {
                            enginePitch = -1.0f;
                        }
                    }
                    if (engineVolume >= 1.0f)
                    {
                        engineVolume = 1.0f;
                    }
                    else
                    {
                        if (engineVolume <= 0.0f)
                        {
                            engineVolume = 0.0f;
                        }
                    }

                    engineInstance.Pitch  = enginePitch;
                    engineInstance.Volume = engineVolume;

                    if (Vector3.Distance(EndPoint, bobBox.Position) < 5)
                    {
                        if (reverseTimer != null)
                        {
                            reverseTimer.pause = true;
                        }
                        gameOver          = true;
                        gameScore.pause   = true;
                        gamemenu.gameOver = true;
                        successful        = true;
                        gamemenu.Visible  = true;
                    }

                    if (bobBox.Position.Y < -70)
                    {
                        if (reverseTimer != null)
                        {
                            reverseTimer.pause = true;
                        }
                        gameOver          = true;
                        gameScore.pause   = true;
                        gamemenu.gameOver = true;
                        gamemenu.Visible  = true;
                    }
                }
                //modify engine pitch, from -1.0f to 1.0f
            }
            //codice per la gestione del countdown
            else if (start)
            {
                //faccio partire il brano di sottofondo
                //songInstance.Volume = 0.75f;
                //songInstance.IsLooped = false;
                //songInstance.Play();

                if (countDown == null)
                {
                    countDown = new timeSprite(Game, 3000f, new Vector2(465, 220), timeFont, Color.DarkRed, false, 0);
                    Game.Components.Add(countDown);
                }
                else if (countDown.timeOver)
                {
                    songInstance.Volume   = 0.2f;
                    songInstance.IsLooped = true;
                    songInstance.Play();
                    countDown.Dispose();
                    start     = false;
                    gameScore = new timeSprite(Game, 0f, new Vector2(20, 20), timeFont, Color.White, true, 3);
                    Game.Components.Add(gameScore);
                }
            }

            else if (pause)
            {
                if (KeyboardState.IsKeyDown(Keys.Enter) && !prevStateEnterKey)
                {
                    if (gamemenu.selection == 0)
                    {
                        pause            = false;
                        gamemenu.pause   = false;
                        gamemenu.Visible = false;
                    }
                    else if (gamemenu.selection == 1)
                    {
                        gamemenu.selection = 0;
                        gamemenu.Visible   = false;
                        Reset();
                        nextLevel();
                    }
                    else if (gamemenu.selection == 2)
                    {
                        goToMenu();
                    }
                }
                if (KeyboardState.IsKeyDown(Keys.Down) && keyTimer > 500)
                {
                    if (gamemenu.selection < 2)
                    {
                        gamemenu.selection++;
                    }
                    else
                    {
                        gamemenu.selection = 0;
                    }
                    keyTimer = 0;
                }
                if (KeyboardState.IsKeyDown(Keys.Up) && keyTimer > 500)
                {
                    if (gamemenu.selection > 0)
                    {
                        gamemenu.selection--;
                    }
                    else
                    {
                        gamemenu.selection = 2;
                    }
                    keyTimer = 0;
                }
                keyTimer += gameTime.ElapsedGameTime.Milliseconds;
            }

            else if (gameOver)
            {
                space.Update();
                if (KeyboardState.IsKeyDown(Keys.Enter) && !prevStateEnterKey)
                {
                    if (gamemenu.selection == 0)
                    {
                        Reset();
                        nextLevel();
                        gamemenu.Visible   = false;
                        gamemenu.selection = 0;
                    }
                    else
                    {
                        if (successful)
                        {
                            goToSaveScore();
                        }
                        else
                        {
                            goToMenu();
                        }
                    }
                }
                if ((KeyboardState.IsKeyDown(Keys.Up) || KeyboardState.IsKeyDown(Keys.Down)) && keyTimer > 500)
                {
                    if (gamemenu.selection == 1)
                    {
                        gamemenu.selection = 0;
                    }
                    else
                    {
                        gamemenu.selection = 1;
                    }
                    keyTimer = 0;
                }
                keyTimer += gameTime.ElapsedGameTime.Milliseconds;
            }

            prevStatePauseKey = KeyboardState.IsKeyDown(Keys.P);

            base.Update(gameTime);
        }
Example #3
0
        public override void Update(GameTime gameTime)
        {
            //100% cpu utilization with a i7-2820m, and it still not perform well
            //Thread trd = new Thread(new ThreadStart(this.boundingBoxTasks));
            //trd.IsBackground = true;
            //trd.Start();
            //boundingBoxTasks();

            //alternative solution: check if the bob collide with a fake/invisible box at the and of the track

            KeyboardState = Keyboard.GetState();
            MouseState = Mouse.GetState();
            //codice per uscire dal gioco
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == Microsoft.Xna.Framework.Input.ButtonState.Pressed
                || KeyboardState.IsKeyDown(Keys.Escape))
                Game.Exit();
            //aggiorno la telecamera
            Camera.Update((float)gameTime.ElapsedGameTime.TotalSeconds);
            //ricavo la direzione top-down del bob e applico un'accellerazione in questa direzione per tenerlo il piu' possibile incollato alla  pista
            Vector3 dw = bobBox.OrientationMatrix.Down;
            bobBox.LinearVelocity += (0.1f * dw - bobBox.LinearVelocity / 60) / 7;

            if (!pause && !start && !gameOver)
            {

                //gestione pausa
                if (KeyboardState.IsKeyDown(Keys.P) && prevStatePauseKey == false)
                {
                    pause = true;
                    gamemenu.pause = true;
                    gamemenu.Visible = true;
                    if (reverseTimer != null)
                        reverseTimer.pause = true;
                    if (gameScore != null)
                        gameScore.pause = true;
                }
                //aggiorno la fisica del gioco
                space.Update();

                if (bobBox.OrientationMatrix.Down.Y > 0.70 && !reverse)
                {
                    reverse = true;
                    reverseTimer = new timeSprite(Game, 3000f, new Vector2(465, 220), timeFont, Color.Red, false, 0);
                    reverseTimer.stringToAppend = "reversed ";
                    Game.Components.Add(reverseTimer);
                }
                else if (bobBox.OrientationMatrix.Down.Y <=  0.70)
                {
                    reverse = false;
                    if (reverseTimer != null)
                    {
                        Game.Components.Remove(reverseTimer);
                    }
                }
                if (reverseTimer != null && reverseTimer.timeOver)
                {
                    Game.Components.Remove(reverseTimer);
                    reverseTimer = null;
                    gameOver = true;
                    gameScore.pause = true;
                    gamemenu.gameOver = true;
                    gamemenu.Visible = true;
                }

                if ((Game as Engine).usingBalanceBoard) //update with balance board
                {

                    float horizontaldelta = 0;
                    float verticaldelta = 0;
                    float total = 0;

                    for (int i = 0; i < balanceBoards.Count; i++)
                    {
                        BalanceBoardSensorsF balance = balanceBoards[i].WiimoteState.BalanceBoardState.SensorValuesKg;
                        //sommo tutti i contributi di tutte le balanceboards
                        horizontaldelta += (balance.BottomRight + balance.TopRight) - (balance.BottomLeft + balance.TopLeft);
                        verticaldelta += (balance.TopLeft + balance.TopRight) - (balance.BottomLeft + balance.BottomRight);
                        total += (balance.TopLeft + balance.TopRight) + (balance.BottomLeft + balance.BottomRight);

                    }
                    //faccio la media
                    horizontaldelta = horizontaldelta / balanceBoards.Count;
                    verticaldelta = verticaldelta / balanceBoards.Count;
                    total = total / balanceBoards.Count;

                    //logica di spostamento
                    if (total > 30) //per evitare spostamenti non voluti, visto che il corpo non sarà mai perfettamente fermo
                    {
                        //la percentuale di peso che si può spostare è limitata alla metà del peso corporeo
                        float forwardThreshold = 0.5f;
                        float lateralThreshold = 0.5f;
                        float forwardMovement = (verticaldelta / total)/(Game as Engine).sensibility;
                        float lateralMovement = (0.05f*horizontaldelta / total)/(Game as Engine).sensibility; //0.2 è per limitare il movimento laterale

                        //gestione dei trashold per evitare che ci siano movimenti esagerati
                        if (verticaldelta / total > forwardThreshold)
                            forwardMovement = forwardThreshold / (Game as Engine).sensibility;
                        if (verticaldelta / total < -forwardThreshold)
                            forwardMovement = -forwardThreshold / (Game as Engine).sensibility;
                        if (horizontaldelta / total > lateralThreshold)
                            lateralMovement = 0.5f * lateralThreshold / (Game as Engine).sensibility;
                        if (horizontaldelta / total < -lateralThreshold)
                            lateralMovement = -0.5f * lateralThreshold / (Game as Engine).sensibility;

                        //effettuo lo spostamento del bob, proporzionale ai valori della bb
                        if ( forwardMovement>= 0.2)
                        {
                            Vector3 fw = bobBox.OrientationMatrix.Forward;
                            bobBox.LinearVelocity += (forwardMovement * fw + - bobBox.LinearVelocity / 60) / 7;
                        }

                        if (forwardMovement < -0.2)
                        {
                            Vector3 fw = bobBox.OrientationMatrix.Forward;
                            bobBox.LinearVelocity -= (-forwardMovement * fw - bobBox.LinearVelocity / 60) / 7;
                        }

                        if (lateralMovement < -0.2)
                        {
                            Vector3 left = bobBox.OrientationMatrix.Left;
                            bobBox.LinearVelocity += (-lateralMovement * left - bobBox.LinearVelocity / 60) / 7;
                            bobBox.AngularVelocity += (0.5f * Vector3.One - bobBox.AngularVelocity / 60) / 7;
                        }

                        if (lateralMovement > 0.2)
                        {
                            Vector3 right = bobBox.OrientationMatrix.Right;
                            bobBox.LinearVelocity += (lateralMovement * right - bobBox.LinearVelocity / 60) / 7;
                            bobBox.AngularVelocity -= (0.5f * Vector3.One - bobBox.LinearVelocity / 60) / 7;
                        }

                    }

                }
                else //update with keyboard
                {
                    //la stessa di prima la faccio se non sono in pausa e se non c'è il countdown alla pressione delle frecce
                    if (KeyboardState.IsKeyDown(Keys.Up))
                    {
                        Vector3 fw = bobBox.OrientationMatrix.Forward;
                        bobBox.LinearVelocity += (1.50f * fw - bobBox.LinearVelocity / 60) / 7;
                    }
                    if (KeyboardState.IsKeyDown(Keys.Down))
                    {
                        Vector3 fw = bobBox.OrientationMatrix.Forward;
                        bobBox.LinearVelocity -= (1.18f * fw - bobBox.LinearVelocity / 60) / 7;
                    }
                    if (KeyboardState.IsKeyDown(Keys.Left))
                    {
                        Vector3 left = bobBox.OrientationMatrix.Left;
                        //old behaviour
                        //bobBox.LinearVelocity += (0.7f * left - bobBox.LinearVelocity / 60) / 7;
                        //new mod
                        bobBox.LinearVelocity += (0.7f * left - bobBox.LinearVelocity / 60) / 7;
                        bobBox.AngularVelocity += (0.1f * Vector3.One - bobBox.AngularVelocity / 60) / 7;
                    }
                    if (KeyboardState.IsKeyDown(Keys.Right))
                    {
                        Vector3 right = bobBox.OrientationMatrix.Right;
                        //old behaviour
                        //bobBox.LinearVelocity += (0.7f * right - bobBox.LinearVelocity / 60) / 7;
                        //new mod
                        bobBox.LinearVelocity += (0.7f * right - bobBox.LinearVelocity / 60) / 7;
                        bobBox.AngularVelocity -= (0.1f * Vector3.One - bobBox.LinearVelocity / 60) / 7;
                    }
                }

                //engineInstance.Play();
                if (engineInstance.State != SoundState.Playing)
                {
                    engineInstance.IsLooped = true;
                    engineInstance.Play();
                }

                //update delle caratteristiche sonore
                actualForwardVelocity = Vector3.Dot(bobBox.LinearVelocity, bobBox.OrientationMatrix.Forward);

                //enginePitch += Vector3.Dot(bobBox.LinearVelocity, bobBox.OrientationMatrix.Forward) / 1000;
                enginePitch += (actualForwardVelocity - previousForwardVelocity)/10;
                engineVolume += (actualForwardVelocity - previousForwardVelocity)/10;

                previousForwardVelocity = actualForwardVelocity;

                //engineVolume = Vector3.Dot(bobBox.LinearVelocity, bobBox.OrientationMatrix.Forward) / 30;
                //engine pitch must be bounded from -1.0f to 1.0f and volume from 0.0f to 1.0f;
                if (engineInstance.State == SoundState.Playing)
                {

                    if (enginePitch >= 1.0f)
                    {
                        enginePitch = 1.0f;
                        if (hyperspaceAlreadyPlayed == false)
                        {
                            hyperspaceInsance.Play();
                            hyperspaceAlreadyPlayed = true;
                        }
                    }
                    else
                    {
                        hyperspaceAlreadyPlayed = false;
                        if (enginePitch <= -1.0f)
                            enginePitch = -1.0f;
                    }
                    if (engineVolume >= 1.0f)
                    {
                        engineVolume = 1.0f;
                    }
                    else
                    {
                        if (engineVolume <= 0.0f)
                            engineVolume = 0.0f;
                    }

                    engineInstance.Pitch = enginePitch;
                    engineInstance.Volume = engineVolume;

                    if (Vector3.Distance(EndPoint, bobBox.Position) < 5)
                    {
                        if (reverseTimer != null)
                        {
                            reverseTimer.pause = true;
                        }
                        gameOver = true;
                        gameScore.pause = true;
                        gamemenu.gameOver = true;
                        successful = true;
                        gamemenu.Visible = true;
                    }

                    if(bobBox.Position.Y<-70)
                    {
                        if (reverseTimer != null)
                        {
                            reverseTimer.pause = true;
                        }
                        gameOver = true;
                        gameScore.pause = true;
                        gamemenu.gameOver = true;
                        gamemenu.Visible = true;
                    }
                }
                //modify engine pitch, from -1.0f to 1.0f

            }
            //codice per la gestione del countdown
            else if (start)
            {
                //faccio partire il brano di sottofondo
                //songInstance.Volume = 0.75f;
                //songInstance.IsLooped = false;
                //songInstance.Play();

                if (countDown == null)
                {
                    countDown = new timeSprite(Game, 3000f, new Vector2(465, 220), timeFont, Color.DarkRed, false, 0);
                    Game.Components.Add(countDown);
                }
                else if (countDown.timeOver)
                {
                    songInstance.Volume = 0.2f;
                    songInstance.IsLooped = true;
                    songInstance.Play();
                    countDown.Dispose();
                    start = false;
                    gameScore = new timeSprite(Game, 0f, new Vector2(20, 20), timeFont, Color.White, true, 3);
                    Game.Components.Add(gameScore);
                }
            }

            else if (pause)
            {
                if (KeyboardState.IsKeyDown(Keys.Enter) && !prevStateEnterKey)
                {
                    if (gamemenu.selection == 0)
                    {
                        pause = false;
                        gamemenu.pause = false;
                        gamemenu.Visible = false;
                    }
                    else if (gamemenu.selection == 1)
                    {
                        gamemenu.selection = 0;
                        gamemenu.Visible = false;
                        Reset();
                        nextLevel();
                    }
                    else if (gamemenu.selection == 2)
                    {
                        goToMenu();
                    }
                }
                if (KeyboardState.IsKeyDown(Keys.Down) && keyTimer > 500)
                {
                    if (gamemenu.selection < 2)
                        gamemenu.selection++;
                    else
                        gamemenu.selection = 0;
                    keyTimer = 0;
                }
                if (KeyboardState.IsKeyDown(Keys.Up) && keyTimer > 500)
                {
                    if (gamemenu.selection > 0)
                        gamemenu.selection--;
                    else
                        gamemenu.selection = 2;
                    keyTimer = 0;
                }
                keyTimer += gameTime.ElapsedGameTime.Milliseconds;
            }

            else if (gameOver)
            {
                space.Update();
                if(KeyboardState.IsKeyDown(Keys.Enter) && !prevStateEnterKey)
                {
                    if (gamemenu.selection == 0)
                    {
                        Reset();
                        nextLevel();
                        gamemenu.Visible = false;
                        gamemenu.selection = 0;
                    }
                    else
                    {
                        if (successful)
                            goToSaveScore();
                        else
                            goToMenu();
                    }
                }
                if ((KeyboardState.IsKeyDown(Keys.Up) || KeyboardState.IsKeyDown(Keys.Down)) && keyTimer > 500)
                {
                    if (gamemenu.selection == 1)
                        gamemenu.selection = 0;
                    else
                        gamemenu.selection = 1;
                    keyTimer = 0;
                }
                keyTimer += gameTime.ElapsedGameTime.Milliseconds;
            }

            prevStatePauseKey = KeyboardState.IsKeyDown(Keys.P);

            base.Update(gameTime);
        }
Example #4
0
 public void Reset()
 {
     successful = false;
     reverse = false;
     start = true;
     pause = false;
     gameOver = false;
     Camera = null;
     Game.Components.Remove(gameScore);
     Game.Components.Remove(countDown);
     countDown = null;
     Game.Components.Remove(bobEntity);
     space.Remove(stageMesh);
     Game.Components.Remove(stageMod);
     space.Remove(bobBox);
     Game.Components.Remove(bgMod);
     Game.Components.Remove(gamemenu);
     songInstance.Stop();
     if (engineInstance.State == SoundState.Playing)
     {
         engineInstance.Stop();
     }
     if (hyperspaceInsance.State == SoundState.Playing)
         hyperspaceInsance.Stop();
     Initialize();
 }