Esempio n. 1
0
        /// <summary>
        /// updates the won state
        /// </summary>
        /// <param name="gameTime"></param>
        /// <returns>true if won should be closed</returns>
        public bool update(ownGameTime gameTime)
        {
            //zwei sekunden kann man nichts machen dann kann man mit enter oder a weiter
            //update the InfoText
            elapsedTime += gameTime.getElapsedGameTime();
            if (elapsedTime > 1000)
            {
                infoText.updateText("02");
                infoText.setPosition(new Vector2(Settings.getResolutionX() / 2 - infoText.getWidth() / 2, Settings.getResolutionY() - infoText.getHeight()));
            }
            if (elapsedTime > 2000)
            {
                infoText.updateText("01");
                infoText.setPosition(new Vector2(Settings.getResolutionX() / 2 - infoText.getWidth() / 2, Settings.getResolutionY() - infoText.getHeight()));
            }
            if (elapsedTime > 3000)
            {
                keyboard = Keyboard.GetState();
                gamePad1 = GamePad.GetState(PlayerIndex.One);
                gamePad2 = GamePad.GetState(PlayerIndex.Two);
                gamePad3 = GamePad.GetState(PlayerIndex.Three);
                gamePad4 = GamePad.GetState(PlayerIndex.Four);

                infoText.updateText("Press Enter or A to continue!");
                infoText.setPosition(new Vector2(Settings.getResolutionX() / 2 - infoText.getWidth() / 2, Settings.getResolutionY() - infoText.getHeight()));
                if (keyboard.IsKeyDown(Keys.Enter) || keyboard.IsKeyDown(Keys.Escape) ||gamePad1.IsButtonDown(Buttons.A) || gamePad2.IsButtonDown(Buttons.A) || gamePad3.IsButtonDown(Buttons.A) || gamePad4.IsButtonDown(Buttons.A))
                    return true;
            }
            return false;
        }
Esempio n. 2
0
        /// <summary>
        /// Keyboard Movement
        /// </summary>
        /// <param name="gameTime">GameTime for correct movement dependent on Time not FPS</param>
        private void moveK(ownGameTime gameTime, Keys moveUp, Keys moveDown, Keys moveLeft, Keys moveRight, Keys lookLeft, Keys lookRight)
        {
            Vector3 newPosition = position;
            timeSinceLastMove = gameTime.getElapsedGameTime();
            keyboard = Keyboard.GetState();
            direction = lookAt - position;
            ortoDirection = Vector3.Cross(direction, upDirection);
            bool up = keyboard.IsKeyDown(moveUp) && !keyboard.IsKeyDown(moveDown);
            bool down = keyboard.IsKeyDown(moveDown) && !keyboard.IsKeyDown(moveUp);
            bool left = keyboard.IsKeyDown(moveLeft) && !keyboard.IsKeyDown(moveRight);
            bool right = keyboard.IsKeyDown(moveRight) && !keyboard.IsKeyDown(moveLeft);
            if (isBouncing)
            {
                newPosition += bounceDirection * (timeSinceLastMove / timescale) * bouncingTimeLeft;

                if (/*mapCollision(newPosition) ||*/ bouncingTimeLeft < 0){
                    isBouncing = false;
                    bouncingTimeLeft = bouncingTime;
                }
                else
                {
                    movementRotationX -= (position - newPosition).X;
                    movementRotationZ += (position - newPosition).Z;

                    if (!this.mapCollision(new Vector3(newPosition.X, position.Y, position.Z)))
                    {
                        position.X = newPosition.X;
                    }

                    if (!this.mapCollision(new Vector3(position.X, position.Y, newPosition.Z)))
                    {
                        position.Z = newPosition.Z;
                    }
                    bouncingTimeLeft -= (timeSinceLastMove / timescale);

                    //movementRotationX -= (position - newPosition).X;

                    //movementRotationZ += (position - newPosition).Z;
                    //position = newPosition;
                    //bouncingTimeLeft -= (timeSinceLastMove / timescale);
                    //Console.WriteLine(bouncingTimeLeft);

                }
            }
            else
            {
                //compute the "new position" for the player after keyboard inputs
                if (up)
                {//forward
                    newPosition = newPosition + direction;// * (timeSinceLastMove / timescale);
                }
                if (down)
                {//backward
                    newPosition = newPosition - direction;// * (timeSinceLastMove / timescale);
                }
                if (right)
                {//right
                    newPosition = newPosition + ortoDirection;// * (timeSinceLastMove / timescale);
                }
                if (left)
                {//left
                    newPosition = newPosition - ortoDirection;// *(timeSinceLastMove / timescale);
                }
            }

            //compute the move Vector and ormalize it
            Vector2 moveVector = new Vector2(newPosition.X - position.X, newPosition.Z - position.Z);//darf nur vector 2 sein, sonst führt die y coordinate beim normalisieren zu problemen

            //normalize the move Vector if needet and add the timeScaling bevore collision
            if (moveVector.Length() > 1)
                moveVector.Normalize();
            moveVector *= (timeSinceLastMove / timescale);

            //Hier nen dicken Player drehen
            //Roll, Roll, Roll A Witch, Twist It At The End. Light It Up And Take A Puff, And Pass It To Your Friends
            //The Witch in the Maze goes round and round, round and round, round and round, the Witch in the Maze goes round and round all throung Game
            if (left)
                movementRotationX -= moveVector.Length();
            if (right)
                movementRotationX += moveVector.Length();
            if (up)
                movementRotationZ -= moveVector.Length();
            if (down)
                movementRotationZ += moveVector.Length();

            //move at the x coordinates and roll the Player
            if (!this.mapCollision(new Vector3(position.X + moveVector.X, position.Y, position.Z)))
            {
                //movementRotationX += moveVector.X;
                position.X += moveVector.X;
                lookAt = position + direction;
            }
            //move at the z coordinates
            if (!this.mapCollision(new Vector3(position.X, position.Y, position.Z + moveVector.Y)))
            {
                //movementRotationZ += moveVector.Y;
                position.Z += moveVector.Y;
                lookAt = position + direction;
            }

            //rotate the player
            if (keyboard.IsKeyDown(lookLeft) && !keyboard.IsKeyDown(lookRight))
            {//rotate left / look left
                Vector3 newLookAt = position + (Vector3.Transform((lookAt - position), Matrix.CreateRotationY(turningScale * timeSinceLastMove / timescale)));

                //inner schön vom player mittelpunkt aus rechnen du pfeife...
                Vector3 playerToLookAt = lookAt - position;
                Vector3 playerToNewLookAt = newLookAt - position;

                //lookatRotation += (float)Math.Acos(Math.Abs(Vector3.Dot(playerToNewLookAt, playerToLookAt)) / (playerToNewLookAt.Length() * playerToLookAt.Length()));
                lookatRotation += (float)Math.Asin(Math.Abs(Vector3.Cross(playerToNewLookAt, playerToLookAt).Length()) / (playerToNewLookAt.Length() * playerToLookAt.Length()));
                lookAt = newLookAt;
            }
            if (keyboard.IsKeyDown(lookRight) && !keyboard.IsKeyDown(lookLeft))
            {//rotate rigth / look right
                Vector3 newLookAt = position + (Vector3.Transform((lookAt - position), Matrix.CreateRotationY(turningScale * (-timeSinceLastMove) / timescale)));

                //inner schön vom player mittelpunkt aus rechnen du pfeife...
                Vector3 playerToLookAt = lookAt - position;
                Vector3 playerToNewLookAt = newLookAt - position;

                //lookatRotation -= (float)Math.Acos(Math.Abs(Vector3.Dot(playerToNewLookAt, playerToLookAt)) / (playerToNewLookAt.Length() * playerToLookAt.Length()));
                lookatRotation -= (float)Math.Asin(Math.Abs(Vector3.Cross(playerToNewLookAt, playerToLookAt).Length()) / (playerToNewLookAt.Length() * playerToLookAt.Length()));
                lookAt = newLookAt;
            }
            //reset if bigger than 2OI or smaller then 0
            while (lookatRotation > 2 * Math.PI)
                lookatRotation %= 2 * Math.PI;
            while (lookatRotation < 0)
                lookatRotation += 2 * Math.PI;

            ////fliegen
            //if (!keyboard.IsKeyDown(Keys.LeftControl) && keyboard.IsKeyDown(Keys.LeftShift))
            //{
            //    position += new Vector3(0,timeSinceLastMove / timescale,0);
            //    lookAt += new Vector3(0, timeSinceLastMove / timescale, 0);
            //}
            //if (keyboard.IsKeyDown(Keys.LeftControl) && !keyboard.IsKeyDown(Keys.LeftShift))
            //{
            //    position -= new Vector3(0, timeSinceLastMove / timescale, 0);
            //    lookAt -= new Vector3(0, timeSinceLastMove / timescale, 0);
            //}
        }
Esempio n. 3
0
        public override EGameState update(ownGameTime gameTime)
        {
            if (GamePad.GetState(PlayerIndex.One).IsConnected)
                gamePad = GamePad.GetState(PlayerIndex.One);
            else if (GamePad.GetState(PlayerIndex.Two).IsConnected)
                gamePad = GamePad.GetState(PlayerIndex.Two);
            else if (GamePad.GetState(PlayerIndex.Three).IsConnected)
                gamePad = GamePad.GetState(PlayerIndex.Three);
            else if (GamePad.GetState(PlayerIndex.Four).IsConnected)
                gamePad = GamePad.GetState(PlayerIndex.Four);

            updatePlayer();
            if (!keyboard.IsKeyDown(Keys.Left) && !keyboard.IsKeyDown(Keys.Right) && !gamePad.IsButtonDown(Buttons.DPadLeft) && !gamePad.IsButtonDown(Buttons.DPadRight) && !gamePad.IsButtonDown(Buttons.A) && !gamePad.IsButtonDown(Buttons.B))
                isPressed = false;

            if ((keyboard.IsKeyDown(Keys.Left) || gamePad.IsButtonDown(Buttons.DPadLeft)) && !isPressed)
            {
                GameModeSelected.switchLeftKlicked();
                isPressed = true;
            }

            if ((keyboard.IsKeyDown(Keys.Right) || gamePad.IsButtonDown(Buttons.DPadRight)) && !isPressed)
            {
                GameModeSelected.switchRightKlicked();
                isPressed = true;
            }

            //start?
            if ((player1Controlls == Player.EPlayerControlls.none || player1Icon.isSelected())
                && (player2Controlls == Player.EPlayerControlls.none || player2Icon.isSelected())
                && (player3Controlls == Player.EPlayerControlls.none || player3Icon.isSelected())
                && (player4Controlls == Player.EPlayerControlls.none || player4Icon.isSelected())
                && !(player1Controlls == Player.EPlayerControlls.none && player2Controlls == Player.EPlayerControlls.none && player3Controlls == Player.EPlayerControlls.none && player4Controlls == Player.EPlayerControlls.none))
                startGame = true;
            else
                startGame = false;

            if (startGame)
            {
                elapsedTime += gameTime.getElapsedGameTime();
                if (elapsedTime > 1000)
                {
                    infoText.updateText("Game starts in 02!");
                    infoText.setPosition(new Vector2(Settings.getResolutionX() / 2 - infoText.getWidth() / 2, Settings.getResolutionY()/2 - infoText.getHeight()/2));
                }
                if (elapsedTime > 2000)
                {
                    infoText.updateText("Game starts in 01!");
                    infoText.setPosition(new Vector2(Settings.getResolutionX() / 2 - infoText.getWidth() / 2, Settings.getResolutionY() / 2 - infoText.getHeight() / 2));
                }
                if (elapsedTime > 3000)
                {
                    infoText.updateText("Start!");
                    infoText.setPosition(new Vector2(Settings.getResolutionX() / 2 - infoText.getWidth() / 2, Settings.getResolutionY() / 2 - infoText.getHeight() / 2));
                }
                if (elapsedTime > 3200)
                {
                    return EGameState.InGame; // GameState InGame braucht übergabeparameter!
                }
            }
            else
            {
                elapsedTime = 0;
                infoText.updateText("Game starts in 03!");
                infoText.setPosition(new Vector2(Settings.getResolutionX() / 2 - infoText.getWidth() / 2, Settings.getResolutionY() / 2 - infoText.getHeight() / 2));
            }
            //set selected GameMode
            switch (GameModeSelected.getDisplayedIndex())
            {
                case 0:
                    this.eInGameState = EInGameState.NeedForIngrediance;
                    break;
                case 1:
                    this.eInGameState = EInGameState.RushHour;
                    break;
                default:
                    throw new NotImplementedException();
            }

            //if(keyboard.IsKeyDown(Keys.Space))
            //    return EGameState.InGame; // GameState InGame braucht übergabeparameter!
            if (keyboard.IsKeyDown(Keys.Escape) /*|| gamePad.IsButtonDown(Buttons.B)*/ || gamePad.IsButtonDown(Buttons.Back))
                return EGameState.MainMenu;
            else
                return EGameState.CharacterSelection;
        }
Esempio n. 4
0
        //GamePad
        private void moveG(ownGameTime gameTime, PlayerIndex playerIndex)
        {
            // Get the current gamepad state.
                GamePadState currentState = GamePad.GetState(playerIndex);

                Vector3 newPosition = position;
                timeSinceLastMove = gameTime.getElapsedGameTime();
                keyboard = Keyboard.GetState();
                direction = lookAt - position;
                ortoDirection = Vector3.Cross(direction, upDirection);
                bool up = currentState.ThumbSticks.Left.Y > 0.1f;
                bool down = currentState.ThumbSticks.Left.Y < -0.1f;
                bool left = currentState.ThumbSticks.Left.X < -0.1f;
                bool right = currentState.ThumbSticks.Left.X > 0.0f;
                bool lookLeft = currentState.ThumbSticks.Right.X < -0.1f;
                bool lookRight = currentState.ThumbSticks.Right.X > 0.1f;
                float leftMoveScale = 1;
                float rightMoveScale = 1;
                if (isBouncing)
                {
                    newPosition += bounceDirection * (timeSinceLastMove / timescale) * bouncingTimeLeft;

                    if (/*mapCollision(newPosition) ||*/ bouncingTimeLeft < 0)
                    {
                        isBouncing = false;
                        bouncingTimeLeft = bouncingTime;
                    }
                    else
                    {
                        movementRotationX -= (position - newPosition).X;
                        movementRotationZ += (position - newPosition).Z;

                        if (!this.mapCollision(new Vector3(newPosition.X, position.Y, position.Z)))
                        {
                            position.X = newPosition.X;
                        }

                        if (!this.mapCollision(new Vector3(position.X, position.Y, newPosition.Z)))
                        {
                            position.Z = newPosition.Z;
                        }
                        bouncingTimeLeft -= (timeSinceLastMove / timescale);

                    }
                }
                else
                {
                    //compute the "new position" for the player after keyboard inputs
                    if (up)
                    {//forward
                        newPosition = newPosition + direction;
                        leftMoveScale = Math.Abs(currentState.ThumbSticks.Left.Y);
                    }
                    if (down)
                    {//backward
                        newPosition = newPosition - direction;
                        leftMoveScale = Math.Abs(currentState.ThumbSticks.Left.Y);
                    }
                    if (right)
                    {//right
                        newPosition = newPosition + ortoDirection;
                        rightMoveScale = Math.Abs(currentState.ThumbSticks.Left.X);
                    }
                    if (left)
                    {//left
                        newPosition = newPosition - ortoDirection;
                        rightMoveScale = Math.Abs(currentState.ThumbSticks.Left.X);
                    }
                }

                //compute the move Vector and ormalize it
                Vector2 moveVector = new Vector2(newPosition.X - position.X, newPosition.Z - position.Z);//darf nur vector 2 sein, sonst führt die y coordinate beim normalisieren zu problemen

                //normalize the move Vector if needet and add the timeScaling bevore collision
                Console.WriteLine(moveVector);
                if (moveVector.Length() > 1)
                    moveVector.Normalize();
                float h = (leftMoveScale + rightMoveScale);//h scales the movescale back if its too high
                if(h > 1)
                    h = 1;
                moveVector *= (timeSinceLastMove / timescale) * h;
                    //moveVector.Y  *= Math.Abs(currentState.ThumbSticks.Left.Y);
                    //moveVector.X *= Math.Abs(currentState.ThumbSticks.Left.X);

                //Hier nen dicken Player drehen
                //Roll, Roll, Roll A Witch, Twist It At The End. Light It Up And Take A Puff, And Pass It To Your Friends
                //The Witch in the Maze goes round and round, round and round, round and round, the Witch in the Maze goes round and round all throung Game
                if (left)
                    movementRotationX -= moveVector.Length();
                if (right)
                    movementRotationX += moveVector.Length();
                if (up)
                    movementRotationZ -= moveVector.Length();
                if (down)
                    movementRotationZ += moveVector.Length();

                //move at the x coordinates and roll the Player
                if (!this.mapCollision(new Vector3(position.X + moveVector.X, position.Y, position.Z)))
                {
                    //movementRotationX += moveVector.X;
                    position.X += moveVector.X;
                    lookAt = position + direction;
                }
                //move at the z coordinates
                if (!this.mapCollision(new Vector3(position.X, position.Y, position.Z + moveVector.Y)))
                {
                    //movementRotationZ += moveVector.Y;
                    position.Z += moveVector.Y;
                    lookAt = position + direction;
                }

                //rotate the player
                if (lookLeft)
                {//rotate left / look left
                    Vector3 newLookAt = position + (Vector3.Transform((lookAt - position), Matrix.CreateRotationY(turningScale * timeSinceLastMove / timescale)));
                    Vector3 moveLookAt = newLookAt - lookAt;//to scale toth the controller
                    moveLookAt *= Math.Abs(currentState.ThumbSticks.Right.X);
                    newLookAt = lookAt + moveLookAt;
                    //inner schön vom player mittelpunkt aus rechnen du pfeife...
                    Vector3 playerToLookAt = lookAt - position;
                    Vector3 playerToNewLookAt = newLookAt - position;

                    //lookatRotation += (float)Math.Acos(Math.Abs(Vector3.Dot(playerToNewLookAt, playerToLookAt)) / (playerToNewLookAt.Length() * playerToLookAt.Length()));
                    lookatRotation += (float)Math.Asin(Math.Abs(Vector3.Cross(playerToNewLookAt, playerToLookAt).Length()) / (playerToNewLookAt.Length() * playerToLookAt.Length()));
                    lookAt = newLookAt;
                }
                if (lookRight)
                {//rotate rigth / look right
                    Vector3 newLookAt = position + (Vector3.Transform((lookAt - position), Matrix.CreateRotationY(turningScale * (-timeSinceLastMove) / timescale)));
                    Vector3 moveLookAt = newLookAt - lookAt;//to scale toth the controller
                    moveLookAt *= Math.Abs(currentState.ThumbSticks.Right.X);
                    newLookAt = lookAt + moveLookAt;
                    //inner schön vom player mittelpunkt aus rechnen du pfeife...
                    Vector3 playerToLookAt = lookAt - position;
                    Vector3 playerToNewLookAt = newLookAt - position;

                    //lookatRotation -= (float)Math.Acos(Math.Abs(Vector3.Dot(playerToNewLookAt, playerToLookAt)) / (playerToNewLookAt.Length() * playerToLookAt.Length()));
                    lookatRotation -= (float)Math.Asin(Math.Abs(Vector3.Cross(playerToNewLookAt, playerToLookAt).Length()) / (playerToNewLookAt.Length() * playerToLookAt.Length()));
                    lookAt = newLookAt;
                }
                //reset if bigger than 2OI or smaller then 0
                while (lookatRotation > 2 * Math.PI)
                    lookatRotation %= 2 * Math.PI;
                while (lookatRotation < 0)
                    lookatRotation += 2 * Math.PI;
        }
Esempio n. 5
0
        public void update(ownGameTime gameTime)
        {
            //check if clock is started jet
            if (!running)
                return;
            else
            {
                elapsedTime += gameTime.getElapsedGameTime();
                int hseconds = (int)(elapsedTime / 1000) % 60;
                int hminutes = ((int)(elapsedTime / 1000) - hseconds) / 60;

                if (hseconds < 10)
                    seconds.updateText("0" + hseconds.ToString());
                else
                    seconds.updateText(hseconds.ToString());
                if (hminutes < 10)
                    minutes.updateText("0" + hminutes.ToString());
                else
                    minutes.updateText(hminutes.ToString());
            }
        }