Exemplo n.º 1
0
        override public void Update(GameTime time)
        {
            oldKeyboardState     = currentKeyboardState;
            currentKeyboardState = Keyboard.GetState();

            XboxoldState     = XboxcurrentState;
            XboxcurrentState = GamePad.GetState(PlayerIndex.One);

            Keys[] pressedKeys;
            pressedKeys = currentKeyboardState.GetPressedKeys();

            if (XboxcurrentState.IsButtonDown(Buttons.A) && !XboxoldState.IsButtonDown(Buttons.A))
            {
                Sound.pauseSound("Sound\\menu", content);
                GamePlayScreen level = new GamePlayScreen();
                level.Level          = this.level;
                level.Terrain        = "Models\\" + this.level;
                level.TerrainTexture = "Textures\\" + this.level;
                level.Background     = "Sound\\" + this.level;
                level.Name           = textString;
                ScreenManager.AddScreen(level);
                ScreenManager.RemoveScreen(this);
            }

            foreach (Keys key in pressedKeys)
            {
                if (oldKeyboardState.IsKeyUp(key))
                {
                    if (key == Keys.Back)
                    { // overflows
                        if (textString.Length > 0)
                        {
                            textString = textString.Remove(textString.Length - 1, 1);
                        }
                    }
                    else
                    {
                        if (key == Keys.Enter || key == Keys.Space)
                        {
                            Sound.pauseSound("Sound\\menu", content);
                            GamePlayScreen level = new GamePlayScreen();
                            level.Level          = this.level;
                            level.Terrain        = "Models\\" + this.level;
                            level.TerrainTexture = "Textures\\" + this.level;
                            level.Background     = "Sound\\" + this.level;
                            level.Name           = textString;
                            ScreenManager.AddScreen(level);
                            ScreenManager.RemoveScreen(this);
                        }
                        else if (textString.Length > 5)
                        {
                            return;
                        }
                        else if (key == Keys.Space)
                        {
                            textString += " ";
                        }
                        else if (AllowedKeys.Contains(key.ToString()))
                        {
                            textString += key.ToString();
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        override public void Update(GameTime time)
        {
            if (goUp)
            {
                MenuScale[Selected] += .005f;
            }
            else
            {
                MenuScale[Selected] -= .005f;
            }
            if (MenuScale[Selected] > 0.6 || MenuScale[Selected] < 0.5)
            {
                goUp = !goUp;
            }

            oldState         = currentState;
            XboxoldState     = XboxcurrentState;
            XboxcurrentState = GamePad.GetState(PlayerIndex.One);
            currentState     = Keyboard.GetState();

            if ((currentState.IsKeyDown(Keys.W) && !oldState.IsKeyDown(Keys.W)) || (currentState.IsKeyDown(Keys.Up) && !oldState.IsKeyDown(Keys.Up)) || (XboxcurrentState.DPad.Up == ButtonState.Pressed && XboxoldState.DPad.Up != ButtonState.Pressed))
            {
                Sound.playSoundOnce("Sound\\tap", content);
                MenuScale[Selected] = 0.5f;
                Selected--;
                if (Selected < 0)
                {
                    Selected = 2;
                }
                MenuScale[Selected] = 0.5f;
                goUp = true;
            }
            if ((currentState.IsKeyDown(Keys.S) && !oldState.IsKeyDown(Keys.S)) || (currentState.IsKeyDown(Keys.Down) && !oldState.IsKeyDown(Keys.Down)) || (XboxcurrentState.DPad.Down == ButtonState.Pressed && XboxoldState.DPad.Down != ButtonState.Pressed))
            {
                Sound.playSoundOnce("Sound\\tap", content);
                MenuScale[Selected] = 0.5f;
                Selected++;
                if (Selected > 2)
                {
                    Selected = 0;
                }
                MenuScale[Selected] = 0.5f;
                goUp = true;
            }
            if ((currentState.IsKeyDown(Keys.Space) && !oldState.IsKeyDown(Keys.Space)) || (currentState.IsKeyDown(Keys.Enter) && !oldState.IsKeyDown(Keys.Enter)) || (XboxcurrentState.IsButtonDown(Buttons.A) && !XboxoldState.IsButtonDown(Buttons.A)))
            {
                //Enter was pressed on a menu Item.
                if (Selected == 0)
                {
                    ScreenManager.RemoveAll();
                    GamePlayScreen level = new GamePlayScreen();
                    level.Level          = this.level;
                    level.Terrain        = "Models\\" + this.level;
                    level.TerrainTexture = "Textures\\" + this.level;
                    level.Background     = "Sound\\" + this.level;
                    level.Name           = this.name;
                    ScreenManager.AddScreen(level);
                }
                else if (Selected == 1)
                {
                    ScreenManager.RemoveAll();
                    GamePlayScreen level = new GamePlayScreen();
                    this.level++;
                    if (this.level > 5)
                    {
                        this.level = 1;
                    }
                    level.Level          = this.level;
                    level.Terrain        = "Models\\" + this.level;
                    level.TerrainTexture = "Textures\\" + this.level;
                    level.Background     = "Sound\\" + this.level;
                    level.Name           = this.name;
                    ScreenManager.AddScreen(level);
                }
                else if (Selected == 2)
                {
                    ScreenManager.RemoveAll();
                    ScreenManager.AddScreen(new MainMenu());
                }
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// LoadContent will be called once per game and is the place to load
 /// all of your content.
 /// </summary>
 protected override void LoadContent()
 {
     ScreenManager.AddScreen(new MainMenu());
     spriteBatch = new SpriteBatch(GraphicsDevice);
 }
Exemplo n.º 4
0
        override public void Update(GameTime time)
        {
            if (goUp)
            {
                MenuScale[Selected] += .01f;
            }
            else
            {
                MenuScale[Selected] -= .01f;
            }
            if (MenuScale[Selected] > 1.4 || MenuScale[Selected] < 1)
            {
                goUp = !goUp;
            }

            oldState         = currentState;
            XboxoldState     = XboxcurrentState;
            XboxcurrentState = GamePad.GetState(PlayerIndex.One);
            currentState     = Keyboard.GetState();

            if ((currentState.IsKeyDown(Keys.Up) && !oldState.IsKeyDown(Keys.Up)) || (XboxcurrentState.DPad.Up == ButtonState.Pressed && XboxoldState.DPad.Up != ButtonState.Pressed))
            {
                Sound.playSoundOnce("Sound\\tap", content);
                MenuScale[Selected] = 1;
                Selected--;
                if (Selected < 0)
                {
                    Selected = 2;
                }
                MenuScale[Selected] = 1;
                goUp = true;
            }
            if ((currentState.IsKeyDown(Keys.Down) && !oldState.IsKeyDown(Keys.Down)) || (XboxcurrentState.DPad.Down == ButtonState.Pressed && XboxoldState.DPad.Down != ButtonState.Pressed))
            {
                Sound.playSoundOnce("Sound\\tap", content);
                MenuScale[Selected] = 1;
                Selected++;
                if (Selected > 3)
                {
                    Selected = 0;
                }
                MenuScale[Selected] = 1;
                goUp = true;
            }
            if ((currentState.IsKeyDown(Keys.Enter) && !oldState.IsKeyDown(Keys.Enter)) || (XboxcurrentState.IsButtonDown(Buttons.A) && !XboxoldState.IsButtonDown(Buttons.A)))
            {
                //Enter was pressed on a menu Item.
                if (Selected == 0)
                {
                    Entrance newGame = new Entrance();
                    newGame.Level = 1;
                    ScreenManager.AddScreen(newGame);
                }
                else if (Selected == 1)
                {
                    ScreenManager.AddScreen(new LoadLevelScreen());
                }
                else if (Selected == 2)
                {
                    ScreenManager.AddScreen(new HelpScreen());
                }
                else if (Selected == 3)
                {
                    ScreenManager.RemoveAll();
                }
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        override public void Update(GameTime gameTime)
        {
            timeInMillis += gameTime.ElapsedGameTime.Milliseconds;
            LevelTime    -= gameTime.ElapsedGameTime.Milliseconds;

            if (LevelTime < 0 || ball.position.Y <= pitHeight)
            {
                Sound.pauseSound("Sound\\" + this.level, content);
                GameOver startOver = new GameOver();
                startOver.Level = this.level;
                startOver.Name  = this.name;
                ScreenManager.AddScreen(startOver);
            }

            lastKeyboardState = currentKeyboardState;
            lastGamePadState  = currentGamePadState;
            lastMousState     = currentMouseState;

            currentKeyboardState = Keyboard.GetState();
            currentGamePadState  = GamePad.GetState(PlayerIndex.One);
            currentMouseState    = Mouse.GetState();

            Int32 middleX = device.Viewport.Bounds.Width / 2;
            Int32 middleY = device.Viewport.Bounds.Height / 2;;

#if XBOX
            // Exit when the Escape key or Back button is pressed
            if (currentGamePadState.Buttons.Back == ButtonState.Pressed)
            {
                ScreenManager.RemoveScreen(this);
            }

            if (!ball.onGround && currentGamePadState.IsButtonDown(Buttons.B) && !lastGamePadState.IsButtonDown(Buttons.B))
            {
                ball.dash();
            }
            else if (currentGamePadState.IsButtonDown(Buttons.A) && !lastGamePadState.IsButtonDown(Buttons.A))
            {
                if (ball.onGround && !ball.jumpDelayTimer.IsRunning)
                {
                    //ball.dashDelayTimer.Start();
                    ball.jump();
                }
            }

            if (currentGamePadState.DPad.Down == ButtonState.Pressed)
            {
                Vector3 offset = camera.DesiredPositionOffset;
                offset.Y = MathHelper.Clamp(offset.Y += 2, 20, 150);
                if (Math.Abs(offset.Y - camera.DesiredPositionOffset.Y) > 0.0001)
                {
                    Sound.playSoundOnce("Sound\\rotateCam", content);
                }
                camera.DesiredPositionOffset = offset;
            }
            else if (currentGamePadState.DPad.Up == ButtonState.Pressed)
            {
                Vector3 offset = camera.DesiredPositionOffset;
                offset.Y = MathHelper.Clamp(offset.Y -= 2, 20, 150);
                if (Math.Abs(offset.Y - camera.DesiredPositionOffset.Y) > 0.0001)
                {
                    Sound.playSoundOnce("Sound\\rotateCam", content);
                }
                camera.DesiredPositionOffset = offset;
            }

            if (currentGamePadState.IsButtonDown(Buttons.LeftShoulder) && !lastGamePadState.IsButtonDown(Buttons.LeftShoulder))
            {
                if (currentBallProperties.Equals(beachBallProperties))
                {
                    currentBallProperties = airBallProperties;
                }
                else if (currentBallProperties.Equals(airBallProperties))
                {
                    currentBallProperties = metalBallProperties;
                }
                else if (currentBallProperties.Equals(metalBallProperties))
                {
                    currentBallProperties = beachBallProperties;
                }
                Sound.playSoundOnce(currentBallProperties.ChangeToSound, content);
            }
            else if (currentGamePadState.IsButtonDown(Buttons.RightShoulder) && !lastGamePadState.IsButtonDown(Buttons.RightShoulder))
            {
                if (currentBallProperties.Equals(beachBallProperties))
                {
                    currentBallProperties = metalBallProperties;
                }
                else if (currentBallProperties.Equals(metalBallProperties))
                {
                    currentBallProperties = airBallProperties;
                }
                else if (currentBallProperties.Equals(airBallProperties))
                {
                    currentBallProperties = beachBallProperties;
                }
                Sound.playSoundOnce(currentBallProperties.ChangeToSound, content);
            }

            else if (currentGamePadState.IsButtonDown(Buttons.Back) && !lastGamePadState.IsButtonDown(Buttons.Back))
            {
                Sound.pauseSound(background, content);
                ScreenManager.AddScreen(new MainMenu());
            }

            if (currentGamePadState.IsButtonDown(Buttons.RightStick) && !lastGamePadState.IsButtonDown(Buttons.RightStick))
            {
                ball.Reset();
                camera.Reset();
            }
#endif
#if WINDOWS
            // Exit when the Escape key or Back button is pressed
            if (currentKeyboardState.IsKeyDown(Keys.Escape) ||
                currentGamePadState.Buttons.Back == ButtonState.Pressed)
            {
                ScreenManager.RemoveScreen(this);
            }

            if (!ball.onGround && !lastKeyboardState.IsKeyDown(Keys.Space) && currentKeyboardState.IsKeyDown(Keys.Space))
            {
                ball.dash();
            }
            else if (currentKeyboardState.IsKeyDown(Keys.Space))
            {
                if (ball.onGround && !ball.jumpDelayTimer.IsRunning)
                {
                    //ball.dashDelayTimer.Start();
                    ball.jump();
                }
            }

            if (currentKeyboardState.IsKeyDown(Keys.I) || (currentMouseState.RightButton == ButtonState.Pressed) && (currentMouseState.Y > middleY))
            {
                Vector3 offset = camera.DesiredPositionOffset;
                offset.Y = MathHelper.Clamp(offset.Y += 2, 20, 150);
                if (Math.Abs(offset.Y - camera.DesiredPositionOffset.Y) > 0.0001)
                {
                    Sound.playSoundOnce("Sound\\rotateCam", content);
                }
                camera.DesiredPositionOffset = offset;
            }
            else if (currentKeyboardState.IsKeyDown(Keys.K) || (currentMouseState.RightButton == ButtonState.Pressed) && (currentMouseState.Y <= middleY))
            {
                Vector3 offset = camera.DesiredPositionOffset;
                offset.Y = MathHelper.Clamp(offset.Y -= 2, 20, 150);
                if (Math.Abs(offset.Y - camera.DesiredPositionOffset.Y) > 0.0001)
                {
                    Sound.playSoundOnce("Sound\\rotateCam", content);
                }
                camera.DesiredPositionOffset = offset;
            }

            if (currentKeyboardState.IsKeyDown(Keys.Q) && !lastKeyboardState.IsKeyDown(Keys.Q))
            {
                if (currentBallProperties.Equals(beachBallProperties))
                {
                    currentBallProperties = airBallProperties;
                }
                else if (currentBallProperties.Equals(airBallProperties))
                {
                    currentBallProperties = metalBallProperties;
                }
                else if (currentBallProperties.Equals(metalBallProperties))
                {
                    currentBallProperties = beachBallProperties;
                }
                Sound.playSoundOnce(currentBallProperties.ChangeToSound, content);
            }
            else if (currentKeyboardState.IsKeyDown(Keys.E) && !lastKeyboardState.IsKeyDown(Keys.E))
            {
                if (currentBallProperties.Equals(beachBallProperties))
                {
                    currentBallProperties = metalBallProperties;
                }
                else if (currentBallProperties.Equals(metalBallProperties))
                {
                    currentBallProperties = airBallProperties;
                }
                else if (currentBallProperties.Equals(airBallProperties))
                {
                    currentBallProperties = beachBallProperties;
                }
                Sound.playSoundOnce(currentBallProperties.ChangeToSound, content);
            }

            else if (currentKeyboardState.IsKeyDown(Keys.M))
            {
                Sound.pauseSound(background, content);
                ScreenManager.AddScreen(new MainMenu());
            }

            if (currentKeyboardState.IsKeyDown(Keys.Z))
            {
                System.Diagnostics.Debug.WriteLine(ball.position);
            }

            bool touchTopLeft = currentMouseState.LeftButton == ButtonState.Pressed &&
                                lastMousState.LeftButton != ButtonState.Pressed &&
                                currentMouseState.X < device.Viewport.Width / 10 &&
                                currentMouseState.Y < device.Viewport.Height / 10;

            if (currentKeyboardState.IsKeyDown(Keys.R) ||
                currentGamePadState.Buttons.RightStick == ButtonState.Pressed)
            {
                ball.Reset();
                camera.Reset();
            }
#endif
            ArrowRotation = RotateToFace(ball.position, ExitPosition, Vector3.Up);
            ExitRotation  = RotateToFace(ExitPosition, ball.position, Vector3.Up);

            if (currentKeyboardState.IsKeyDown(Keys.P))
            {
                Sound.playSoundOnce("Sound\\victory", content);

                clearScore(1);
                clearScore(2);
                clearScore(3);
                clearScore(4);
                clearScore(5);
            }

            if (currentKeyboardState.IsKeyDown(Keys.O) || ExitBox.Contains(ball.position) == ContainmentType.Contains)
            {
                long nowTicks = DateTime.Now.Ticks;
#if WINDOWS
                sendScore(name, level, (int)(LevelTime), nowTicks);
#endif
                VictoryScreen victoryScreen = new VictoryScreen();
                victoryScreen.Level = this.level;
                victoryScreen.Name  = this.name;
                victoryScreen.Ticks = nowTicks;
                ScreenManager.AddScreen(victoryScreen);
            }

            //Test stuff
            if (heightMap.IsOnHeightmap(ball.position))
            {
                heightMap.GetHeightAndNormal(ball.position, out h, out norm);
                norm.Normalize();
                h = Vector3.Dot(new Vector3(0, 1, 0), norm);
                a = Math.Acos(h);
                //a = getSignedAngle(new Vector3(0, 1, 0), norm);
                b = Math.Atan2(norm.Y, norm.X);
            }

            for (int x = 0; x < coinList.Count; x++)
            {
                coinList[x].Update(gameTime);
                if (coinList[x].detectIntersection(ball.position))
                {
                    LevelTime += 5000f;
                    Sound.playSoundOnce("Sound\\ding", content);
                    coinList.RemoveAt(x);
                }
            }

            for (int x = 0; x < teleporterList.Count; x++)
            {
                teleporterList[x].Update(gameTime);
                if (teleporterList[x].detectIntersection(ball.position))
                {
                    Sound.playSoundOnce("Sound\\pop", content);
                    ball.position = new Vector3(RandomNumber(-2500, 3000), 0, RandomNumber(-2500, 3000));
                }
            }

            ball.properties = currentBallProperties;
            ball.Update(gameTime);
            camera.ChasePosition  = ball.position;
            camera.ChaseDirection = ball.Direction;
            camera.Up             = ball.Up;
            camera.Reset();

            particleEngine.EmitterLocation = new Vector2(Mouse.GetState().X, Mouse.GetState().Y);
            particleEngine.Update();
            base.Update(gameTime);
        }