Exemple #1
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, 0.5f);
                }
                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, 0.5f);
                }
                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 (ExitBox.Contains(ball.position) == ContainmentType.Contains || currentKeyboardState.IsKeyDown(Keys.P))
            {
                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);
        }
Exemple #2
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>
        protected override void Update(GameTime gameTime)
        {
            timeInMillis += gameTime.ElapsedGameTime.Milliseconds;

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

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

            // Exit when the Escape key or Back button is pressed
            if (currentKeyboardState.IsKeyDown(Keys.Escape) ||
                currentGamePadState.Buttons.Back == ButtonState.Pressed)
            {
                Exit();
            }

            if (currentKeyboardState.IsKeyDown(Keys.Space))
            {
                if (ball.onGround && !ball.jumpDelayTimer.IsRunning)
                {
                    ball.ApplyForce(new Vector3(0, 300, 0));
                    Sound.playSoundOnce("Sound\\jump", Content);
                }
            }

            if (currentKeyboardState.IsKeyDown(Keys.I))
            {
                Vector3 offset = camera.DesiredPositionOffset;
                offset.Y = MathHelper.Clamp(offset.Y += 2, 20, 150);
                camera.DesiredPositionOffset = offset;
                Sound.playSoundOnce("Sound\\rotateCam", Content);
            }
            else if (currentKeyboardState.IsKeyDown(Keys.K))
            {
                Vector3 offset = camera.DesiredPositionOffset;
                offset.Y = MathHelper.Clamp(offset.Y -= 2, 20, 150);
                camera.DesiredPositionOffset = offset;
                Sound.playSoundOnce("Sound\\rotateCam", Content);
            }

            if (currentKeyboardState.IsKeyDown(Keys.Q) && !lastKeyboardState.IsKeyDown(Keys.Q))
            {
                if (ballTexture.Equals(ballTextureBeach))
                {
                    ballTexture = ballTextureMetal;
                }
                else if (ballTexture.Equals(ballTextureMetal))
                {
                    ballTexture = ballTextureBeach;
                }
                Sound.playSoundOnce("Sound\\changeBall", Content);
            }
            else if (currentKeyboardState.IsKeyDown(Keys.E) && !lastKeyboardState.IsKeyDown(Keys.E))
            {
                if (ballTexture.Equals(ballTextureBeach))
                {
                    ballTexture = ballTextureMetal;
                }
                else if (ballTexture.Equals(ballTextureMetal))
                {
                    ballTexture = ballTextureBeach;
                }
                Sound.playSoundOnce("Sound\\changeBall", Content);
            }
            if (currentKeyboardState.IsKeyDown(Keys.N))
            {
                Sound.pauseSound("Sound\\background", Content);
                Sound.playSoundLoop("Sound\\background2", Content);
            }
            if (currentKeyboardState.IsKeyDown(Keys.M))
            {
                Sound.pauseSound("Sound\\background2", Content);
                Sound.playSoundLoop("Sound\\background", Content);
            }

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

            if (currentKeyboardState.IsKeyDown(Keys.R) ||
                currentGamePadState.Buttons.RightStick == ButtonState.Pressed)
            {
                ball.Reset();
                camera.Reset();
            }

            //if (currentKeyboardState.IsKeyDown(Keys.Z))
            //{
            //    IPEndPoint ip = new IPEndPoint(IPAddress.Parse("128.143.69.241"), 9050);
            //    Socket server = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            //    try
            //    {
            //        server.Connect(ip);
            //    }
            //    catch (SocketException e)
            //    {
            //        Console.WriteLine("Unable to connect to server.");
            //        return;
            //    }
            //    server.Send(Encoding.ASCII.GetBytes("HIGHSCORE-INSERT-1-5000"));
            //    byte[] data = new byte[1024];
            //    int receivedDataLength = server.Receive(data);
            //    string stringData = Encoding.ASCII.GetString(data, 0, receivedDataLength);
            //    Console.WriteLine("DATA FROM SERVER: " + stringData);
            //}

            ball.Update(gameTime);
            camera.ChasePosition  = ball.Position;
            camera.ChaseDirection = ball.Direction;
            camera.Up             = ball.Up;
            camera.Reset();
            base.Update(gameTime);
        }