Exemple #1
0
        public void KeyboardInput()
        {
            KeyboardState keyboard = Keyboard.GetState();

            if (keyboard.IsKeyDown(Keys.R) && oldKeyboardState != keyboard)
                getFile.OpenFile();

            if (keyboard.IsKeyDown(Keys.W))
                camera.Zoom += .01f;
            else if (keyboard.IsKeyDown(Keys.S))
                camera.Zoom -= .01f;

            if (mapInputUpdatestate == MapInputUpdateState.noUpdate)
                if (keyboard.IsKeyDown(Keys.Space))
                {
                    MapArrayPlayerInputSizeX = "";
                    MapArrayPlayerInputSizeY = "";
                    mapInputUpdatestate = MapInputUpdateState.isUpdating;
                }
            if (keyboard.IsKeyDown(Keys.Tab) && keyboard != oldKeyboardState && menuState != MenuState.tilePickerMenu)
                menuState = MenuState.tilePickerMenu;
            else if (keyboard.IsKeyDown(Keys.Tab) && keyboard != oldKeyboardState)
                menuState = MenuState.noMenu;

            if (mapInputUpdatestate == MapInputUpdateState.isUpdating)//validate no tiles over 200;
            {
                if (isXInput)
                    MapArrayInputUpdate(ref MapArrayPlayerInputSizeX, keyboard);
                else if (!isXInput)
                    MapArrayInputUpdate(ref MapArrayPlayerInputSizeY, keyboard);

                if (keyboard.IsKeyDown(Keys.Enter) && keyboard != oldKeyboardState)
                {

                    if (isXInput)
                    {
                        if (int.Parse(MapArrayPlayerInputSizeX) > 200)
                        {
                            isXInput = true;
                            MapArrayPlayerInputSizeX = "";
                        }
                        else
                        {
                                isXInput = false;

                        }
                    }
                    else if(!isXInput)
                    {
                        if (int.Parse(MapArrayPlayerInputSizeY) > 200)
                        {
                            isXInput = true;
                            MapArrayPlayerInputSizeY = "";
                        }
                        else
                        {

                            mapInputUpdatestate = MapInputUpdateState.updateMap;
                            isXInput = true;

                        }

                    }

                }
            }

            oldKeyboardState = keyboard;
        }
Exemple #2
0
        protected override void Update(GameTime gameTime)
        {
            _elapsed_time += (float)gameTime.ElapsedGameTime.TotalMilliseconds;
               if(_elapsed_time >1000)
            {
                _elapsed_time = 0;
                _fpsCount = _totalFrames;
                _totalFrames = 0;
            }

            MouseState mouse = Mouse.GetState();
            camera.Update((int)mouse.X, (int)mouse.Y, map.MapWidth, map.MapHeight);

            mousePosX = (int)Math.Round(((decimal)(mouse.X / camera.Zoom) + (camera.xZoomOffset / (decimal)camera.Zoom)));
            mousePosY = (int)Math.Round(((decimal)(mouse.Y / camera.Zoom) + (camera.yZoomOffSet / (decimal)camera.Zoom)));

               // zoomTest();
            KeyboardInput();

            if (menuState == MenuState.noMenu)
            {
                highLightTile = map.highlightTile(mousePosX, mousePosY, test, sizeX, sizeY, spriteBatch);

                if (mouse.LeftButton == ButtonState.Pressed)
                {
                   // if(tileVal !=)
                    map.CheckMap(mousePosX,
                        mousePosY, ref test, sizeX, sizeY, tileVal);//GrassTile: 1-3,StoneTile: 4

                }
                else
                {

                }

                if (mapInputUpdatestate == MapInputUpdateState.updateMap)
                {
                    FillMapArray(int.Parse(MapArrayPlayerInputSizeX), int.Parse(MapArrayPlayerInputSizeY));
                    map.Generate(test, sizeX, sizeY,true);

                    mapInputUpdatestate = MapInputUpdateState.noUpdate;

                }
            }

            if (menuState == MenuState.tilePickerMenu)
                if (mouse.LeftButton == ButtonState.Pressed)
                {
                    int hold;
                    hold = tilePicker.TileSelector(new Vector2(mouse.X, mouse.Y));//screenWidth, screenHeight

                    if (hold >= 0)
                        tileVal = hold;
                    else if (hold == -2)
                        tilePicker.AddTile(GraphicsDevice);
                }
                else
                    tilePicker.TileSelectorHighlighter(new Vector2(mouse.X, mouse.Y));

            base.Update(gameTime);
        }