Exemplo n.º 1
0
        protected override void Update(GameTime gameTime)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }

            x += -1 * Utility.UserInput.getXAxis();
            y += -1 * Utility.UserInput.getYAxis();

            transform = Matrix.CreateTranslation(x, y, 0);

            var MouseX = Mouse.GetState().X;
            var MouseY = Mouse.GetState().Y;

            var mousePosition = new Vector2(MouseX, MouseY);

            cursor.Update(Mouse.GetState().Position.ToVector2());


            Console.WriteLine(paused);


            if (delay < gameTime.TotalGameTime.TotalSeconds)
            {
                if (Keyboard.GetState().IsKeyDown(Keys.Back))
                {
                    if (paused)
                    {
                        paused = false;
                    }
                    else
                    {
                        paused = true;
                    }

                    delay = gameTime.TotalGameTime.TotalSeconds + .25;
                }

                Console.WriteLine(paused);

                if (!paused)
                {
                    if (Keyboard.GetState().IsKeyDown(Keys.LeftShift))
                    {
                        expansionSpeed = 5;
                    }
                    if (Keyboard.GetState().IsKeyUp(Keys.LeftShift))
                    {
                        expansionSpeed = 1;
                    }
                    if (Keyboard.GetState().IsKeyDown(Keys.W))
                    {
                        var width   = cursor._Texture.Width + (1 * expansionSpeed);
                        var height  = cursor._Texture.Height;
                        var texture = TextureGen.CreateTexture(width, height, cursor._Color);
                        cursor.Update(texture);
                    }
                    if (Keyboard.GetState().IsKeyDown(Keys.Q))
                    {
                        Console.WriteLine(cursor._Texture.Width);
                        if (cursor._Texture.Width > 5)
                        {
                            var width   = cursor._Texture.Width - (1 * expansionSpeed);
                            var height  = cursor._Texture.Height;
                            var texture = TextureGen.CreateTexture(width, height, cursor._Color);
                            cursor.Update(texture);
                        }
                    }
                    if (Keyboard.GetState().IsKeyDown(Keys.P))
                    {
                        var width   = cursor._Texture.Width;
                        var height  = cursor._Texture.Height + (1 * expansionSpeed);
                        var texture = TextureGen.CreateTexture(width, height, cursor._Color);
                        cursor.Update(texture);
                    }
                    if (Keyboard.GetState().IsKeyDown(Keys.O))
                    {
                        if (cursor._Texture.Height > 5)
                        {
                            var width   = cursor._Texture.Width;
                            var height  = cursor._Texture.Height - (1 * expansionSpeed);
                            var texture = TextureGen.CreateTexture(width, height, cursor._Color);
                            cursor.Update(texture);
                        }
                    }


                    if (Mouse.GetState().LeftButton == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Enter))
                    {
                        level.AddTile(cursor);
                        delay = gameTime.TotalGameTime.TotalSeconds + .25;
                    }

                    if (Mouse.GetState().RightButton == ButtonState.Pressed)
                    {
                        List <Tile> Delete = new List <Tile>();
                        foreach (var block in level.GetList())
                        {
                            if (cursor._Rectangle.Intersects(block._Rectangle))
                            {
                                Delete.Add(block);
                            }
                        }
                        foreach (var block in Delete)
                        {
                            level.Delete(block);
                        }
                        Delete.Clear();

                        delay = gameTime.TotalGameTime.TotalSeconds + .25;
                    }

                    if (Keyboard.GetState().IsKeyDown(Keys.T))
                    {
                        if (tCount <= 0)
                        {
                            tCount = Tiles.Length - 1;
                        }
                        else
                        {
                            tCount--;
                        }

                        cursor = Tiles[tCount];

                        delay = gameTime.TotalGameTime.TotalSeconds + .25;
                    }

                    if (Keyboard.GetState().IsKeyDown(Keys.L))
                    {
                        System.Windows.Forms.OpenFileDialog oDialogue = new System.Windows.Forms.OpenFileDialog();

                        oDialogue.Filter           = "Data Files (*.dat) | *.dat ";
                        oDialogue.RestoreDirectory = true;

                        if (oDialogue.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                        {
                            var stream = oDialogue.OpenFile();
                            var data   = SerializerUtility.DataManagementXML.Load(stream);

                            if (data.Count > 0)
                            {
                                level = LevelGenerator.GenerateLevel(data[0], GraphicsDevice);
                            }
                        }
                    }

                    if (Keyboard.GetState().IsKeyDown(Keys.S))
                    {
                        System.Windows.Forms.SaveFileDialog sDialogue = new System.Windows.Forms.SaveFileDialog();

                        sDialogue.Filter           = "Data Files (*.dat) | *.dat ";
                        sDialogue.RestoreDirectory = true;

                        if (sDialogue.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                        {
                            var fileStream = sDialogue.OpenFile();
                            SerializerUtility.DataManagementXML.Save(fileStream, level.GenerateBlueprint());
                        }
                    }

                    if (Keyboard.GetState().IsKeyDown(Keys.Delete))
                    {
                        level.Delete();
                    }
                }
            }


            base.Update(gameTime);
        }