Пример #1
0
 private static bool IsTripleSide(TileDirections directions)
 {
     return
         (directions == (TileDirections)(TileDirections.All - TileDirections.Down) ||
          directions == (TileDirections)(TileDirections.All - TileDirections.Left) ||
          directions == (TileDirections)(TileDirections.All - TileDirections.Right) ||
          directions == (TileDirections)(TileDirections.All - TileDirections.Up));
 }
Пример #2
0
    TileDirections GetClosestNeighbours(int x, int y, int wallOrNot = 0)
    {
        TileDirections newTileDirection = new TileDirections();

        if (x - 1 >= 0 && x + 1 < width && y - 1 >= 0 && y + 1 < height)
        {
            if (map[x, y + 1] == wallOrNot)
            {
                newTileDirection.up = true;
            }
            if (map[x + 1, y] == wallOrNot)
            {
                newTileDirection.right = true;
            }
            if (map[x, y - 1] == wallOrNot)
            {
                newTileDirection.down = true;
            }
            if (map[x - 1, y] == wallOrNot)
            {
                newTileDirection.left = true;
            }

            newTileDirection.wallNeighbours += map[x + 1, y];
            newTileDirection.wallNeighbours += map[x - 1, y];
            newTileDirection.wallNeighbours += map[x, y + 1];
            newTileDirection.wallNeighbours += map[x, y - 1];
        }
        else
        {
            if (y - 1 < 0)
            {
                newTileDirection.edge            = true;
                newTileDirection.downEdge        = true;
                newTileDirection.wallNeighbours += 3;
            }
            if (y + 1 > height - 1)
            {
                newTileDirection.edge            = true;
                newTileDirection.upEdge          = true;
                newTileDirection.wallNeighbours += 3;
            }
            if (x - 1 < 0)
            {
                newTileDirection.edge            = true;
                newTileDirection.rightEdge       = true;
                newTileDirection.wallNeighbours += 3;
            }
            if (x + 1 > width - 1)
            {
                newTileDirection.edge            = true;
                newTileDirection.leftEdge        = true;
                newTileDirection.wallNeighbours += 3;
            }
        }

        return(newTileDirection);
    }
Пример #3
0
 public void SetAdjacentTile(TileDirections dir, WorldTile tile)
 {
     if (adjacentTiles.ContainsKey(dir))
     {
         adjacentTiles[dir] = tile;
     }
     else
     {
         adjacentTiles.Add(dir, tile);
     }
 }
Пример #4
0
        public int Tile(string name, TileDirections directions, AnimationFrame frame)
        {
            var spriteSheet = _spriteDictionary[name];

            if (_frameCache.ContainsKey(spriteSheet))
            {
                var frameIndex = _frameCache[spriteSheet].IndexOf(frame);

                return(spriteSheet.Tile(directions, frameIndex));
            }

            return(spriteSheet.Tile(directions));
        }
Пример #5
0
    private void GenerateRoom()
    {
        if (map != null)
        {
            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    Vector3 pos = (new Vector3(-width / 2 + x + 0.5f, -height / 2 + y + 0.5f, 0)) / 2.1f;
                    if (map[x, y] == 1)
                    {
                        SpawnWall(pos, x, y);
                    }
                    else if (map[x, y] == 0)
                    {
                        GameObject background     = Instantiate(openArea, pos + mapOffset, transform.rotation, transform);
                        int        neighbourTiles = GetSurroundingWallCount(x, y);

                        if (neighbourTiles == 8)
                        {
                            SpawnWall(pos, x, y);
                            Destroy(background);
                        }

                        TileDirections    closestNeighbour = GetClosestNeighbours(x, y, 1);
                        RandomeBackground backgroundScript = background.GetComponent <RandomeBackground>();

                        if (closestNeighbour.down && !closestNeighbour.right && !closestNeighbour.left)
                        {
                            backgroundScript.isAboveGround = true;
                            spawnLocations.Add(backgroundScript.gameObject.transform);
                        }

                        backgroundScript.RandomSprite();

                        NeighbourLogic(closestNeighbour, null, backgroundScript);
                    }
                }
            }
        }
        //This happens when the room is done spawning in... maybe
        if (startArea)
        {
            mySpawner.SpawnPlayer(spawnLocations);
        }
        mySpawner.StartSpawning(spawnLocations);
    }
Пример #6
0
        public static TileDirections GetDirections(SpriteAppearance[,,] tilesTracker, int x, int y, int z, bool top)
        {
            SpriteAppearance  appearance  = tilesTracker[x, y, z];
            string            connect     = GetConnect(appearance, top);
            SpriteConnectType connectType = GetConnectType(appearance, top);
            TileDirections    directions  = TileDirections.None;

            if (appearance == null || connect == null)
            {
                return(directions);
            }

            SpriteAppearance above = tilesTracker[x, y - 1, z];
            SpriteAppearance below = tilesTracker[x, y + 1, z];
            SpriteAppearance left  = tilesTracker[x - 1, y, z];
            SpriteAppearance right = tilesTracker[x + 1, y, z];

            bool aboveConnect = GetConnect(above, top) == connect;
            bool belowConnect = GetConnect(below, top) == connect;
            bool leftConnect  = GetConnect(left, top) == connect;
            bool rightConnect = GetConnect(right, top) == connect;

            if (aboveConnect)
            {
                directions |= TileDirections.Up;
            }
            if (belowConnect)
            {
                directions |= TileDirections.Down;
            }
            if (leftConnect)
            {
                directions |= TileDirections.Left;
            }
            if (rightConnect)
            {
                directions |= TileDirections.Right;
            }

            if (connectType == SpriteConnectType.Wall)
            {
                directions = ApplyWallTypeConnectionRules(tilesTracker, x, y, z, top, directions, connect);
            }

            return(directions);
        }
Пример #7
0
        private void RenderMapSprites(
            ISpriteManager spriteManager, IDataRogueControl mapConfiguration,
            bool[,] renderTracker, int renderWidth, int renderHeight,
            SpriteAppearance[,,] tilesTracker, AnimationFrame[,,] frameTracker, BLTMapRendererOffset[,,] offsetTracker,
            int z, bool top)
        {
            if (z == 0)
            {
                BLTLayers.Set(top ? BLTLayers.MapTileTop : BLTLayers.MapTileBottom, mapConfiguration.ActivityIndex);
            }
            else
            {
                BLTLayers.Set(top ? BLTLayers.MapEntityTop : BLTLayers.MapEntityBottom, mapConfiguration.ActivityIndex);
            }

            BLT.Font("");
            BLT.Color(Color.White);

            for (int x = 0; x < renderWidth; x++)
            {
                for (int y = 0; y < renderHeight; y++)
                {
                    if (renderTracker[x + 1, y + 1])
                    {
                        var appearance = tilesTracker[x + 1, y + 1, z];
                        var frame      = frameTracker[x + 1, y + 1, z];
                        if (appearance != null)
                        {
                            var spriteName = top ? appearance.Top : appearance.Bottom;
                            if (spriteName != null)
                            {
                                TileDirections directions = BLTTileDirectionHelper.GetDirections(tilesTracker, x + 1, y + 1, z, top);
                                var            sprite     = spriteManager.Tile(spriteName, directions, frame);
                                var            offsetX    = (int)Math.Floor(offsetTracker[x + 1, y + 1, z].OffsetX * BLTTilesIOSystem.TILE_SPACING);
                                var            offsetY    = (int)Math.Floor(offsetTracker[x + 1, y + 1, z].OffsetY * BLTTilesIOSystem.TILE_SPACING);
                                BLT.Put(
                                    mapConfiguration.Position.Left + x * BLTTilesIOSystem.TILE_SPACING + offsetX,
                                    mapConfiguration.Position.Top + y * BLTTilesIOSystem.TILE_SPACING + offsetY,
                                    sprite);
                            }
                        }
                    }
                }
            }
        }
Пример #8
0
        private static TileDirections ApplyWallTypeConnectionRules(SpriteAppearance[,,] tilesTracker, int x, int y, int z, bool top, TileDirections directions, string connect)
        {
            if (IsTripleSide(directions))
            {
                TileDirections fromDirection = (TileDirections)(TileDirections.All - directions);
                directions = ApplyWallCornerCheck(tilesTracker, x, y, z, top, directions, connect, fromDirection);
            }

            if (directions == TileDirections.All)
            {
                foreach (var fromDirection in AllDirections)
                {
                    directions = ApplyWallCornerCheck(tilesTracker, x, y, z, top, directions, connect, fromDirection);
                }
            }

            return(directions);
        }
        protected override void DisplayInternal(ISpriteManager spriteManager, IDataRogueControl control, ISystemContainer systemContainer, List <MapCoordinate> playerFov)
        {
            var x    = control.Position.X;
            var y    = control.Position.Y;
            var text = (control as TextFormData).Value.ToString();

            var spriteSheet = spriteManager.Get(control.IsFocused ? "textbox_white_small" : "textbox_grey_small");

            BLTLayers.Set(BLTLayers.Text, control.ActivityIndex);
            BLT.Font("text");

            BLT.Print(x + 4, y, text);

            var textSize = BLT.Measure(new String('@', 30));

            var textBoxSize = textSize.Width + 4;

            if (textBoxSize % TILE_SIZE != 0)
            {
                textBoxSize = (textBoxSize / TILE_SIZE + 1) * TILE_SIZE;
            }

            var numberOfTiles = textBoxSize / TILE_SIZE;

            BLTLayers.Set(BLTLayers.UIElements, control.ActivityIndex);
            BLT.Font("");

            for (int i = 0; i < numberOfTiles; i++)
            {
                TileDirections direction = TileDirections.None;
                if (i != 0)
                {
                    direction |= TileDirections.Left;
                }

                if (i != numberOfTiles - 1)
                {
                    direction |= TileDirections.Right;
                }

                BLT.PutExt(x + TILE_SIZE * i, y - 2, 0, -2, spriteSheet.Tile(direction));
            }
        }
Пример #10
0
    public void SpawnWall(Vector3 pos, int x, int y)
    {
        GameObject tile = Instantiate(wall, pos + mapOffset, wall.transform.rotation, transform);
        Wall       tileWallComponent = tile.GetComponent <Wall>();

        int            neighbourTiles   = GetSurroundingWallCount(x, y);
        TileDirections closestNeighbour = GetClosestNeighbours(x, y);

        NeighbourLogic(closestNeighbour, tileWallComponent, null, 0, 0);

        if (neighbourTiles == 8)
        {
            tileWallComponent.innerWall = true;
            tileWallComponent.GetComponent <BoxCollider2D>().enabled = false;
        }
        else
        {
        }
    }
Пример #11
0
        protected override void DisplayInternal(ISpriteManager spriteManager, IDataRogueControl control, ISystemContainer systemContainer, List <MapCoordinate> playerFov)
        {
            var display     = control as ButtonControl;
            var x           = control.Position.X;
            var y           = control.Position.Y;
            var pressed     = control.IsPressed;
            var focused     = control.IsFocused;
            var spriteSheet = focused ? spriteManager.Get("button_pressed") : spriteManager.Get("button_unpressed");

            BLT.Font("text");

            var textSize   = BLT.Measure(display.Text).Width;
            var buttonSize = textSize + 4;

            if (buttonSize % 8 != 0)
            {
                buttonSize = (buttonSize / 8 + 1) * 8;
            }

            var numberOfTiles = buttonSize / 8;

            BLT.Font("");
            BLTLayers.Set((int)BLTLayers.UIElements, control.ActivityIndex);
            for (int i = 0; i < numberOfTiles; i++)
            {
                TileDirections direction = TileDirections.None;
                if (i != 0)
                {
                    direction |= TileDirections.Left;
                }

                if (i != numberOfTiles - 1)
                {
                    direction |= TileDirections.Right;
                }

                BLT.Put(x + 8 * i, y, spriteSheet.Tile(direction));
            }

            BLT.Font("text");
            BLTLayers.Set((int)BLTLayers.Text, control.ActivityIndex);
            BLT.Print(x + buttonSize / 2 - textSize / 2, y + (focused ? 3 : 2), display.Text);
        }
Пример #12
0
        /// <summary>
        /// Create an LBD tile from a binary stream.
        /// </summary>
        /// <param name="br">The binary stream.</param>
        /// <param name="addressOffset">The AddressOffset from the LBDHeader.</param>
        /// <param name="extraTilesTop">The offset of the extra tiles array in the LBD file.</param>
        public LBDTile(BinaryReader br, uint addressOffset, int extraTilesTop)
        {
            DrawTile    = br.ReadByte() == 1;
            UnknownFlag = br.ReadByte();
            TileType    = br.ReadUInt16();
            FootstepSoundAndCollision = br.ReadByte();
            TileDirection             = (TileDirections)br.ReadByte();
            TileHeight          = br.ReadInt16();
            _rawExtraTileOffset = br.ReadUInt32();

            if (_rawExtraTileOffset == 0)
            {
                ExtraTileIndex = -1;
            }
            else
            {
                ExtraTileIndex = (int)((_rawExtraTileOffset + addressOffset) - extraTilesTop) / Length;
            }
        }
        public void GetCorner_GetsCornerCoordinate(int x0, int y0, TileDirections firstFacing, int x1, int y1, TileDirections secondFacing, int xE, int yE)
        {
            var map = Substitute.For <IMap>();

            map.Origin.Returns(new Vector(0, 0));
            map.GetSize().ReturnsForAnyArgs(new System.Drawing.Size(0, 0));

            var poss = new VaultPossibleConnection
            {
                First  = new VaultConnectionPoint(new MapCoordinate("", x0, y0), new Vector(0, 0), map),
                Second = new VaultConnectionPoint(new MapCoordinate("", x1, y1), new Vector(0, 0), map)
            };

            poss.First.Facing  = firstFacing;
            poss.Second.Facing = secondFacing;

            poss.IsRightAngle.Should().BeTrue();

            poss.GetCorner().Should().Be(new MapCoordinate("", xE, yE));
        }
Пример #14
0
        protected override void DisplayInternal(ISpriteManager spriteManager, IDataRogueControl control, ISystemContainer systemContainer, List <MapCoordinate> playerFov)
        {
            var backgroundSpriteSheet = spriteManager.Get("textbox_blue");

            BLTLayers.Set(BLTLayers.Background, control.ActivityIndex);
            BLT.Font("");

            var width  = (int)Math.Ceiling(control.Position.Width / (double)BLTTilesIOSystem.TILE_SPACING);
            var height = (int)Math.Ceiling(control.Position.Height / (double)BLTTilesIOSystem.TILE_SPACING);

            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    TileDirections directions = BLTTileDirectionHelper.GetDirections(x, width, y, height);

                    var sprite = backgroundSpriteSheet.Tile(directions);

                    BLT.Put(control.Position.Left + x * BLTTilesIOSystem.TILE_SPACING, control.Position.Top + y * BLTTilesIOSystem.TILE_SPACING, sprite);
                }
            }
        }
Пример #15
0
        private static bool OppositeCornersConnect(SpriteAppearance[,,] tilesTracker, int x, int y, int z, bool top, TileDirections fromDirection, string connect)
        {
            Vector           clockwiseVector     = OppositeCornerClockwise[fromDirection];
            SpriteAppearance clockwiseAppearance = tilesTracker[x + clockwiseVector.X, y + clockwiseVector.Y, z];
            string           clockwiseConnect    = top ? clockwiseAppearance.TopConnect : clockwiseAppearance.BottomConnect;

            if (connect != clockwiseConnect)
            {
                return(false);
            }

            Vector           anticlockwiseVector     = OppositeCornerAnticlockwise[fromDirection];
            SpriteAppearance anticlockwiseAppearance = tilesTracker[x + anticlockwiseVector.X, y + anticlockwiseVector.Y, z];
            string           anticlockwiseConnect    = top ? anticlockwiseAppearance.TopConnect : anticlockwiseAppearance.BottomConnect;

            if (connect != anticlockwiseConnect)
            {
                return(false);
            }

            return(true);
        }
Пример #16
0
 private static TileDirections OppositeDirection(TileDirections fromDirection)
 {
     return(OppositeDirections[fromDirection]);
 }
Пример #17
0
 private static TileDirections ApplyWallCornerCheck(SpriteAppearance[,,] tilesTracker, int x, int y, int z, bool top, TileDirections directions, string connect, TileDirections fromDirection)
 {
     if (OppositeCornersConnect(tilesTracker, x, y, z, top, fromDirection, connect))
     {
         directions = (TileDirections)(directions - OppositeDirection(fromDirection));
     }
     return(directions);
 }
Пример #18
0
 public void SetNeighbor(TileDirections direction, Tile tile)
 {
     neighbors[(int)direction] = tile;
 }
Пример #19
0
 public int Tile(TileDirections directions)
 {
     return(Tile(directions, 0));
 }
Пример #20
0
 public int Tile(TileDirections directions, int frame)
 {
     return(_offset + frame);
 }
Пример #21
0
    private float FindTileHeight(TileDirections direction)
    {
        //Reference to the tile that we get the height for
        TileInfo foundTile = null;

        //Switch statement for the direction we need to check
        switch (direction)
        {
        case TileDirections.North:
            //Looping through all of the connected tiles in our tile
            foreach (TileInfo connection in this.tileReference.connectedTiles)
            {
                //Making sure the tile isn't null
                if (connection != null)
                {
                    //If the tile has a higher Z coord and the X coord is the same, then it's the tile we're looking for
                    if (connection.tilePosition.z > this.tileReference.tilePosition.z)
                    {
                        if (Mathf.Round(connection.tilePosition.x) == Mathf.Round(this.tileReference.tilePosition.x))
                        {
                            foundTile = connection;
                            break;
                        }
                    }
                }
            }
            break;

        case TileDirections.Northeast:
            //Looping through all of the connected tiles in our tile
            foreach (TileInfo connection in this.tileReference.connectedTiles)
            {
                //Making sure the tile isn't null
                if (connection != null)
                {
                    //If the tile has a higher Z and X coord, then it's the tile we're looking for
                    if (connection.tilePosition.z > this.tileReference.tilePosition.z)
                    {
                        if (connection.tilePosition.x > this.tileReference.tilePosition.x)
                        {
                            foundTile = connection;
                            break;
                        }
                    }
                }
            }
            break;

        case TileDirections.Southeast:
            //Looping through all of the connected tiles in our tile
            foreach (TileInfo connection in this.tileReference.connectedTiles)
            {
                //Making sure the tile isn't null
                if (connection != null)
                {
                    //If the tile has a lower Z coord and a higher X coord, then it's the tile we're looking for
                    if (connection.tilePosition.z < this.tileReference.tilePosition.z)
                    {
                        if (connection.tilePosition.x > this.tileReference.tilePosition.x)
                        {
                            foundTile = connection;
                            break;
                        }
                    }
                }
            }
            break;

        case TileDirections.South:
            //Looping through all of the connected tiles in our tile
            foreach (TileInfo connection in this.tileReference.connectedTiles)
            {
                //Making sure the tile isn't null
                if (connection != null)
                {
                    //If the tile has a lower Z coord and the X coord is the same, then it's the tile we're looking for
                    if (connection.tilePosition.z < this.tileReference.tilePosition.z)
                    {
                        if (Mathf.Round(connection.tilePosition.x) == Mathf.Round(this.tileReference.tilePosition.x))
                        {
                            foundTile = connection;
                            break;
                        }
                    }
                }
            }
            break;

        case TileDirections.Southwest:
            //Looping through all of the connected tiles in our tile
            foreach (TileInfo connection in this.tileReference.connectedTiles)
            {
                //Making sure the tile isn't null
                if (connection != null)
                {
                    //If the tile has a lower Z coord and a lower X coord, then it's the tile we're looking for
                    if (connection.tilePosition.z < this.tileReference.tilePosition.z)
                    {
                        if (connection.tilePosition.x < this.tileReference.tilePosition.x)
                        {
                            foundTile = connection;
                            break;
                        }
                    }
                }
            }
            break;

        case TileDirections.Northwest:
            //Looping through all of the connected tiles in our tile
            foreach (TileInfo connection in this.tileReference.connectedTiles)
            {
                //Making sure the tile isn't null
                if (connection != null)
                {
                    //If the tile has a higher Z and lower X coord, then it's the tile we're looking for
                    if (connection.tilePosition.z > this.tileReference.tilePosition.z)
                    {
                        if (connection.tilePosition.x < this.tileReference.tilePosition.x)
                        {
                            foundTile = connection;
                            break;
                        }
                    }
                }
            }
            break;
        }

        //If the found tile is still null, we return 0 for the height
        if (foundTile == null)
        {
            return(0);
        }
        //Otherwise we return the tile's elevation
        else
        {
            return(foundTile.elevation);
        }
    }
Пример #22
0
    public void NeighbourLogic(TileDirections closestNeighbour, Wall currentWall, RandomeBackground backgroundScript, int x, int y)
    {
        if (currentWall != null)
        {
            //If its a edge tile this happens
            if (closestNeighbour.edge)
            {
                if (closestNeighbour.wallNeighbours == 4)
                {
                    currentWall.innerWall = true;
                    return;
                }
                if (closestNeighbour.downEdge)
                {
                    currentWall.Rotate(1, true);
                }
                if (closestNeighbour.rightEdge)
                {
                    currentWall.Rotate(2, true);
                }
                if (closestNeighbour.upEdge)
                {
                    currentWall.Rotate(3, true);
                }
                if (closestNeighbour.leftEdge)
                {
                    currentWall.Rotate(4, true);
                }
                return;
            }

            //This happens if you have three neighbours
            if (closestNeighbour.wallNeighbours == 3)
            {
                if (closestNeighbour.up)
                {
                    currentWall.Rotate(1, true);
                }
                if (closestNeighbour.right)
                {
                    currentWall.Rotate(2, true);
                }
                if (closestNeighbour.down)
                {
                    currentWall.Rotate(3, true);
                }
                if (closestNeighbour.left)
                {
                    currentWall.Rotate(4, true);
                }
            }

            //This is the logic for if you have 4 neighbours
            if (closestNeighbour.wallNeighbours == 4)
            {
                currentWall.innerWall = true;
                return;
            }

            //This happens if you have no neighbours
            if (closestNeighbour.wallNeighbours == 0)
            {
                currentWall.SoloWall();
            }

            //This happens if you only have one neighbour
            if (closestNeighbour.wallNeighbours == 1)
            {
                //Pointing up
                if (closestNeighbour.left && closestNeighbour.up && closestNeighbour.right)
                {
                    currentWall.EndWall(1);
                }

                //Pointing right
                if (closestNeighbour.up && closestNeighbour.right && closestNeighbour.down)
                {
                    currentWall.EndWall(2);
                }

                //Pointing down
                if (closestNeighbour.right && closestNeighbour.down && closestNeighbour.left)
                {
                    currentWall.EndWall(3);
                }

                //Pointing left
                if (closestNeighbour.down && closestNeighbour.left && closestNeighbour.up)
                {
                    currentWall.EndWall(4);
                }
            }


            //This happens if you have 2 neighbours
            if (closestNeighbour.wallNeighbours == 2)
            {
                if (closestNeighbour.left && closestNeighbour.up)
                {
                    //Top left corner
                    currentWall.CornerLogic(1);
                }
                if (closestNeighbour.up && closestNeighbour.right)
                {
                    //Top right corner
                    currentWall.CornerLogic(2);
                }
                if (closestNeighbour.right && closestNeighbour.down)
                {
                    //Bottom right corner
                    currentWall.CornerLogic(3);
                }
                if (closestNeighbour.down && closestNeighbour.left)
                {
                    //Bottom left corner
                    currentWall.CornerLogic(4);
                }
                if (closestNeighbour.up && closestNeighbour.down)
                {
                    //up and down is walls
                    currentWall.CornerLogic(5);
                }
                if (closestNeighbour.right && closestNeighbour.left)
                {
                    //left and right is walls
                    currentWall.CornerLogic(6);
                }
            }
        }
        else
        {
            if (closestNeighbour.up)
            {
                backgroundScript.RoofSpikes();
            }
            if (closestNeighbour.down)
            {
                backgroundScript.RandomPlant();
            }

            if (closestNeighbour.up && !closestNeighbour.left && !closestNeighbour.right)
            {
                backgroundScript.canSpawnWater = true;
                waterSpawn.Add(backgroundScript);

                tmpX.Add(x);
                tmpY.Add(y);

                ceilSpawn.Add(new Vector3((-width / 2f + x + 0.5f), (-height / 2f + y), 0) * GameManager.globalScale);
            }
        }
    }
Пример #23
0
 public int Tile(string name, TileDirections directions)
 {
     return(Tile(name, directions, 0));
 }
Пример #24
0
    private void GenerateRoom()
    {
        if (map != null)
        {
            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    Vector3 pos = (new Vector3(-width / 2 + x + 0.5f, -height / 2 + y + 0.5f, 0)) / 2.1f;
                    if (map[x, y] == 1)
                    {
                        SpawnWall(pos, x, y);
                    }
                    else if (map[x, y] == 0 /*|| map[x, y] == 2*/)
                    {
                        GameObject background     = Instantiate(openArea, pos + mapOffset, transform.rotation, transform);
                        int        neighbourTiles = GetSurroundingWallCount(x, y);

                        ///This adds random one spot walls
                        if (addExtraOneTiles)
                        {
                            int neighbours = GetMoreSouroundingWallCount(x, y);
                            int tmpRandom  = UnityEngine.Random.Range(0, 1000);
                            if (tmpRandom <= 6 && neighbours < 1)
                            {
                                SpawnWall(pos, x, y);
                                Destroy(background);
                            }
                        }
                        ///

                        if (neighbourTiles == 8)
                        {
                            SpawnWall(pos, x, y);
                            Destroy(background);
                        }

                        TileDirections    closestNeighbour = GetClosestNeighbours(x, y, 1);
                        RandomeBackground backgroundScript = background.GetComponent <RandomeBackground>();

                        if (closestNeighbour.down && !closestNeighbour.right && !closestNeighbour.left && !closestNeighbour.up)
                        {
                            backgroundScript.isAboveGround = true;
                            spawnLocations.Add(backgroundScript.transform);
                            floorCoords.Add(new Coord(x, y));

                            //TEmp
                            list.Add(backgroundScript.transform.position);
                        }

                        backgroundScript.RandomSprite();

                        NeighbourLogic(closestNeighbour, null, backgroundScript, x, y);
                    }
                }
            }

            WaterSpawner WS = GetComponentInChildren <WaterSpawner>();
            WS.roomGen = this;

            int tmp = UnityEngine.Random.Range(0, tmpX.Count);

            int momentaryX = tmpX[tmp];
            int momentaryY = tmpY[tmp];

            if (spawnWater)
            {
                WS.spawnLocations = waterSpawn;
                WS.SetList(momentaryX, momentaryY);
            }
        }

        //This is all happens after the room has fully spawned in!
        GetComponent <CompositeCollider2D>().GenerateGeometry();

        endCoord   = floorCoords[floorCoords.Count - 1];
        startCoord = floorCoords[0];

        mySpawner.StartSpawning(spawnLocations);

        if (startArea)
        {
            mySpawner.SpawnPlayer(spawnLocations);
        }
    }
Пример #25
0
    public void NeighbourLogic(TileDirections closestNeighbour, Wall currentWall, RandomeBackground backgroundScript)
    {
        if (currentWall != null)
        {
            //If its a edge tile this happens
            if (closestNeighbour.edge)
            {
                if (closestNeighbour.wallNeighbours == 4)
                {
                    currentWall.innerWall = true;
                    return;
                }
                if (closestNeighbour.downEdge)
                {
                    currentWall.Rotate(1, true);
                }
                if (closestNeighbour.rightEdge)
                {
                    currentWall.Rotate(2, true);
                }
                if (closestNeighbour.upEdge)
                {
                    currentWall.Rotate(3, true);
                }
                if (closestNeighbour.leftEdge)
                {
                    currentWall.Rotate(4, true);
                }
                return;
            }

            //This happens if you have three neighbours
            if (closestNeighbour.wallNeighbours == 3)
            {
                if (closestNeighbour.up)
                {
                    currentWall.Rotate(1, true);
                }
                if (closestNeighbour.right)
                {
                    currentWall.Rotate(2, true);
                }
                if (closestNeighbour.down)
                {
                    currentWall.Rotate(3, true);
                }
                if (closestNeighbour.left)
                {
                    currentWall.Rotate(4, true);
                }
            }

            //This is the logic for if you have 4 neighbours
            if (closestNeighbour.wallNeighbours == 4)
            {
                currentWall.innerWall = true;
                return;
            }

            //This happens if you have no neighbours
            if (closestNeighbour.wallNeighbours == 0)
            {
                currentWall.SoloWall();
            }

            //This happens if you only have one neighbour
            if (closestNeighbour.wallNeighbours == 1)
            {
                //Pointing up
                if (closestNeighbour.left && closestNeighbour.up && closestNeighbour.right)
                {
                    currentWall.EndWall(1);
                }

                //Pointing right
                if (closestNeighbour.up && closestNeighbour.right && closestNeighbour.down)
                {
                    currentWall.EndWall(2);
                }

                //Pointing down
                if (closestNeighbour.right && closestNeighbour.down && closestNeighbour.left)
                {
                    currentWall.EndWall(3);
                }

                //Pointing left
                if (closestNeighbour.down && closestNeighbour.left && closestNeighbour.up)
                {
                    currentWall.EndWall(4);
                }
            }


            //This happens if you have 2 neighbours
            if (closestNeighbour.wallNeighbours == 2)
            {
                if (closestNeighbour.left && closestNeighbour.up)
                {
                    //Top left corner
                    currentWall.CornerLogic(1);
                }
                if (closestNeighbour.up && closestNeighbour.right)
                {
                    //Top right corner
                    currentWall.CornerLogic(2);
                }
                if (closestNeighbour.right && closestNeighbour.down)
                {
                    //Bottom right corner
                    currentWall.CornerLogic(3);
                }
                if (closestNeighbour.down && closestNeighbour.left)
                {
                    //Bottom left corner
                    currentWall.CornerLogic(4);
                }
            }
        }
        else
        {
            if (closestNeighbour.up)
            {
                backgroundScript.RoofSpikes();
            }
            if (closestNeighbour.down)
            {
                backgroundScript.RandomPlant();
            }
        }
    }
Пример #26
0
 public int Tile(TileDirections directions, int frame)
 {
     return(_offset + mapping[directions]);
 }
Пример #27
0
        public int Tile(TileDirections directions, int frame)
        {
            var map = mapping[directions];

            return(_offset + map + frame * 7 * 3);
        }