예제 #1
0
        /// <summary>
        /// Replace the tile in the hot bar with the tile hovered above it.
        /// </summary>
        /// <param name="tileHolder"></param>
        public static void ReplaceHotBar(TileHolder tileHolder)
        {
            for (int i = 0; i < _tileHolders.Count; i++)
            {
                if (tileHolder.IsIntersectingWithSlotOf(_tileHolders[i]))
                {
                    // It's all an optical illusion. The tile in the hot bar replaces the tile being moved, and a temporary tile is created to animate the deletion of the tile in the hotbar.

                    _deletedTile = new TileHolder(_tileHolders[i].Id);
                    _deletedTile.SetPosition(_tileHolders[i].GetPosition());
                    _deletedTile.MoveTo(new Vector2(_deletedTile.GetPosition().X, -_deletedTile.DrawRectangle.Height), 200);

                    _tileHolders[i].ChangeId(tileHolder.Id);
                    _tileHolders[i].SetPosition(tileHolder.GetPosition());
                    _tileHolders[i].ReturnToDefaultPosition();

                    tileHolder.SetPosition(TMBAW_Game.UserResWidth, TMBAW_Game.UserResHeight);
                    tileHolder.ReturnToDefaultPosition(500);

                    _swipeSound.Play();
                    _replaceSound.Play();
                    return;
                }
            }
            TileHolder.ReturnSound.Play();
        }
예제 #2
0
        /// <summary>
        /// Returns true if the tile is intersecting with the middle of the slot of another tile.
        /// </summary>
        /// <param name="tile"></param>
        /// <returns></returns>
        public bool IsIntersectingWithSlotOf(TileHolder tile)
        {
            Rectangle r = new Rectangle(DrawRectangle.X + DrawRectangle.Width / 2 - 1, DrawRectangle.Y, 1,
                                        DrawRectangle.Height);

            return(r.Intersects(tile.SlotRectangle));
        }
예제 #3
0
        /// <summary>
        /// Change brush to clicked tile.
        /// </summary>
        /// <param name="tile"></param>
        private static void Tile_WasClicked(TileHolder tile)
        {
            if (tile.Id == 0)
            {
                return;
            }

            SelectedTile           = tile;
            LevelEditor.SelectedId = tile.Id;
            tile.LastTimeUsed.Reset();
            LevelEditor.Brush.ChangeBrushMode(Brush.BrushMode.Build);
        }
예제 #4
0
        public static void ReplaceHotBarWithMiddleMouse(TileHolder tileHolder, TileType newId)
        {
            _deletedTile = new TileHolder(tileHolder.Id);
            _deletedTile.SetPosition(tileHolder.GetPosition());
            _deletedTile.MoveTo(new Vector2(_deletedTile.GetPosition().X, -_deletedTile.DrawRectangle.Height), 200);

            tileHolder.ChangeId(newId);
            tileHolder.SetPosition(tileHolder.GetPosition().X, -tileHolder.DrawRectangle.Height);
            tileHolder.ReturnToDefaultPosition();

            _swipeSound.Play();
        }
예제 #5
0
 private void TileHolder_WasClicked(TileHolder tile)
 {
     if (CanBeMoved && _wasMouseReleased)
     {
         _pickUpSound.Play();
         _isBeingMoved     = true;
         _wasMouseReleased = false;
         Rectangle mouse = InputSystem.GetMouseInUi();
         float     x     = mouse.X - Position.X;
         float     y     = mouse.Y - Position.Y;
         _mouseDifferential = new Vector2(x, y);
     }
 }
예제 #6
0
        public static void Initialize()
        {
            GraphicsRenderer.OnResolutionChanged += SetTilePositions;

            for (int i = 0; i < 8; i++)
            {
                TileHolder tileHolder = new TileHolder(0);
                tileHolder.WasClicked += Tile_WasClicked;
                tileHolder.CanBeMoved  = false;
                _tileHolders.Add(tileHolder);
            }
            SetTilePositions(UserResWidth, UserResHeight);

            _tileHolders[0].ChangeId(TileType.Grass);
            Tile_WasClicked(_tileHolders[0]);
        }
예제 #7
0
        public static void AddToHotBarFromWorld(TileType id)
        {
            // Checks if already on hotbar.
            foreach (var tileHolder in _tileHolders)
            {
                if (tileHolder.Id == id)
                {
                    Tile_WasClicked(tileHolder);
                    return;
                }
            }


            // Checks for an empty slot, otherwise replaces least used tile.
            foreach (var tileHolder in _tileHolders)
            {
                if (tileHolder.Id == 0)
                {
                    ReplaceHotBarWithMiddleMouse(tileHolder, id);
                    Tile_WasClicked(tileHolder);
                    return;
                }
            }

            TileHolder tileHolderWithHighestTime = new TileHolder(0);

            foreach (var tileHolder in _tileHolders)
            {
                if (tileHolder.LastTimeUsed.TimeElapsedInMilliSeconds > tileHolderWithHighestTime.LastTimeUsed.TimeElapsedInMilliSeconds)
                {
                    tileHolderWithHighestTime = tileHolder;
                }
            }

            ReplaceHotBarWithMiddleMouse(tileHolderWithHighestTime, id);
            Tile_WasClicked(tileHolderWithHighestTime);
        }
예제 #8
0
 private void OnTileClicked(TileHolder tile)
 {
     TileBeingMoved = tile;
 }
예제 #9
0
 private void TileHolder_WasReleased(TileHolder tile)
 {
 }