示例#1
0
        public Cell(Vector2 Location)
        {
            this.Location = Location;

            LeftWall = true;
            RightWall = true;
            TopWall = true;
            BottomWall = true;

            VisitedBy0 = false;
            VisitedBy1 = false;
            VisitedBy2 = false;
            VisitedBy3 = false;

            Previous0 = null;
            Previous1 = null;
            Previous2 = null;
            Previous3 = null;

            LeftColor = new Color(Program.Rand.Next(50, 255), 0, 0);
            RightColor = new Color(0, 0, Program.Rand.Next(50, 255));
            TopColor = new Color(0, Program.Rand.Next(50, 255), 0);

            int Yellow = Program.Rand.Next(50, 255);

            BottomColor = new Color(Yellow, Yellow, 0);
        }
示例#2
0
        protected override void Update(GameTime gameTime)
        {
            if (MasterMode != Program.MasterMaze.State)
            {

                MasterMode = Program.MasterMaze.State;

            }

            if (Program.MasterMaze.State.Contains("Win"))
            {

                if (ID == 0)
                {

                    Program.MasterMaze.State = "Generate";

                }

                else
                {

                    Thread.Sleep(1000);

                }

            }

            // 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(VertexPositionColorTexture), Program.MasterMaze.WallVertices.Length, BufferUsage.WriteOnly);
                        WallIndicesBuffer = new IndexBuffer(GraphicsDevice, IndexElementSize.ThirtyTwoBits, Program.MasterMaze.WallIndices.Length, BufferUsage.WriteOnly);

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

                        if (DoOnce)
                        {

                            DoOnce = false;

                            Vertices = new VertexPositionNormalTexture[Program.MasterMaze.Vertices.Length];
                            Indices = new int[Program.MasterMaze.Indices.Length];

                            Vertices = (VertexPositionNormalTexture[])Program.MasterMaze.Vertices.Clone();
                            Indices = (int[])Program.MasterMaze.Indices.Clone();

                            VerticesBuffer = new VertexBuffer(GraphicsDevice, typeof(VertexPositionNormalTexture), Vertices.Length, BufferUsage.WriteOnly);
                            IndicesBuffer = new IndexBuffer(GraphicsDevice, IndexElementSize.ThirtyTwoBits, Indices.Length, BufferUsage.WriteOnly);

                            VerticesBuffer.SetData<VertexPositionNormalTexture>(Vertices);
                            IndicesBuffer.SetData<int>(Indices);

                        }

                    }

                    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);
        }
示例#3
0
        public void SetPrevious(int Index, Cell Previous)
        {
            switch (Index)
            {

                case 0:
                    Previous0 = Previous; break;
                case 1:
                    Previous1 = Previous; break;
                case 2:
                    Previous2 = Previous; break;
                case 3:
                    Previous3 = Previous; break;
                default:
                    Previous0 = Previous; break;

            }
        }