Beispiel #1
0
        public Sprite GetSprite(IWall wall, bool isCropped)
        {
            Vector3Int coords        = new Vector3Int(wall.X, wall.Y, wall.Z);
            Vector3Int rotatedCoords = WallTransformer.InverseRotateCoord(coords);

            return(WallCreator.DrawSpriteBorders(
                       sprites[rotatedCoords.z],
                       rotatedCoords.z,
                       new InmediateWallNeighbors(wall, OrientationManager.currentOrientation),
                       isCropped));
        }
        void UpdateSprite(IWall wall)
        {
            if (gameobjects.ContainsKey(wall) == false)
            {
                return;
            }

            GameObject wall_go = gameobjects[wall];

            wall_go.transform.position = WallTransformer.CoordToWorld(wall.X, wall.Y, wall.Z);

            SpriteRenderer sr = wall_go.GetComponent <SpriteRenderer> ();

            sr.sprite       = DataManager.wallSpriteData.GetDataById(wall.Type).GetSprite(wall, GetClippingForWall(wall));
            sr.sortingOrder = SortingOrders.WallOrder(wall.X, wall.Y, wall.Z, TileSubLayer.Wall);

            //sr.color = Random.ColorHSV(0, 1, 0, 1, 0.4f, 1);
        }
Beispiel #3
0
        public override void UpdateCursors(Vector2 mousePosition)
        {
            base.UpdateCursors(mousePosition);

            Vector3Int currentWallPos = WallTransformer.ScreenToCoord(mousePosition);
            Vector2    worldPos       = WallTransformer.CoordToWorld(currentWallPos);

            // Static cursors
            if (validClickStart)
            {
                GameObject cursorPrefab = Resources.Load <GameObject>(GamePaths.CursorPrefab);
                if (selectedPositions.ContainsKey(currentWallPos) == false && IsWallAt(currentWallPos))
                {
                    GameObject staticCursor = SimplePool.Spawn(cursorPrefab, worldPos, Quaternion.identity);

                    SpriteRenderer staticCursorSr = staticCursor.GetComponent <SpriteRenderer>();
                    staticCursorSr.sprite           = GetCursorSprite(currentWallPos);
                    staticCursorSr.sortingLayerName = mainCursorSr.sortingLayerName;
                    staticCursorSr.sortingOrder     = SortingOrders.WallOrder(currentWallPos.x, currentWallPos.y, currentWallPos.z, TileSubLayer.FirstWallCursor);

                    selectedPositions.Add(currentWallPos, staticCursor);
                }
            }
            // Main cursor
            else
            {
                if (IsWallAt(currentWallPos))
                {
                    mainCursorSr.enabled      = true;
                    mainCursorSr.sortingOrder = SortingOrders.WallOrder(currentWallPos.x, currentWallPos.y, currentWallPos.z, TileSubLayer.FirstWallCursor);
                    mainCursorSr.sprite       = GetCursorSprite(currentWallPos);

                    mainCursorGo.transform.position = worldPos;
                }
                else
                {
                    mainCursorSr.enabled = false;
                }
            }

            // Arrow cursor
            arrowCursor.transform.position = WallTransformer.CoordToWorld(currentWallPos) + new Vector2(Settings.TILE_WIDTH / 4, Settings.TILE_HEIGHT / 4);
            arrowCursor.GetComponent <SpriteRenderer>().sortingOrder = SortingOrders.WallOrder(currentWallPos.x, currentWallPos.y, currentWallPos.z, TileSubLayer.SecondWallCursor);
        }
Beispiel #4
0
 public void Update()
 {
     if (showMouseCoordinates)
     {
         Vector2Int tileCoords = TileTransformer.ScreenToCoord(Input.mousePosition);
         Vector3Int wallCoords = WallTransformer.ScreenToCoord(Input.mousePosition);
         debugTextField.text = string.Format(
             "Tile Coord: {0}, {1}\nWall Coord: {2}, {3}, {4}\nOrientation: {5}",
             tileCoords.x,
             tileCoords.y,
             wallCoords.x,
             wallCoords.y,
             wallCoords.z,
             OrientationManager.currentOrientation);
     }
     else
     {
         debugTextField.text = "";
     }
 }
Beispiel #5
0
        public static int WallOrder(int x, int y, int z, TileSubLayer layer)
        {
            Vector3Int rotatedCoords = WallTransformer.RotateCoord(new Vector3Int(x, y, z));

            return((rotatedCoords.x + rotatedCoords.y) * 20 + ((int)layer * 2) + 1 - rotatedCoords.z);
        }
        public InmediateWallNeighbors(IWall sourceWall, Orientation orientation)
        {
            int rotatedZ = WallTransformer.RotateCoord(new Vector3Int(0, 0, sourceWall.Z)).z;

            if (orientation == Orientation.North)
            {
                if (rotatedZ == 0)
                {
                    Top         = sourceWall.GetNeighbor(-1, 0, 0);
                    TopLeft     = sourceWall.GetNeighbor(0, -1, 1);
                    TopRight    = sourceWall.GetNeighbor(0, 0, 1);
                    Bottom      = sourceWall.GetNeighbor(1, 0, 0);
                    BottomLeft  = sourceWall.GetNeighbor(1, -1, 1);
                    BottomRight = sourceWall.GetNeighbor(1, 0, 1);
                }
                else
                {
                    Top         = sourceWall.GetNeighbor(0, -1, 1);
                    TopLeft     = sourceWall.GetNeighbor(0, 0, 0);
                    TopRight    = sourceWall.GetNeighbor(-1, 0, 0);
                    Bottom      = sourceWall.GetNeighbor(0, 1, 1);
                    BottomLeft  = sourceWall.GetNeighbor(0, 1, 0);
                    BottomRight = sourceWall.GetNeighbor(-1, 1, 0);
                }
            }
            else if (orientation == Orientation.West)
            {
                if (rotatedZ == 0)
                {
                    Top         = sourceWall.GetNeighbor(0, -1, 1);
                    TopLeft     = sourceWall.GetNeighbor(0, 0, 0);
                    TopRight    = sourceWall.GetNeighbor(-1, 0, 0);
                    Bottom      = sourceWall.GetNeighbor(0, 1, 1);
                    BottomLeft  = sourceWall.GetNeighbor(0, 1, 0);
                    BottomRight = sourceWall.GetNeighbor(-1, 1, 0);
                }
                else
                {
                    Top         = sourceWall.GetNeighbor(1, 0, 0);
                    TopLeft     = sourceWall.GetNeighbor(1, 0, 1);
                    TopRight    = sourceWall.GetNeighbor(1, -1, 1);
                    Bottom      = sourceWall.GetNeighbor(-1, 0, 0);
                    BottomLeft  = sourceWall.GetNeighbor(0, 0, 1);
                    BottomRight = sourceWall.GetNeighbor(0, -1, 1);
                }
            }
            else if (orientation == Orientation.South)
            {
                if (rotatedZ == 0)
                {
                    Top         = sourceWall.GetNeighbor(1, 0, 0);
                    TopLeft     = sourceWall.GetNeighbor(1, 0, 1);
                    TopRight    = sourceWall.GetNeighbor(1, -1, 1);
                    Bottom      = sourceWall.GetNeighbor(-1, 0, 0);
                    BottomLeft  = sourceWall.GetNeighbor(0, 0, 1);
                    BottomRight = sourceWall.GetNeighbor(0, -1, 1);
                }
                else
                {
                    Top         = sourceWall.GetNeighbor(0, 1, 1);
                    TopLeft     = sourceWall.GetNeighbor(-1, 1, 0);
                    TopRight    = sourceWall.GetNeighbor(0, 1, 0);
                    Bottom      = sourceWall.GetNeighbor(0, -1, 1);
                    BottomLeft  = sourceWall.GetNeighbor(-1, 0, 0);
                    BottomRight = sourceWall.GetNeighbor(0, 0, 0);
                }
            }
            else
            {
                if (rotatedZ == 0)
                {
                    Top         = sourceWall.GetNeighbor(0, 1, 1);
                    TopLeft     = sourceWall.GetNeighbor(-1, 1, 0);
                    TopRight    = sourceWall.GetNeighbor(0, 1, 0);
                    Bottom      = sourceWall.GetNeighbor(0, -1, 1);
                    BottomLeft  = sourceWall.GetNeighbor(-1, 0, 0);
                    BottomRight = sourceWall.GetNeighbor(0, 0, 0);
                }
                else
                {
                    Top         = sourceWall.GetNeighbor(-1, 0, 0);
                    TopLeft     = sourceWall.GetNeighbor(0, -1, 1);
                    TopRight    = sourceWall.GetNeighbor(0, 0, 1);
                    Bottom      = sourceWall.GetNeighbor(1, 0, 0);
                    BottomLeft  = sourceWall.GetNeighbor(1, -1, 1);
                    BottomRight = sourceWall.GetNeighbor(1, 0, 1);
                }
            }
        }
        private bool GetClippingForWall(IWall wall)
        {
            if (wall.Type == WallIndex.Empty)
            {
                return(true);
            }
            if (currentClipping == ClippingMode.FULL_CLIPPING)
            {
                return(true);
            }
            if (currentClipping == ClippingMode.NO_CLIP)
            {
                return(false);
            }
            Vector2Int   baseTileCoords    = WallTransformer.GetRotatedWallBase(new Vector3Int(wall.X, wall.Y, wall.Z));
            Vector3Int   rotatedWallCoords = WallTransformer.RotateInsideTile(new Vector3Int(wall.X, wall.Y, wall.Z));
            ITile        baseTile          = level.GetTileAt(baseTileCoords.x, baseTileCoords.y);
            List <ITile> tiles             = new List <ITile>();

            if (rotatedWallCoords.z == 1)
            {
                //The tiles checked for wall clipping,
                Vector2Int rotatedOffset1 = TileTransformer.InverseRotateCoord(new Vector2Int(-1, 0));
                Vector2Int rotatedOffSet2 = TileTransformer.InverseRotateCoord(new Vector2Int(-1, -1));
                Vector2Int rotatedOffSet3 = TileTransformer.InverseRotateCoord(new Vector2Int(-2, -1));
                Vector2Int rotatedOffset4 = TileTransformer.InverseRotateCoord(new Vector2Int(-2, -2));
                Vector2Int rotatedOffset5 = TileTransformer.InverseRotateCoord(new Vector2Int(-3, -2));
                Vector2Int rotatedOffSet6 = TileTransformer.InverseRotateCoord(new Vector2Int(-3, -3));
                Vector2Int rotatedOffSet7 = TileTransformer.InverseRotateCoord(new Vector2Int(-4, 3));



                tiles.Add(level.GetTileAt(baseTile.X + rotatedOffset1.x, baseTile.Y + rotatedOffset1.y));
                tiles.Add(level.GetTileAt(baseTile.X + rotatedOffSet2.x, baseTile.Y + rotatedOffSet2.y));
                tiles.Add(level.GetTileAt(baseTile.X + rotatedOffSet3.x, baseTile.Y + rotatedOffSet3.y));
                tiles.Add(level.GetTileAt(baseTile.X + rotatedOffset4.x, baseTile.Y + rotatedOffset4.y));
                tiles.Add(level.GetTileAt(baseTile.X + rotatedOffset5.x, baseTile.Y + rotatedOffset5.y));
                tiles.Add(level.GetTileAt(baseTile.X + rotatedOffSet6.x, baseTile.Y + rotatedOffSet6.y));
                tiles.Add(level.GetTileAt(baseTile.X + rotatedOffSet7.x, baseTile.Y + rotatedOffSet7.y));
            }
            else
            {
                Vector2Int rotatedOffset1 = TileTransformer.InverseRotateCoord(new Vector2Int(0, -1));
                Vector2Int rotatedOffSet2 = TileTransformer.InverseRotateCoord(new Vector2Int(-1, -1));
                Vector2Int rotatedOffSet3 = TileTransformer.InverseRotateCoord(new Vector2Int(-1, -2));
                Vector2Int rotatedOffset4 = TileTransformer.InverseRotateCoord(new Vector2Int(-2, -2));
                Vector2Int rotatedOffset5 = TileTransformer.InverseRotateCoord(new Vector2Int(-2, -3));
                Vector2Int rotatedOffSet6 = TileTransformer.InverseRotateCoord(new Vector2Int(-3, -3));
                Vector2Int rotatedOffSet7 = TileTransformer.InverseRotateCoord(new Vector2Int(-3, -4));

                tiles.Add(level.GetTileAt(baseTile.X + rotatedOffset1.x, baseTile.Y + rotatedOffset1.y));
                tiles.Add(level.GetTileAt(baseTile.X + rotatedOffSet2.x, baseTile.Y + rotatedOffSet2.y));
                tiles.Add(level.GetTileAt(baseTile.X + rotatedOffSet3.x, baseTile.Y + rotatedOffSet3.y));
                tiles.Add(level.GetTileAt(baseTile.X + rotatedOffset4.x, baseTile.Y + rotatedOffset4.y));
                tiles.Add(level.GetTileAt(baseTile.X + rotatedOffset5.x, baseTile.Y + rotatedOffset5.y));
                tiles.Add(level.GetTileAt(baseTile.X + rotatedOffSet6.x, baseTile.Y + rotatedOffSet6.y));
                tiles.Add(level.GetTileAt(baseTile.X + rotatedOffSet7.x, baseTile.Y + rotatedOffSet7.y));
            }
            foreach (ITile tile in tiles)
            {
                if (tile.Type != TileIndex.Empty)
                {
                    return(true);
                }
            }
            return(false);
        }