public void FindVisibleTiles(ITileMap tileMap, int viewerX, int viewerY, int visibleRange)
        {
            this.tileMap     = tileMap;
            this.viewerX     = viewerX;
            this.viewerY     = viewerY;
            this.VisualRange = visibleRange;

            if (visibleRange == 0)
            {
                return;
            }

            sqrVisRange = (float)(visibleRange * visibleRange);
            visibleTiles.Clear();

            AddVisible(viewerX, viewerY, 0);

            ScanOctantRows(1, 1f, 0f, -1, 1);     // 1 - nnw
            ScanOctantRows(1, 1f, 0f, 1, 1);      // 2 - nne
            ScanOctantColumns(1, 1f, 0f, 1, 1);   // 3 - ene
            ScanOctantColumns(1, 1f, 0f, 1, -1);  // 4 - ese
            ScanOctantRows(1, 1f, 0f, 1, -1);     // 5 - sse
            ScanOctantRows(1, 1f, 0f, -1, -1);    // 6 - ssw
            ScanOctantColumns(1, 1f, 0f, -1, -1); // 7 - wsw
            ScanOctantColumns(1, 1f, 0f, -1, 1);  // 8 - wnw
        }
Example #2
0
        public float GetCost(ITileMap map, IMover mover, PointInt32 point, PointInt32 start, PointInt32 target)
        {
            float dx = target.X - point.X;
            float dy = target.Y - point.Y;

            return((float)System.Math.Sqrt((double)((dx * dx) + (dy * dy))) * m_Coefficient);
        }
Example #3
0
        private void LoadTileMaps()
        {
            _backgroundTileMap = new TileMap();
            _backgroundTileMap.Load(MapData, MapData.BackgroundTileLayers);

            _foregroundTileMap = new TileMap();
            _foregroundTileMap.Load(MapData, MapData.ForegroundTileLayers);
        }
Example #4
0
    public void GenerateAndRender()
    {
        ITileMap _tilemap = Generate();

        GetComponent <TilemapRender>().Render(_tilemap);
        GetComponent <PolygonCollider2D>().points = _tilemap.GetCloseMash();
        collider.isTrigger = true;
        Invoke("MethodColliderFalse", 2);
    }
        public PathFinder(ITileMap map)
        {
            doneCalculating = false;
            SetMapTiles(map);

            currentCoordinates = new List<Vector2>();
            adjacentCoordinates = new List<Vector2>();
            nextCurrentCoordinates = new List<Vector2>();
            completeCoordinates = new List<Vector2>();
        }
Example #6
0
 public AStarPathfinder(ITileMap map, int maxSearchDistance, bool allowDiagMovement, IAStarHeuristic heuristic)
 {
     m_Closed            = new List <AStarNode>();
     m_Open              = new OrderedList <AStarNode>();
     m_Heuristic         = heuristic;
     m_Map               = map;
     m_MaxSearchDistance = maxSearchDistance;
     m_AllowDiagMovement = allowDiagMovement;
     m_Nodes             = new AStarMatrix(map.Width);
 }
Example #7
0
 public AStarPathfinder(ITileMap map, int maxSearchDistance, bool allowDiagMovement, IAStarHeuristic heuristic)
 {
     m_Closed = new List<AStarNode>();
       m_Open = new OrderedList<AStarNode>();
       m_Heuristic = heuristic;
       m_Map = map;
       m_MaxSearchDistance = maxSearchDistance;
       m_AllowDiagMovement = allowDiagMovement;
       m_Nodes = new AStarMatrix(map.Width);
 }
 public override bool GetTileData(Vector3Int location, ITileMap tileMap, ref TileData tileData)
 {
     tileData.transform = Matrix4x4.identity;
     tileData.color     = Color.white;
     if (m_AnimatedSprites != null && m_AnimatedSprites.Length > 0)
     {
         tileData.sprite = m_AnimatedSprites[m_AnimatedSprites.Length - 1];
     }
     return(true);
 }
 public override bool GetTileAnimationData(Vector3Int location, ITileMap tileMap, ref TileAnimationData tileAnimationData)
 {
     if (m_AnimatedSprites.Length > 0)
     {
         tileAnimationData.animatedSprites    = m_AnimatedSprites;
         tileAnimationData.animationSpeed     = Random.Range(m_MinSpeed, m_MaxSpeed);
         tileAnimationData.animationStartTime = m_AnimationStartTime;
         return(true);
     }
     return(false);
 }
Example #10
0
        /**
         *
         */
        public override bool GetTileData(Vector3Int location, ITileMap tileMap, ref TileData tileData)
        {
            base.GetTileData(location, tileMap, ref tileData);

            int mask = GetMask(location, tileMap, ref tileData);
            int index = GetIndex(mask);

            tileData.sprite = GetTileSprite(index);
            tileData.gameobject = GetTileGameObject(index);

            return true;
        }
Example #11
0
        public LayerMasterNodeViewModel(ITileMap tileMap)
        {
            TileMap = tileMap;
            Name    = "blabla";
            var childs = new LayerNodeViewModel[11];

            for (int i = 0; i < childs.Length; i++)
            {
                childs[i] = new LayerNodeViewModel(tileMap, i);
            }
            Childs = childs;
        }
Example #12
0
 public override void RefreshTile(Vector3Int location, ITileMap tileMap)
 {
     for (int yd = -1; yd <= 1; yd++)
     {
         for (int xd = -1; xd <= 1; xd++)
         {
             Vector3Int position = new Vector3Int(location.x + xd, location.y + yd, location.z);
             if (TileValue(tileMap, position))
             {
                 tileMap.RefreshTile(position);
             }
         }
     }
 }
Example #13
0
 private static void CheckMap(ITileMap m)
 {
     for (int y = 0; y < m.Height; y++)
     {
         for (int x = 0; x < m.Width; x++)
         {
             Debug.Assert(m[x, y] == Tile.Floor || m[x, y] == Tile.Wall);
             if (y == 0 || x == 0 || y == m.Height - 1 || x == m.Width - 1)
             {
                 Debug.Assert(m[x, y] != Tile.Floor);
             }
         }
     }
 }
Example #14
0
 public void Init(ITileMap tileMap)
 {
     for (int y = 0; y < tileMap.Height; y++)
     {
         List <tiles> temp = new List <tiles>(tileMap.Height);
         for (int x = 0; x < TileMap.TotalWidth; x++)
         {
             temp.Add(new tiles()
             {
                 x = x, y = y, tileState = tileMap.GetTileCollision(x, y) ? states.wall : states.unVisited
             });                                                                                                                    /*GET WALL INFO*/
         }
         moveTiles.Add(temp);
     }
 }
Example #15
0
        /**
         *
         */
        public override void RefreshTile(Vector3Int location, ITileMap tileMap)
        {
            for (int y = -1; y <= 1; y++)
            {
                for (int x = -1; x <= 1; x++)
                {
                    Vector3Int position = new Vector3Int(location.x + x, location.y + y, location.z);

                    if (TileValue(tileMap, position))
                    {
                        tileMap.RefreshTile(position);
                    }
                }
            }
        }
Example #16
0
 public void Render(ITileMap _tilemap)
 {
     Clear();
     for (int x = 0; x < _tilemap.Width; x++)
     {
         for (int y = 0; y <= _tilemap.Height; y++)
         {
             var _cell = _tilemap.GetCell(new Vector2Int(x, y));
             if (_cell != null)
             {
                 GameObject _cellGo = CreateEmpty(new Vector2Int(x, y));
                 _cell.Refresh(new Vector2Int(x, y), _tilemap, _cellGo);
             }
         }
     }
 }
Example #17
0
 public LayerNodeViewModel(ITileMap tileMap, int priority)
 {
     TileMap  = tileMap;
     Priority = priority;
     Childs   = new ObservableCollection <LayerEntryViewModel>(
         tileMap.Layers
         .Where(x =>
     {
         if (x is ILayerTilemap layerTilemap)
         {
             return(layerTilemap.Priority == priority);
         }
         return(false);
     })
         .Select(x => new LayerEntryViewModel(x as ILayerTilemap))
         );
 }
        private void UpdateTile(Vector3Int location, ITileMap tileMap, ref TileData tileData)
        {
            tileData.transform = Matrix4x4.identity;
            tileData.color     = Color.white;

            int mask = TileValue(tileMap, location + new Vector3Int(0, 1, 0)) ? 1 : 0;

            mask += TileValue(tileMap, location + new Vector3Int(1, 1, 0)) ? 2 : 0;
            mask += TileValue(tileMap, location + new Vector3Int(1, 0, 0)) ? 4 : 0;
            mask += TileValue(tileMap, location + new Vector3Int(1, -1, 0)) ? 8 : 0;
            mask += TileValue(tileMap, location + new Vector3Int(0, -1, 0)) ? 16 : 0;
            mask += TileValue(tileMap, location + new Vector3Int(-1, -1, 0)) ? 32 : 0;
            mask += TileValue(tileMap, location + new Vector3Int(-1, 0, 0)) ? 64 : 0;
            mask += TileValue(tileMap, location + new Vector3Int(-1, 1, 0)) ? 128 : 0;

            byte original = (byte)mask;

            if ((original | 254) < 255)
            {
                mask = mask & 125;
            }
            if ((original | 251) < 255)
            {
                mask = mask & 245;
            }
            if ((original | 239) < 255)
            {
                mask = mask & 215;
            }
            if ((original | 191) < 255)
            {
                mask = mask & 95;
            }

            int index = GetIndex((byte)mask);

            if (index >= 0 && index < m_Sprites.Length && TileValue(tileMap, location))
            {
                tileData.sprite       = m_Sprites[index];
                tileData.transform    = GetTransform((byte)mask);
                tileData.color        = Color.white;
                tileData.flags        = (int)(TileFlags.LockTransform | TileFlags.LockColor);
                tileData.colliderType = Tile.ColliderType.Sprite;
            }
        }
Example #19
0
    public ITileMap tilemap;// vaihra


    // Use this for initialization
    void Start()
    {
        path     = new BreadthFirstSearch();
        path.map = tilemap;
        body     = GetComponent <Rigidbody2D>();
        //Giz = GetComponent<debugGiz>();
        //Giz.init(path);

        var go = GameObject.FindGameObjectWithTag("Tilemap");

        if (go)
        {
            tilemap = go.GetComponent <TileMap>();
        }
        else
        {
            Debug.LogError("Tilemap missing");
        }
    }
Example #20
0
    private static void PrintMapExample()
    {
        ITileMapFactory tmf = new TileMapFactoryImpl();
        ITileMap        tm  = tmf.Def();

        for (int y = 0; y < tm.Height; ++y)
        {
            for (int x = 0; x < tm.Width; ++x)
            {
                if (tm[x, y] == Tile.Wall)
                {
                    Console.Write("#");
                }
                else
                {
                    Console.Write(".");
                }
            }
            Console.WriteLine();
        }
    }
Example #21
0
        private void UpdateTile(Vector3Int location, ITileMap tileMap, ref TileData tileData)
        {
            tileData.transform = Matrix4x4.identity;
            tileData.color     = Color.white;

            int mask = TileValue(tileMap, location + new Vector3Int(0, 1, 0)) ? 1 : 0;

            mask += TileValue(tileMap, location + new Vector3Int(1, 0, 0)) ? 2 : 0;
            mask += TileValue(tileMap, location + new Vector3Int(0, -1, 0)) ? 4 : 0;
            mask += TileValue(tileMap, location + new Vector3Int(-1, 0, 0)) ? 8 : 0;

            int index = GetIndex((byte)mask);

            if (index >= 0 && index < m_Sprites.Length && TileValue(tileMap, location))
            {
                tileData.sprite       = m_Sprites[index];
                tileData.transform    = GetTransform((byte)mask);
                tileData.flags        = (int)(TileFlags.LockTransform | TileFlags.LockColor);
                tileData.colliderType = Tile.ColliderType.Sprite;
            }
        }
Example #22
0
        public static void Fill(this Cell cell, int x, int y, ITileMap map, GeneratorParams parameters)
        {
            Tile[,] template;

            switch (cell.Type)
            {
                case CellType.Room:
                    template = FillRoom(cell.Openings);
                    break;
                case CellType.Corridor:
                    template = FillCorridor(cell.Openings);
                    break;
                default:
                    return;
            }

            ApplyAttributes(cell, template);

            const int cs = CellBasedGenerator.CellSize;

            Iterate(template, ( loc, tile) => map[x*cs + loc.X, y*cs + loc.Y] = tile);
        }
Example #23
0
        public static void Fill(this Cell cell, int x, int y, ITileMap map, GeneratorParams parameters)
        {
            Tile[,] template;

            switch (cell.Type)
            {
            case CellType.Room:
                template = FillRoom(cell.Openings);
                break;

            case CellType.Corridor:
                template = FillCorridor(cell.Openings);
                break;

            default:
                return;
            }

            ApplyAttributes(cell, template);

            const int cs = CellBasedGenerator.CellSize;

            Iterate(template, (loc, tile) => map[x * cs + loc.X, y * cs + loc.Y] = tile);
        }
Example #24
0
 int GetAssetNameBitmaskNoStr(int x, int y, ITileMap Tilemap, TileType type)
 {
     // found = IsImplemented(type) ? true : false;
     // 4-bit directions
     // North, west, east, south
     int value = 0;
     if (IsUpperTile(type, Tilemap.GetTile(x, y + 1)))  // Tähän reunan insert
     {
         value += 1;
     }
     if (IsUpperTile(type, Tilemap.GetTile(x + 1, y)))
     {
         value += 4;
     }
     if (IsUpperTile(type, Tilemap.GetTile(x, y - 1)))
     {
         value += 8;
     }
     if (IsUpperTile(type, Tilemap.GetTile(x - 1, y)))
     {
         value += 2;
     }
     return value;
 }
Example #25
0
 public float GetCost(ITileMap map, IMover mover, PointInt32 point, PointInt32 start, PointInt32 target)
 {
     float dx = target.X - point.X;
       float dy = target.Y - point.Y;
       return (float)System.Math.Sqrt((double)((dx * dx) + (dy * dy))) * m_Coefficient;
 }
        private int GetMaxRows(ITileMap map)
        {
            int height = 0;
            int maxRows = 0;

            for (int i = 0; i < map.TilesDown; i++)
            {
                height += map[0, i].Height;
                if (height >= Height)
                {
                    i++;
                    maxRows = i;
                    break;
                }
            }
            return maxRows;
        }
Example #27
0
    public void SetTileSprites(int width, int height, ITileMap tilemap, int startX, int startY)
    {
        // int tempIndex = 0;
        float offsetX = tilemap.GetTileGameObject(0, 0).transform.position.x;
        float offsetY = tilemap.GetTileGameObject(0, 0).transform.position.y;

        // sstring currentPool = GetCurrentPool();
        string currentPool = "Border";

        for (int y = startY; y < height; y++)
        {
            for (int x = startX; x < width; x++)
            {
                TileType type = tilemap.GetTile(x, y);

#if true
                if (type == TileType.Water || type == TileType.DeepWater)
                {
                    var anime = tilemap.GetTileGameObject(x, y).GetComponent<TileAnime>();
                    anime.enabled = true;
                    anime.SetSprites(type);
                    anime.Continue(); // maybe redudant 

                    continue;
                }
                else
                {
                    var tileAnime = tilemap.GetTileGameObject(x, y).GetComponent<TileAnime>();
                    if (tileAnime != null)
                        tileAnime.enabled = false;
                }
#endif

                if (type == TileType.Mountain) // outdoor mountain ===??)==??=9
                {
                    int tile = GetAssetNameBitmaskNoStr(x, y, tilemap, type);
                    if (tile == 15)
                    {
                        tilemap.GetTileGameObject(x, y).GetComponent<SpriteRenderer>().sprite = FlatMountains[Random.Range(0, FlatMountains.Length - 1)];
                    }
                    else
                    {
                        tilemap.GetTileGameObject(x, y).GetComponent<SpriteRenderer>().sprite = Mountains[tile];
                    }

                    if (Perlin.CanPlaceDoor && (tile == (int)TileDir.N || tile == (int)TileDir.S || tile == (int)TileDir.E || tile == (int)TileDir.W))
                    {
                        var go = Instantiate(Perlin.DoorHackGameObject);
                        go.transform.position = tilemap.GetTileGameObject(x, y).transform.position;
                        go.transform.position = new Vector3(go.transform.position.x, go.transform.position.y, ZlayerManager.GetZFromY(go.transform.position));
                        // tilemap.AddLater_hack(x, y, go);
                        print("door placed");
                        Perlin.CanPlaceDoor = false;

                        // translate hack
                        switch (tile)
                        {
                            case (int)TileDir.N:
                                go.transform.Translate(Vector3.up);
                                break;
                            case (int)TileDir.S:
                                go.transform.Translate(Vector3.down);
                                break;
                            case (int)TileDir.E:
                                go.transform.Translate(Vector3.left);
                                break;
                            case (int)TileDir.W:
                                go.transform.Translate(Vector3.right);
                                break;
                            default:
                                break;
                        }
                    }
                    continue;
                }

                // normals:
                int value = GetAssetNameBitmaskNoStr(x, y, tilemap, type);

                if (IsImplemented(type))
                    tilemap.GetTileGameObject(x, y).GetComponent<SpriteRenderer>().sprite = _textures2[type][(Random.Range(0, GetAssetCount(type)))];

                if (value == 15)    // ei voi tulla enää reunoja
                {
                    continue;
                }

                // lisää: reunat
                // 4-bit directions
                // North, west, east, south
#if false
                if (tempIndex < temporarySecondLayer.Length - 1)
                {
                    ObjectPool.instance.GetObjectForType("Border", true);

                    string border = "GrassLand_";

                    if (IsImplemented(type))
                    {
                        border = GetEnumName(type);
                    }

                    if ((value & (1 << 1 - 1)) == 0)            // TODO: TEXTURES2 TÄNNE
                    {
                        temporarySecondLayer[tempIndex].GetComponent<SpriteRenderer>().sprite = _textures[border + "N0"];
                        temporarySecondLayer[tempIndex].SetActive(true);
                        temporarySecondLayer[tempIndex].transform.position = new Vector3(x + offsetX, y + offsetY + 1);
                        tempIndex++;
                    }
                    if ((value & (1 << 2 - 1)) == 0)
                    {
                        temporarySecondLayer[tempIndex].GetComponent<SpriteRenderer>().sprite = _textures[border + "W0"];
                        temporarySecondLayer[tempIndex].transform.position = new Vector3(x + offsetX - 1, y + offsetY);
                        temporarySecondLayer[tempIndex].SetActive(true);
                        tempIndex++;
                    }
                    if ((value & (1 << 3 - 1)) == 0)
                    {
                        temporarySecondLayer[tempIndex].GetComponent<SpriteRenderer>().sprite = _textures[border + "E0"];
                        temporarySecondLayer[tempIndex].transform.position = new Vector3(x + offsetX + 1, y + offsetY);
                        temporarySecondLayer[tempIndex].SetActive(true);
                        tempIndex++;
                    }
                    if ((value & (1 << 4 - 1)) == 0)
                    {
                        temporarySecondLayer[tempIndex].GetComponent<SpriteRenderer>().sprite = _textures[border + "S0"];
                        temporarySecondLayer[tempIndex].transform.position = new Vector3(x + offsetX, y + offsetY - 1);
                        temporarySecondLayer[tempIndex].SetActive(true);
                        tempIndex++;
                    }
#else

                string border = "GrassLand_";

                if (IsImplemented(type))
                {
                    border = GetEnumName(type);
                }

                if ((value & (1 << 1 - 1)) == 0)            // TODO: TEXTURES2 TÄNNE
                {
                    var go = ObjectPool.instance.GetObjectForType(currentPool, false);
                    go.GetComponent<SpriteRenderer>().sprite = _textures[border + "N0"];
                    go.transform.position = new Vector3(x + offsetX, y + offsetY + 1);
                    go.transform.parent = _borders.transform;
                    borders.Add(go);
                }

                if ((value & (1 << 2 - 1)) == 0)
                {
                    var go = ObjectPool.instance.GetObjectForType(currentPool, false);
                    go.GetComponent<SpriteRenderer>().sprite = _textures[border + "W0"];
                    go.transform.position = new Vector3(x + offsetX - 1, y + offsetY);
                    go.transform.parent = _borders.transform;
                    borders.Add(go);
                }

                if ((value & (1 << 3 - 1)) == 0)
                {
                    var go = ObjectPool.instance.GetObjectForType(currentPool, false);
                    go.GetComponent<SpriteRenderer>().sprite = _textures[border + "E0"];
                    go.transform.position = new Vector3(x + offsetX + 1, y + offsetY);
                    go.transform.parent = _borders.transform;
                    borders.Add(go);
                }

                if ((value & (1 << 4 - 1)) == 0)
                {
                    var go = ObjectPool.instance.GetObjectForType(currentPool, false);
                    go.GetComponent<SpriteRenderer>().sprite = _textures[border + "S0"];
                    go.transform.position = new Vector3(x + offsetX, y + offsetY - 1);
                    go.transform.parent = _borders.transform;
                    borders.Add(go);
                }
#endif
            }
        }

        // tarkista rajat
        for (int i = 0; i < borders.Count; i++)
        {
            var border = borders[i];
            if (offsetX > border.transform.position.x ||
                offsetX + TileMap.TotalWidth < border.transform.position.x ||
                offsetY > border.transform.position.y ||
                offsetY + TileMap.TotalHeight < border.transform.position.y)
            {
                // border.transform.parent = null;
                border.transform.parent = null;
                ObjectPool.instance.PoolObject(border);
                borders.RemoveAt(i);
                i--;
            }
        }
        // f**k f**k
    }
 public static void DrawTileMap(ITileMap map)
 {
     foreach (Tile t in map)
     {
         Draw(t);
         DrawObjectInTile(t);
     }
 }
        public void Generate(ITileMap map)
        {
            _random = new MersennePrimeRandom(_params.Seed);

            var w = map.Width / CellSize;
            var h = map.Height / CellSize;

            _cells = new Cell[w, h];

            var startLoc = new Point {
                X = w / 2, Y = h / 2
            };

            _cells[startLoc.X, startLoc.Y] = Cell.FourWayRoom();

            if (_params.Exits)
            {
                _cells[startLoc.X, startLoc.Y].Attributes = AttributeType.Entry;
            }

            var unprocessed = new Queue <Point>();

            unprocessed.Enqueue(startLoc);

            while (unprocessed.Count > 0)
            {
                var location = unprocessed.Dequeue();
                var cell     = _cells[location.X, location.Y];

                foreach (var opening in cell.Openings.ToDirectionsArray())
                {
                    var newLocation = opening.GetLocation(location);
                    var newCell     = DetermineCellType(newLocation, opening);

                    if (newCell.Type != CellType.None)
                    {
                        _cells[newLocation.X, newLocation.Y] = ApplyAttributes(newCell);
                        unprocessed.Enqueue(newLocation);
                    }
                }
            }

            var secondExitPlaced = !_params.Exits;

            var chance = 10;

            for (var x = 0; x < _cells.GetLength(0); x++)
            {
                for (var y = 0; y < _cells.GetLength(1); y++)
                {
                    var cell = _cells[x, y];

                    if (!secondExitPlaced)
                    {
                        var spawnExit = _random.Chance(chance);
                        if (cell.Type != CellType.None && ((x <= w * 0.15) || (x >= w * 0.65)) && spawnExit)
                        {
                            cell.Attributes  = AttributeType.Exit;
                            secondExitPlaced = true;
                        }
                        else if (!spawnExit)
                        {
                            chance += (int)(chance * 0.25f);
                        }
                    }

                    cell.Fill(x, y, map, _params);
                }
            }
        }
Example #30
0
 public float GetCost(ITileMap map, IMover mover, PointInt32 point, PointInt32 start, PointInt32 target)
 {
     return System.Math.Max(System.Math.Abs(point.X - target.X), System.Math.Abs(point.Y - target.Y));
 }
 public void UpDateTiles(ITileMap map)
 {
     for (int row = 0; row < mapDemensions.X; row++)
         for (int col = 0; col < mapDemensions.Y; col++)
         {
             if (map[row, col].Solid)
             {
                 gameTiles[row, col] = -1;
             }
             else
                 gameTiles[row, col] = 0;
         }
 }
Example #32
0
 public Pathfinder(ITileMap map)
 {
     this.map = map;
 }
Example #33
0
 public override bool GetTileData(Vector3Int location, ITileMap tileMap, ref TileData tileData)
 {
     UpdateTile(location, tileMap, ref tileData);
     return(true);
 }
Example #34
0
        private bool TileValue(ITileMap tileMap, Vector3Int position)
        {
            TileBase tile = tileMap.GetTile(position);

            return(tile != null && tile == this);
        }
        private int GetMaxCols(ITileMap map)
        {
            int width = 0;
            int maxCols = 0;

            for (int i = 0; i < map.TilesAcross; i++)
            {
                width += map[i, 0].Width;
                if (width >= Width)
                {
                    i++;
                    maxCols = i;
                    break;
                }
            }
            return maxCols;
        }
        public TileCamera(TileMap gameMap, MovingObject montior,  int width, int height, int startRow = 0, int startCol = 0)
        {
            scrollLock = ScrollLock.unlocked;
            this.map = gameMap;
            controller = this;
            Width = width;
            Height = height;

            minRowToStartDraw = 0;
            minColToStartDraw = 0;

            StartRow = (startRow < 0) ? 0 : startRow;
            StartCol = (startCol < 0) ? 0 : startCol;

            maxCol = (gameMap.Width - Width) / gameMap[0, 0].Width;
            maxCol = (maxCol < 0) ? 0 : maxCol;

            maxRow = (gameMap.Height - Height) / gameMap[0, 0].Height;
            maxRow = (maxRow < 0) ? 0 : maxRow;

            currentMaxCol = maxCol;
            currentMinCol = minColToStartDraw;

            currentMaxRow = maxRow;
            currentMinRow = minRowToStartDraw;

            horizontalScrollPoint = new Vector2(0, width);
            verticalScrollPoint = new Vector2(0, height);

            maxRowsToDraw = GetMaxRows(gameMap as ITileMap);
            maxColToDraw = GetMaxCols(gameMap as ITileMap);
            MonitorRectangle(montior);
            tk = new TimeKeeper();
            timer = new ObjectTimer("mili", 400, true);
            _vScrolling = _hscrolling = false;
        }
        public void Generate(ITileMap map)
        {
            _random = new MersennePrimeRandom(_params.Seed);

            var w = map.Width / CellSize;
            var h = map.Height / CellSize;

            _cells = new Cell[w, h];

            var startLoc = new Point { X = w / 2, Y = h / 2 };
            _cells[startLoc.X, startLoc.Y] = Cell.FourWayRoom();

            if (_params.Exits)
            {
                _cells[startLoc.X, startLoc.Y].Attributes = AttributeType.Entry;
            }

            var unprocessed = new Queue<Point>();
            unprocessed.Enqueue(startLoc);

            while (unprocessed.Count > 0)
            {
                var location = unprocessed.Dequeue();
                var cell = _cells[location.X, location.Y];

                foreach (var opening in cell.Openings.ToDirectionsArray())
                {
                    var newLocation = opening.GetLocation(location);
                    var newCell = DetermineCellType(newLocation, opening);

                    if (newCell.Type != CellType.None)
                    {
                        _cells[newLocation.X, newLocation.Y] = ApplyAttributes(newCell);
                        unprocessed.Enqueue(newLocation);
                    }
                }
            }

            var secondExitPlaced = !_params.Exits;

            var chance = 10;
            for (var x = 0; x < _cells.GetLength(0); x++)
                for (var y = 0; y < _cells.GetLength(1); y++)
                {
                    var cell = _cells[x, y];

                    if (!secondExitPlaced)
                    {
                        var spawnExit = _random.Chance(chance);
                        if (cell.Type != CellType.None && ((x <= w * 0.15) || (x >= w * 0.65)) && spawnExit)
                        {
                            cell.Attributes = AttributeType.Exit;
                            secondExitPlaced = true;
                        }
                        else if (!spawnExit)
                        {
                            chance += (int)(chance * 0.25f);
                        }
                    }

                    cell.Fill(x, y, map, _params);
                }
        }
Example #38
0
        private static void Generate()
        {
            var size = sizes[selectedSize];

            dungeon = Generator.Generate(size, Seed);
        }
Example #39
0
    public void Search(List <List <BreadthFirstSearch.tiles> > moveTiles, int goalX, int goalY, ITileMap tilemap)
    {
        Height = tilemap.Height;
        Width  = tilemap.Width;

        this.GoalX = goalX;
        this.GoalY = goalY;
        realMap    = moveTiles;
        Queue <Vec2> frontier = new Queue <Vec2>(100);

        Vec2 start = new Vec2(GoalX, GoalY);

        frontier.Enqueue(start);

        Dictionary <Vec2, Vec2> cameFrom = new Dictionary <Vec2, Vec2>(289); // 17 * 17

        cameFrom[start] = start;

        dirs = new Dir[Height, Width];
        List <Vec2> neighbours = new List <Vec2>(4)
        {
            new Vec2(0, 0), new Vec2(0, 0), new Vec2(0, 0), new Vec2(0, 0)
        };

        // VisualizeMoveTiles();

        while (frontier.Count > 0)
        {
            var current = frontier.Dequeue();
            int count   = 0;
            GetNeighbours(current, neighbours, out count);

            for (int i = 0; i < count; i++)
            {
                var next = neighbours[i];
                if (!cameFrom.ContainsKey(next)) // LOL
                {
                    frontier.Enqueue(next);
                    cameFrom[next] = current;
                }
            }
        }

        GeneratePaths(cameFrom);
    }
Example #40
0
 public float GetCost(ITileMap map, IMover mover, PointInt32 point, PointInt32 start, PointInt32 target)
 {
     return(System.Math.Max(System.Math.Abs(point.X - target.X), System.Math.Abs(point.Y - target.Y)));
 }
Example #41
0
        public void ShowDungeon(ITileMap map)
        {
            var width  = map.Width;
            var height = map.Height;

            var winWidth  = Math.Min(width + 7, 132);
            var winHeight = Math.Min(height + 17, 132);

            try
            {
                Console.SetWindowSize(winWidth, winHeight);
                Console.SetBufferSize(width + 7, height + 17);
            }
            catch
            {
                Debug.Fail("Set console font size to a mono spaced font.");
                Console.SetBufferSize(width + 7, height + 17);
                Console.SetWindowSize(winWidth, winHeight);
            }


            for (var x = 0; x < width; x++)
            {
                for (var y = 0; y < height; y++)
                {
                    Console.SetCursorPosition(x + 3, y + 3);
                    var tile = map[x, y];
                    Console.ForegroundColor = ConsoleColor.White;
                    char output;

                    switch (tile.MaterialType)
                    {
                    case MaterialType.Air:
                        output = ' ';
                        break;

                    case MaterialType.Wall:
                        Console.ForegroundColor = ConsoleColor.White;
                        output = '\u256C';
                        break;

                    case MaterialType.Floor:
                        Console.ForegroundColor = ConsoleColor.Gray;
                        output = '\u2591';
                        break;

                    case MaterialType.BreakableWall:
                        Console.ForegroundColor = ConsoleColor.Green;
                        output = '#';
                        break;

                    default:
                        Console.ForegroundColor = ConsoleColor.Green;
                        output = '?';
                        break;
                    }

                    if (tile.Attributes.HasFlag(AttributeType.Entry))
                    {
                        Console.ForegroundColor = ConsoleColor.Green;
                        output = 'E';
                    }
                    else if (tile.Attributes.HasFlag(AttributeType.Exit))
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        output = 'E';
                    }
                    else if (tile.Attributes.HasFlag(AttributeType.Loot))
                    {
                        Console.ForegroundColor = ConsoleColor.Yellow;
                        output = 'L';
                    }
                    else if (tile.Attributes.HasFlag(AttributeType.MobSpawn))
                    {
                        Console.ForegroundColor = ConsoleColor.DarkRed;
                        output = 'M';
                    }
                    else if (tile.Attributes.HasFlag(AttributeType.Doors))
                    {
                        Console.ForegroundColor = ConsoleColor.DarkBlue;
                        output = 'D';
                    }

                    Console.Write(output);
                }
            }
            Console.ForegroundColor = ConsoleColor.DarkGreen;

            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine(Enumerable.Repeat('\u2500', width + 7).ToArray());
            Console.WriteLine("Width: {0} Height: {1}", width, height);
            Console.WriteLine();
            Console.WriteLine(Enumerable.Repeat('\u2500', width + 7).ToArray());
        }
        public void SetMapTiles(ITileMap map)
        {
            mapDemensions = new Vector2 (map.TilesAcross, map.TilesDown);
            gameTiles = new int[(int)mapDemensions.X, (int)mapDemensions.Y];

            for (int row = 0; row < mapDemensions.X; row++)
                for (int col = 0; col < mapDemensions.Y; col++)
                {
                    if (map[col, row].Solid)
                    {
                        gameTiles[col, row] = -1;
                    }
                    else
                        gameTiles[col, row] = 0;
                }
        }
Example #43
0
        /**
         *
         */
        private bool TileValue(ITileMap tileMap, Vector3Int position)
        {
            BaseTile tile = tileMap.GetTile(position);

            return (tile != null && ShouldMerge(tile));
        }
Example #44
0
 public void uptadeTiles(Vector2 position, ITileMap tileMap)
 {
     uptadeTiles((int)position.x, (int)position.y, tileMap); //
 }
Example #45
0
        /**
         *
         */
        private int GetMask(Vector3Int location, ITileMap tileMap, ref TileData tileData)
        {
            int mask = TileValue(tileMap, location + new Vector3Int(0, -1, 0)) ? SOUTH : 0;
            mask += TileValue(tileMap, location + new Vector3Int(1, -1, 0)) ? SOUTHEAST : 0;
            mask += TileValue(tileMap, location + new Vector3Int(1, 0, 0)) ? EAST : 0;
            mask += TileValue(tileMap, location + new Vector3Int(1, 1, 0)) ? NORTHEAST : 0;
            mask += TileValue(tileMap, location + new Vector3Int(0, 1, 0)) ? NORTH : 0;
            mask += TileValue(tileMap, location + new Vector3Int(-1, 1, 0)) ? NORTHWEST : 0;
            mask += TileValue(tileMap, location + new Vector3Int(-1, 0, 0)) ? WEST : 0;
            mask += TileValue(tileMap, location + new Vector3Int(-1, -1, 0)) ? SOUTHWEST : 0;

            byte original = (byte)mask;

            if ((original | 254) < ALL) { mask = mask & 125; }
            if ((original | 251) < ALL) { mask = mask & 245; }
            if ((original | 239) < ALL) { mask = mask & 215; }
            if ((original | 191) < ALL) { mask = mask & 95; }

            return mask;
        }
Example #46
0
 public float GetCost(ITileMap map, IMover mover, PointInt32 point, PointInt32 start, PointInt32 target)
 {
     return (System.Math.Abs(point.X - target.X) + System.Math.Abs(point.Y - target.Y)) * m_Coefficient;
 }
Example #47
0
 public float GetCost(ITileMap map, IMover mover, PointInt32 point, PointInt32 start, PointInt32 target)
 {
     return((System.Math.Abs(point.X - target.X) + System.Math.Abs(point.Y - target.Y)) * m_Coefficient);
 }