Exemplo n.º 1
0
        protected override void Update(GameTime gameTime)
        {
            if (!FormControl.isFormActive(Window))
            {
                return;
            }

            bool updated = false;

            bool allowUpdate = (lastUpdatedTime + 100) < gameTime.TotalGameTime.TotalMilliseconds;


            if (graphics.PreferredBackBufferWidth != Window.ClientBounds.Width || graphics.PreferredBackBufferHeight != Window.ClientBounds.Height)
            {
                graphics.PreferredBackBufferWidth  = Window.ClientBounds.Width;
                graphics.PreferredBackBufferHeight = Window.ClientBounds.Height;
                graphics.ApplyChanges();
            }

            if (Keyboard.GetState().IsKeyDown(Keys.F11))
            {
                graphics.IsFullScreen = !graphics.IsFullScreen;
                graphics.ApplyChanges();
            }

            if (Keyboard.GetState().IsKeyDown(Keys.F3) && allowUpdate)
            {
                showStats = !showStats;
                updated   = true;
            }


            if (updated)
            {
                updated         = false;
                lastUpdatedTime = gameTime.TotalGameTime.TotalMilliseconds;
            }


            float timeDifference = (float)gameTime.ElapsedGameTime.TotalMilliseconds / 1000.0f;

            Camera.ProcessInput(timeDifference);

            base.Update(gameTime);
        }
Exemplo n.º 2
0
        public void Update(GameTime gameTime)
        {
            if (!FormControl.isFormActive(Evolutio.Window))
            {
                return;
            }
            oldPlayerPosition = PlayerPosition;
            var mouseState = Mouse.GetState();

            updateMouseSelection(mouseState.Position);

            if (mouseState.LeftButton == ButtonState.Pressed && oldMouseState.LeftButton == ButtonState.Released)
            {
                var oldSelected = SelectedTile;

                SelectBlock();

                if (_direction == Direction.SOUTH)
                {
                    AcionedItem = GetPlayerPositionIntFloor() + new Vector3(0, 1, 0);
                }
                else if (_direction == Direction.NORTH)
                {
                    AcionedItem = GetPlayerPositionIntFloor() - new Vector3(0, 1, 0);
                }
                else if (_direction == Direction.WEST)
                {
                    AcionedItem = GetPlayerPositionIntFloor() - new Vector3(1, 0, 0);
                }
                else if (_direction == Direction.EAST)
                {
                    AcionedItem = GetPlayerPositionIntFloor() + new Vector3(1, 0, 0);
                }

                if (AcionedItem == SelectedTile)
                {
                    lastTickAction = gameTime.TotalGameTime.Ticks;
                    Tile tile = World.GetTile(AcionedItem);
                    if (tile.Items.Count > 0)
                    {
                        var item       = tile.Items[tile.Items.Count - 1];
                        var durability = item.ApplyDamage(100);
                        if (durability <= 0)
                        {
                            tile.Items.RemoveAt(tile.Items.Count - 1);
                            var pickable = item.Item.CreatePickable();
                            if (pickable != null)
                            {
                                tile.PickableItems.Add(pickable);
                            }
                        }
                    }
                }
                else if (oldSelected.Equals(SelectedTile))
                {
                    // WE SAY TO DEATH: 'NOT TODAY'
                    doingPathFinder = true;
                }

//                if (oldSelected.Equals(SelectedTile))
//                {
//                    World.PlaceGround(Evolutio.ItemRegistry.findItem("ground"), new Vector3(mouseSelection.X, mouseSelection.Y, 0));
//                }
            }

            if (mouseState.RightButton == ButtonState.Pressed && oldMouseState.RightButton == ButtonState.Released)
            {
                var itemStack = Evolutio.BottomMenu.GetSelectecItem();
                if (itemStack != null)
                {
                    World.PlaceItem(itemStack.Item, new Vector3(mouseSelection.X, mouseSelection.Y, 0));
                    itemStack.ChangeQuantity(-1);
                    if (itemStack.Quantity <= 0)
                    {
                        RemoveItem(itemStack);
                    }
                }
            }

            if (oldKeybordState.IsKeyUp(Keys.Space) && Keyboard.GetState().IsKeyDown(Keys.Space))
            {
            }

            oldMouseState = mouseState;

            speed     = 0.1f;
            isWalking = false;
            if (Keyboard.GetState().IsKeyDown(Keys.LeftShift))
            {
                speed = 0.3f;
            }

            bool moved = false;

            var newPlayerPosition           = PlayerPosition;
            var newPlayerPositionWithMargin = PlayerPosition;

            if (doingPathFinder)
            {
                if (Math.Floor(SelectedTile.X) > Math.Floor(PlayerPosition.X))
                {
                    newPlayerPosition += new Vector3(speed, 0, 0);
                    _direction         = Direction.EAST;
                    moved              = true;
                }
                else if (Math.Floor(SelectedTile.X) < Math.Floor(PlayerPosition.X))
                {
                    newPlayerPosition -= new Vector3(speed, 0, 0);
                    _direction         = Direction.WEST;
                    moved              = true;
                }

                if (Math.Floor(SelectedTile.Y) > Math.Floor(PlayerPosition.Y))
                {
                    newPlayerPosition += new Vector3(0, speed, 0);
                    _direction         = Direction.SOUTH;
                    moved              = true;
                }
                else if (Math.Floor(SelectedTile.Y) < Math.Floor(PlayerPosition.Y))
                {
                    newPlayerPosition -= new Vector3(0, speed, 0);
                    _direction         = Direction.NORTH;
                    moved              = true;
                }

                if (Math.Floor(SelectedTile.X) == Math.Floor(PlayerPosition.X) && Math.Floor(SelectedTile.Y) == Math.Floor(PlayerPosition.Y))
                {
                    doingPathFinder = false;
                }

                newPlayerPositionWithMargin = newPlayerPosition;
            }

            if (oldKeybordState.IsKeyUp(Keys.R) && Keyboard.GetState().IsKeyDown(Keys.R))
            {
                World.PlaceGround(Evolutio.ItemRegistry.findItem("ground"), new Vector3(mouseSelection.X, mouseSelection.Y, 0));
            }

            if (Keyboard.GetState().IsKeyDown(Keys.S))
            {
                newPlayerPosition           += new Vector3(0, speed, 0);
                newPlayerPositionWithMargin += new Vector3(0, speed + 0.2f, 0);
                _direction = Direction.SOUTH;
                moved      = true;
            }

            if (Keyboard.GetState().IsKeyDown(Keys.W))
            {
                newPlayerPosition           -= new Vector3(0, speed, 0);
                newPlayerPositionWithMargin -= new Vector3(0, speed + +0.2f, 0);
                _direction = Direction.NORTH;
                moved      = true;
            }

            if (Keyboard.GetState().IsKeyDown(Keys.A))
            {
                newPlayerPosition           -= new Vector3(speed, 0, 0);
                newPlayerPositionWithMargin -= new Vector3(speed + 0.2f, 0, 0);
                _direction = Direction.WEST;
                moved      = true;
            }

            if (Keyboard.GetState().IsKeyDown(Keys.D))
            {
                newPlayerPosition           += new Vector3(speed, 0, 0);
                newPlayerPositionWithMargin += new Vector3(speed + +0.2f, 0, 0);
                _direction = Direction.EAST;
                moved      = true;
            }

            if (moved)
            {
                var tile = World.GetTile(new Vector3((int)Math.Floor(newPlayerPositionWithMargin.X), (int)Math.Floor(newPlayerPositionWithMargin.Y), (int)newPlayerPositionWithMargin.Z));
                if (tile != null)
                {
                    if (tile.CanWalk())
                    {
                        isWalking      = true;
                        PlayerPosition = newPlayerPosition;
                        Evolutio.Camera.MoveCamera(newPlayerPosition);
                        if (tile.PickableItems.Count > 0)
                        {
                            foreach (var itemStack in tile.PickableItems)
                            {
                                GiveItem(itemStack);
                            }
                            tile.PickableItems.Clear();
                        }
                    }
                    else
                    {
                        doingPathFinder = false;
                    }
                }
            }
            oldKeybordState = Keyboard.GetState();
        }