Example #1
0
        public void MouseDown(MouseButton button)
        {
            if (button != MouseButton.Left || Time.GameTime.TotalGameTime.TotalSeconds < _lastPlaced + 0.5f)
            {
                return;
            }

            var itemPlacer = ItemPlacers.FirstOrDefault(x => x.PlacerFor(SelectedItem));

            if (itemPlacer == null)
            {
                return;
            }

            var(i, y, _, _) = MouseState.Bounds(_camera.GetMatrix());
            var mouseTileX = i / GameWorld.TileSize;
            var mouseTileY = y / GameWorld.TileSize;

            if (!itemPlacer.Place(Entity, GameWorld, SelectedItem, mouseTileX, mouseTileY))
            {
                return;
            }

            YetiGame.ContentManager.Load <SoundEffect>("place").Play();
            ItemUsed?.Invoke(SelectedItem);
            _lastPlaced = Time.GameTime.TotalGameTime.TotalSeconds;
        }