예제 #1
0
        protected override void Update(GameTime gameTime)
        {
            if (MasterMode != Program.MasterMaze.State)
            {
                MasterMode = Program.MasterMaze.State;
            }

            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
            {
                this.Exit();
            }

            #region Free Camera

            KeyboardState keyState   = Keyboard.GetState();
            MouseState    mouseState = Mouse.GetState();

            if (keyState.IsKeyDown(Keys.Space))
            {
                // Determine how much the camera should turn
                float deltaX = (float)lastMouseState.X - (float)mouseState.X;
                float deltaY = (float)lastMouseState.Y - (float)mouseState.Y;

                // Rotate the camera
                MovableCamera.Rotate(deltaX * .005f, deltaY * .005f);
            }

            Vector3 translation = Vector3.Zero;

            // Determine in which direction to move the camera
            if (keyState.IsKeyDown(Keys.W))
            {
                translation += Vector3.Forward;
            }
            if (keyState.IsKeyDown(Keys.S))
            {
                translation += Vector3.Backward;
            }
            if (keyState.IsKeyDown(Keys.A))
            {
                translation += Vector3.Left;
            }
            if (keyState.IsKeyDown(Keys.D))
            {
                translation += Vector3.Right;
            }
            if (keyState.IsKeyDown(Keys.F12))
            {
                this.Exit();
            }

            // Move 4 units per millisecond, independent of frame rate
            translation *= (float)(0.5 * gameTime.ElapsedGameTime.TotalMilliseconds) * (Keyboard.GetState().IsKeyDown(Keys.LeftControl) ? 2.5f : 1f) * (Keyboard.GetState().IsKeyDown(Keys.LeftShift) ? 10f : 1f);

            // Move the camera
            MovableCamera.Move(translation);
            MovableCamera.Update();

            lastMouseState = mouseState;

            #endregion

            #region Maze Stuff
            switch (MasterMode)
            {
            case "Generate":

                ReRender--;

                if (ID == 0)
                {
                    Program.MasterMaze.GenerateNext(ReRender < 0 ? true : false);
                }

                else
                {
                    WallVerticesBuffer = new VertexBuffer(GraphicsDevice, typeof(VertexPositionColor), Program.MasterMaze.WallVertices.Length, BufferUsage.WriteOnly);
                    WallIndicesBuffer  = new IndexBuffer(GraphicsDevice, IndexElementSize.ThirtyTwoBits, Program.MasterMaze.WallIndices.Length, BufferUsage.WriteOnly);

                    WallVerticesBuffer.SetData <VertexPositionColor>(Program.MasterMaze.WallVertices);
                    WallIndicesBuffer.SetData <int>(Program.MasterMaze.WallIndices);
                }

                if (ReRender < 0)
                {
                    ReRender += Stagger;
                }

                break;

            case "Ready":

                #region Maze Stuff

                if (SelfMode == "Ready")
                {
                }

                #region Transition
                else if (SelfMode == "Transition")
                {
                    if (SmallTimer > 0)
                    {
                        if (ID == 0)
                        {
                            MovableCamera = new FreeCamera(new Vector3(1375 - (180 - SmallTimer) * 1320 / 180f,
                                                                       3750 - (180 - SmallTimer) * 3695 / 180f,
                                                                       1375 - (180 - SmallTimer) * 1320 / 180f),
                                                           MathHelper.ToRadians(-(180 - SmallTimer)),
                                                           MathHelper.ToRadians(-90 + (180 - SmallTimer) * .5f), GraphicsDevice);
                        }

                        else
                        {
                            MovableCamera = new FreeCamera(new Vector3(1375 - (180 - SmallTimer) * 1320 / 180f,
                                                                       3750 - (180 - SmallTimer) * 3695 / 180f,
                                                                       1375 + (180 - SmallTimer) * 1320 / 180f),
                                                           MathHelper.ToRadians(0),
                                                           MathHelper.ToRadians(-90 + (180 - SmallTimer) * .5f), GraphicsDevice);
                        }

                        MovableCamera.Update();

                        SmallTimer--;
                    }

                    else
                    {
                        SelfMode = "Guess";

                        PathStack = new Stack <Cell>();

                        if (ID == 0)
                        {
                            PathStack.Push(Program.MasterMaze.Cells[0, 0]);
                        }
                        else
                        {
                            PathStack.Push(Program.MasterMaze.Cells[0, (int)Program.MasterMaze.Dimensions.Y - 1]);
                        }

                        Current = PathStack.Peek();

                        CurrentDirection = ID == 0 ? "Down" : "Up";
                        MovableCamera    = new FreeCamera(new Vector3(Current.Location.X * 110 + 55, 55, Current.Location.Y * 110 + 55), MovableCamera.Yaw, 0, GraphicsDevice);
                    }
                }
                #endregion

                #region Guess
                else if (SelfMode == "Guess")
                {
                    Next = Program.MasterMaze.Guess(PathStack, ID, Next);

                    Vector3 Difference = new Vector3(Current.Location.X * 110 + 55, 55, Current.Location.Y * 110 + 55) - MovableCamera.Position;

                    ShouldMove = new Vector2(Difference.X + 110, Difference.Z + 110);
                    HasMoved   = new Vector2(110) - ShouldMove;
                    Start      = MovableCamera.Position;
                    Start.Y    = 55;

                    RotateBy = NeedsRotate();

                    if (RotateBy == 0)
                    {
                        //No rotation needed go to moving immediately
                        SelfMode   = "Move";
                        SmallTimer = 0;
                    }

                    else
                    {
                        SelfMode   = "Rotate";
                        SmallTimer = Math.Abs(RotateBy / 90) * 30;

                        if (RotateBy > 90)
                        {
                        }
                    }
                }
                #endregion

                #region Move and Rotate
                else if (SelfMode == "Move")
                {
                    if (HasMoved.X < 110 && HasMoved.Y < 110)
                    {
                        MovableCamera.Position += (new Vector3(Next.Location.X * 110 + 55, 55, Next.Location.Y * 110 + 55) - Start) / 30f;
                        HasMoved += new Vector2(Math.Abs(Vector3.Forward.X * 110 / 30f), Math.Abs(Vector3.Forward.Z * 110 / 30f));
                    }

                    else
                    {
                        SelfMode = "Guess";
                        Current  = Next;
                    }
                }

                else if (SelfMode == "Rotate")
                {
                    if (SmallTimer > 0)
                    {
                        MovableCamera.Rotate(MathHelper.ToRadians(RotateBy) / (Math.Abs(RotateBy / 90) * 30), 0);
                        SmallTimer--;
                    }

                    else
                    {
                        SelfMode   = "Move";
                        SmallTimer = 0;
                        SetDirection();
                    }
                }
                #endregion

                else
                {
                    SmallTimer = 180;
                    SelfMode   = "Transition";
                }

                #endregion

                #region Overview

                if (Delay <= 0)
                {
                    if (CameraState == "Waiting")
                    {
                        CameraState = "Up";
                        Delay       = 60;
                    }

                    else if (CameraState == "Up")
                    {
                        CameraState = "Observe";
                        Delay       = 600;
                    }

                    else if (CameraState == "Observe")
                    {
                        CameraState = "Down";
                        Delay       = 60;
                    }

                    else if (CameraState == "Down")
                    {
                        CameraState = "Waiting";
                        Delay       = Program.Rand.Next(1500, 3000);
                    }
                }

                else
                {
                    if (CameraState == "Up")
                    {
                        MovableCamera.Rotate(0, -MathHelper.ToRadians(90) / 60);
                        MovableCamera.Position += new Vector3(0, 500 / 60, 0);
                    }

                    else if (CameraState == "Down")
                    {
                        MovableCamera.Rotate(0, MathHelper.ToRadians(90) / 60);
                        MovableCamera.Position -= new Vector3(0, 500 / 60, 0);
                    }

                    Delay--;
                }

                #endregion

                break;
            }

            #endregion

            base.Update(gameTime);
        }
예제 #2
0
        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
            {
                this.Exit();
            }

            KeyboardState keyState    = Keyboard.GetState();
            Vector3       translation = Vector3.Zero;

            // Determine in which direction to move the camera
            if (keyState.IsKeyDown(Keys.W))
            {
                translation += Vector3.Up;
            }
            if (keyState.IsKeyDown(Keys.S))
            {
                translation += Vector3.Down;
            }
            if (keyState.IsKeyDown(Keys.A))
            {
                translation += Vector3.Left;
            }
            if (keyState.IsKeyDown(Keys.D))
            {
                translation += Vector3.Right;
            }
            if (keyState.IsKeyDown(Keys.F12))
            {
                this.Exit();
            }

            // Move 4 units per millisecond, independent of frame rate
            translation *= (float)(0.5 * gameTime.ElapsedGameTime.TotalMilliseconds);

            // Move the camera
            MovableCamera.Move(translation);
            MovableCamera.Update();

            Time++;

            if (Time > TransitionInTime)
            {
                if (TransitionIn)
                {
                    TransitionIn = false;
                    Time         = 0;

                    if (Mode == "Pan")
                    {
                        TransitionInTime -= 480;
                    }
                    else if (Mode == "Fade")
                    {
                        TransitionInTime = TransitionOutTime;
                    }
                    else
                    {
                        TransitionInTime = TransitionOutTime;
                    }
                }

                else
                {
                    ImageIndex++;

                    if (ImageIndex >= Images.Count)
                    {
                        ImageIndex = 0;
                    }

                    Mode = RandomMode();
                    GeneratePrimatives(Program.Rand.Next(10, 25), Images[ImageIndex]);
                    Time         = 0;
                    TransitionIn = true;
                }
            }

            base.Update(gameTime);
        }