Ejemplo n.º 1
0
        // ------------------
        private void CreateBoulder(int tileX, int tileY)
        {
            Boulder tile = new Boulder(BoulderSprite, this);

            tile.SetTilePosition(new Vector2(tileX, tileY));
            tiles[tileX, tileY] = tile;
        }
Ejemplo n.º 2
0
        // ------------------
        private bool TryMove(Vector2 direction)
        {
            Vector2 newGridPos = GetTilePosition() + direction;

            // Ask the level what is in this slot already
            Tile tileInDirection = ourLevel.GetTileAtPosition(newGridPos);

            // If the target tile is a wall, we can't move there - return false.
            if (tileInDirection != null && tileInDirection is Wall)
            {
                // TODO: Play bump SFX
                return(false);
            }

            if (tileInDirection != null && tileInDirection is Diamond)
            {
                score++;
            }

            // If the target tile is a box, try to push it.
            if (tileInDirection != null && tileInDirection is Boulder)
            {
                Boulder targetBox   = tileInDirection as Boulder;
                bool    pushSuccess = targetBox.TryPush(direction);

                if (pushSuccess == false)
                {
                    return(false);
                }
            }

            Tile floorInDirection = ourLevel.GetFloorAtPosition(newGridPos);

            if (floorInDirection != null && floorInDirection is Goal)
            {
                ourLevel.NextLevel();
            }


            bool moveResult = ourLevel.TryMoveTile(this, newGridPos);

            // return true or false based on move successfullness
            return(moveResult);
        }