Exemple #1
0
        CCTileMapLayer(CCTileSetInfo[] tileSetInfos, CCTileLayerInfo layerInfo, CCTileMapInfo mapInfo, CCTileMapCoordinates layerSize,
                       int totalNumberOfTiles, int tileCapacity)
        {
            tileRenderCommand = new CCCustomCommand(RenderTileMapLayer);

            this.mapInfo    = mapInfo;
            LayerName       = layerInfo.Name;
            LayerSize       = layerSize;
            Opacity         = layerInfo.Opacity;
            LayerProperties = new Dictionary <string, string>(layerInfo.Properties);

            TileCoordOffset = new CCTileMapCoordinates(layerInfo.TileCoordOffset);
            ContentSize     = LayerSize.Size * TileTexelSize * CCTileMapLayer.DefaultTexelToContentSizeRatios;

            TileGIDAndFlagsArray = layerInfo.TileGIDAndFlags;

            UpdateTileCoordsToNodeTransform();

            ParseInternalProperties();

            InitialiseTileAnimations();

            InitialiseDrawBuffers(tileSetInfos);

            GenerateMinVertexZ();
        }
Exemple #2
0
        CCTileSetInfo TilesetForLayer(CCTileLayerInfo layerInfo)
        {
            CCTileMapCoordinates size     = layerInfo.LayerDimensions;
            List <CCTileSetInfo> tilesets = MapInfo.Tilesets;
            int numOfTiles = size.Row * size.Column;

            if (tilesets != null)
            {
                for (int tilesetIdx = 0; tilesetIdx < tilesets.Count; tilesetIdx++)
                {
                    CCTileSetInfo tileset        = tilesets[tilesetIdx];
                    short         tilesetLastGid = (short)(tilesetIdx < tilesets.Count - 1 ? tilesets[tilesetIdx + 1].FirstGid - 1 : short.MaxValue);
                    for (uint tileIdx = 0; tileIdx < numOfTiles; tileIdx++)
                    {
                        CCTileGidAndFlags gidAndFlags = layerInfo.TileGIDAndFlags[tileIdx];

                        if (gidAndFlags.Gid != 0 && gidAndFlags.Gid >= tileset.FirstGid && gidAndFlags.Gid <= tilesetLastGid)
                        {
                            return(tileset);
                        }
                    }
                }
            }

            CCLog.Log("CocosSharp: Warning: CCTileMapLayer: TileMap layer '{0}' has no tiles", layerInfo.Name);
            return(null);
        }
Exemple #3
0
        CCPoint LayerOffset(CCTileMapCoordinates tileCoords)
        {
            CCPoint offsetInNodespace = CCPoint.Zero;

            switch (MapType)
            {
            case CCTileMapType.Ortho:
                offsetInNodespace = new CCPoint(tileCoords.Column * TileTexelSize.Width, -tileCoords.Row * TileTexelSize.Height);
                break;

            case CCTileMapType.Iso:
                offsetInNodespace = new CCPoint((TileTexelSize.Width / 2) * (tileCoords.Column - tileCoords.Row),
                                                (TileTexelSize.Height / 2) * (-tileCoords.Column - tileCoords.Row));
                break;

            case CCTileMapType.Staggered:
                float diffX = 0;
                if ((int)tileCoords.Row % 2 == 1)
                {
                    diffX = TileTexelSize.Width / 2;
                }

                offsetInNodespace = new CCPoint(tileCoords.Column * TileTexelSize.Width + diffX,
                                                -tileCoords.Row * TileTexelSize.Height / 2);
                break;

            case CCTileMapType.Hex:
                break;
            }

            offsetInNodespace *= CCTileMapLayer.DefaultTexelToContentSizeRatios;

            return(offsetInNodespace);
        }
Exemple #4
0
        public void SetTileGID(CCTileGidAndFlags gidAndFlags, CCTileMapCoordinates tileCoords)
        {
            if (gidAndFlags.Gid == 0)
            {
                RemoveTile(tileCoords);
                return;
            }

            if (gidAndFlags.Gid < TileSetInfo.FirstGid)
            {
                Debug.Assert(false, String.Format("CCTileMapLayer: SetTileGID: Invalid GID {0}", gidAndFlags.Gid));
                return;
            }

            if (AreValidTileCoordinates(tileCoords) == false)
            {
                Debug.Assert(false, String.Format("CCTileMapLayer: Invalid tile coordinates row: {0} column: {1}",
                                                  tileCoords.Row, tileCoords.Column));
                return;
            }

            CCTileGidAndFlags currentGID = TileGIDAndFlags(tileCoords);

            if (currentGID == gidAndFlags)
            {
                return;
            }

            SetBatchRenderedTileGID(tileCoords.Column, tileCoords.Row, gidAndFlags);
        }
Exemple #5
0
        CCTileMapLayer(CCTileSetInfo tileSetInfo, CCTileLayerInfo layerInfo, CCTileMapInfo mapInfo, CCTileMapCoordinates layerSize,
                       int totalNumberOfTiles, int tileCapacity, CCTexture2D texture)
        {
            if (texture.ContentSizeInPixels == CCSize.Zero)
            {
                CCLog.Log("Tilemap Layer Texture {0} not loaded for layer {1}", tileSetInfo.TilesheetFilename, layerInfo.Name);
            }

            LayerName       = layerInfo.Name;
            LayerSize       = layerSize;
            Opacity         = layerInfo.Opacity;
            LayerProperties = new Dictionary <string, string>(layerInfo.Properties);

            MapType       = mapInfo.MapType;
            TileTexelSize = mapInfo.TileTexelSize;
            TileSetInfo   = tileSetInfo;

            Position    = LayerOffset(layerInfo.TileCoordOffset);
            ContentSize = LayerSize.Size * TileTexelSize * CCTileMapLayer.DefaultTexelToContentSizeRatios;

            tileSetTexture       = texture;
            tileGIDAndFlagsArray = layerInfo.TileGIDAndFlags;

            TileSetInfo.TilesheetSize = tileSetTexture.ContentSizeInPixels;

            UpdateTileCoordsToNodeTransform();

            ParseInternalProperties();

            InitialiseDrawBuffers();
        }
        public List<CCPoint> FindPath (CCPoint start, CCPoint end)
        {
            startTile = mapLayer.ClosestTileCoordAtNodePosition(start);
            endTile = mapLayer.ClosestTileCoordAtNodePosition(end);
            InitializeMap();
            startNode = nodes[startTile.Column, startTile.Row];
            startNode.State = Node.NodeState.open;
            endNode = nodes[endTile.Column, endTile.Row];

            List<CCPoint> path = new List<CCPoint>();
            bool success = Search(startNode);
            if(success)
            {
                // If a path was found, follow the parents from the end node to build a list of locations
                Node node = this.endNode;
                while (node.ParentNode != null)
                {
                    var centeredPoint = mapLayer.TilePosition(node.Location);
                    centeredPoint = new CCPoint(centeredPoint.X + map.TileTexelSize.Width / 2, centeredPoint.Y + map.TileTexelSize.Width / 2);
                    path.Add(centeredPoint);
                    node = node.ParentNode;
                }

                // Reverse the list so it's in the correct order when returned
                path.Reverse();
            }

            return path;
        }
        //returns a list of tiles with a certain property and value - checks up,down,left,right nodes
        //if you're in the upper left hand corner for instance and check for walkable tiles it will return bottom and right coords
        public static List<CCTileMapCoordinates> getSurroundingTilesWithProperties(CCPoint myPosition,string property, string value)
        {
            var adjacentCoordinates = new List<CCTileMapCoordinates>();
            foreach (CCTileMapLayer layer in map.TileLayersContainer.Children)
            {
                CCTileMapCoordinates currentTile = layer.ClosestTileCoordAtNodePosition(myPosition); // (touchlocation if depending on who passed in)
                CCTileMapCoordinates up, left, right, down;
                //Up
                up = new CCTileMapCoordinates(currentTile.Column + 1, currentTile.Row);
                if (checkSingleTileWithProperties(up, property, value))
                    adjacentCoordinates.Add(up);
                //Left
                left = new CCTileMapCoordinates(currentTile.Column, currentTile.Row - 1);
                if (checkSingleTileWithProperties(left, property, value))
                    adjacentCoordinates.Add(left);
                //Down
                down = new CCTileMapCoordinates(currentTile.Column - 1, currentTile.Row);
                if (checkSingleTileWithProperties(down, property, value))
                    adjacentCoordinates.Add(down);
                //Right
                right = new CCTileMapCoordinates(currentTile.Column, currentTile.Row + 1);
                if (checkSingleTileWithProperties(right, property, value))
                    adjacentCoordinates.Add(right);
            }
            

            return adjacentCoordinates;
        }
Exemple #8
0
 /// Creates a new instance of Node.
 /// <param name="x">The node's location along the X axis</param>
 /// <param name="y">The node's location along the Y axis</param>
 /// <param name="isWalkable">True if the node can be traversed, false if the node is a wall</param>
 /// <param name="endLocation">The location of the destination node</param>
 public Node(int x, int y, bool isWalkable, CCTileMapCoordinates endLocation)
 {
     this.Location = new CCTileMapCoordinates(x,y);
     this.State = NodeState.untested;
     this.IsWalkable = isWalkable;
     this.H = GetTraversalCost(this.Location, endLocation);
     this.G = 0;
 }
Exemple #9
0
        public CCPoint TilePosition(CCTileMapCoordinates tileCoords)
        {
            if ((MapType == CCTileMapType.Hex && tileCoords.Column % 2 == 1) ||
                (MapType == CCTileMapType.Staggered && tileCoords.Row % 2 == 1))
            {
                return(tileCoordsToNodeTransformOdd.Transform(tileCoords.Point));
            }

            return(tileCoordsToNodeTransform.Transform(tileCoords.Point));
        }
Exemple #10
0
        void UpdateVisibleTileRange()
        {
            var culledBounds = AffineWorldTransform.Inverse.Transform(VisibleBoundsWorldspace);
            var contentRect  = new CCRect(0.0f, 0.0f, ContentSize.Width, ContentSize.Height);

            culledBounds = culledBounds.Intersection(ref contentRect);

            foreach (var drawBufferManager in drawBufferManagers)
            {
                // The tileset dimensions may in fact be larger than the actual map tile size which will affect culling
                CCSize tileSetTileSize    = drawBufferManager.TileSetInfo.TileTexelSize * CCTileMapLayer.DefaultTexelToContentSizeRatios;
                float  tileSetTileSizeMax = Math.Max(tileSetTileSize.Width, tileSetTileSize.Height);
                CCSize mapTileSize        = TileTexelSize * CCTileMapLayer.DefaultTexelToContentSizeRatios;


                CCRect visibleTiles = nodeToTileCoordsTransform.Transform(culledBounds);
                visibleTiles           = visibleTiles.IntegerRoundedUpRect();
                visibleTiles.Origin.Y += 1;
                visibleTiles.Origin.X -= 1;

                int tilesOverX = 0;
                int tilesOverY = 0;

                CCRect overTileRect = new CCRect(0.0f, 0.0f,
                                                 Math.Max(tileSetTileSizeMax - mapTileSize.Width, 0),
                                                 Math.Max(tileSetTileSizeMax - mapTileSize.Height, 0));
                overTileRect = nodeToTileCoordsTransform.Transform(overTileRect);

                tilesOverX = (int)(Math.Ceiling(overTileRect.Origin.X + overTileRect.Size.Width) - Math.Floor(overTileRect.Origin.X));
                tilesOverY = (int)(Math.Ceiling(overTileRect.Origin.Y + overTileRect.Size.Height) - Math.Floor(overTileRect.Origin.Y));

                int yBegin = (int)Math.Max(0, visibleTiles.Origin.Y - tilesOverY);
                int yEnd   = (int)Math.Min(LayerSize.Row - 1, visibleTiles.Origin.Y + visibleTiles.Size.Height + tilesOverY);
                int xBegin = (int)Math.Max(0, visibleTiles.Origin.X - tilesOverX);
                int xEnd   = (int)Math.Min(LayerSize.Column - 1, visibleTiles.Origin.X + visibleTiles.Size.Width + tilesOverX);

                drawBufferManager.StartUpdateVisibleTiles(FlattenedTileIndex(new CCTileMapCoordinates(xBegin, yBegin)));

                for (int y = yBegin; y <= yEnd; ++y)
                {
                    CCTileMapCoordinates startCoord = new CCTileMapCoordinates(xBegin, y);
                    CCTileMapCoordinates endCoord   = new CCTileMapCoordinates(xEnd, y);
                    drawBufferManager.AddVisibleTileRange(FlattenedTileIndex(startCoord), FlattenedTileIndex(endCoord));
                }

                drawBufferManager.EndUpdateVisibleTiles();

                visibleTileRangeDirty = false;
            }
        }
        public void PerformCollisionAgainst(PhysicsEntity entity, out CCTileMapCoordinates tileAtXy, out bool didCollisionOccur)
        {
            didCollisionOccur = false;
            tileAtXy = CCTileMapCoordinates.Zero;

            int leftIndex;
            int rightIndex;

            int directionCount = 0;
            //entity是player/enemy
            //boundiongBox是包裹entity的最小的矩形
            //lowerLeft是左下角,UpperRight是右上角
            //得到的leftIndex和rightIndex应该是和entity有接触的瓦片地图的实体瓦片的list
            //例如,如果entity在地面上,则这个list里面应该只有和entity接触的地面瓦片
            //然后进一步判断这个地面瓦片对于entity的作用(地面就是支持entity)
            GetIndicesBetween (entity.LeftX, entity.RightX, out leftIndex, out rightIndex);

            var boundingBoxWorld = entity.BoundingBoxTransformedToWorld;

            //遍历所有和entity有接触的瓦片,来判断这些瓦片对于entity的物理作用
            for (int i = leftIndex; i < rightIndex; i++)
            {
                //计算得到这个瓦片和entity接触后对entity的作用力产生的运动vector
                //把ball从砖块里弹出来
                var separatingVector = GetSeparatingVector (boundingBoxWorld, collisions [i]);

                //如果player和瓦片地图中的不可进入的瓦片相碰
                for (directionCount = 0; directionCount < 4; directionCount++)
                {
                    if (separatingVector[directionCount] != CCVector2.Zero)
                    {
                        //更新entity的位置
                        entity.PositionX += separatingVector[directionCount].X;
                        entity.PositionY += separatingVector[directionCount].Y;
                        // refresh boundingBoxWorld:
                        boundingBoxWorld = entity.BoundingBoxTransformedToWorld;

                        didCollisionOccur = true;

                        tileAtXy = collisions [i].tiledMapCoordinate;
                    }
                }

            }
        }
Exemple #12
0
        public void SetTileGID(CCTileGidAndFlags gidAndFlags, CCTileMapCoordinates tileCoords)
        {
            if (gidAndFlags.Gid == 0)
            {
                RemoveTile(tileCoords);
                return;
            }

            if (AreValidTileCoordinates(tileCoords) == false)
            {
                Debug.Assert(false, String.Format("CCTileMapLayer: Invalid tile coordinates row: {0} column: {1}",
                                                  tileCoords.Row, tileCoords.Column));
                return;
            }

            CCTileGidAndFlags currentGID = TileGIDAndFlags(tileCoords);

            if (currentGID == gidAndFlags)
            {
                return;
            }
            CCTileMapDrawBufferManager drawBufferManager = GetDrawBufferManagerByGid(gidAndFlags.Gid);

            if (drawBufferManager == null)
            {
                foreach (CCTileSetInfo tileSetInfo in mapInfo.Tilesets)
                {
                    if (tileSetInfo.FirstGid <= gidAndFlags.Gid && tileSetInfo.LastGid >= gidAndFlags.Gid)
                    {
                        drawBufferManager = InitialiseDrawBuffer(tileSetInfo);
                        break;
                    }
                }
                if (drawBufferManagers == null)
                {
                    Debug.Assert(false, String.Format("CCTileMapLayer: Invalid tile grid id: {0}", gidAndFlags.Gid));
                    return;
                }

                drawBufferManagers.Add(drawBufferManager);
                visibleTileRangeDirty = true;
            }
            SetBatchRenderedTileGID(tileCoords.Column, tileCoords.Row, gidAndFlags);
        }
Exemple #13
0
        CCTileSetInfo[] TilesetForLayer(CCTileLayerInfo layerInfo)
        {
            CCTileMapCoordinates size     = layerInfo.LayerDimensions;
            List <CCTileSetInfo> tilesets = MapInfo.Tilesets;
            List <CCTileSetInfo> results  = new List <CCTileSetInfo>();
            int numOfTiles = size.Row * size.Column;

            if (tilesets != null)
            {
                for (int tilesetIdx = 0; tilesetIdx < tilesets.Count; tilesetIdx++)
                {
                    CCTileSetInfo tileset        = tilesets[tilesetIdx];
                    bool          contains       = false;
                    short         tilesetLastGid = (short)(tilesetIdx < tilesets.Count - 1 ? tilesets[tilesetIdx + 1].FirstGid - 1 : short.MaxValue);
                    for (uint tileIdx = 0; tileIdx < numOfTiles; tileIdx++)
                    {
                        CCTileGidAndFlags gidAndFlags = layerInfo.TileGIDAndFlags[tileIdx];
                        if (gidAndFlags.Gid != 0 && gidAndFlags.Gid >= tileset.FirstGid && gidAndFlags.Gid <= tilesetLastGid)
                        {
                            //return tileset;
                            results.Add(tileset);
                            contains = true;
                            break;
                        }
                    }
                    if (contains)
                    {
                        continue;
                    }
                }
            }
            if (results.Count > 0)
            {
                return(results.ToArray());
            }
            else
            {
                CCLog.Log("CocosSharp: Warning: CCTileMapLayer: TileMap layer '{0}' has no tiles", layerInfo.Name);
                return(null);
            }
        }
Exemple #14
0
 public CCSprite ExtractTile(CCTileMapCoordinates tileCoords, bool addToTileMapLayer = true)
 {
     return(ExtractTile(tileCoords.Column, tileCoords.Row, addToTileMapLayer));
 }
Exemple #15
0
 int FlattenedTileIndex(CCTileMapCoordinates tileCoords)
 {
     return(FlattenedTileIndex(tileCoords.Column, tileCoords.Row));
 }
        public void SetTileGID(CCTileGidAndFlags gidAndFlags, CCTileMapCoordinates tileCoords)
        {
            if (gidAndFlags.Gid == 0)
            {
                RemoveTile(tileCoords);
                return;
            }

            if (AreValidTileCoordinates(tileCoords) == false)
            {
                Debug.Assert(false, String.Format("CCTileMapLayer: Invalid tile coordinates row: {0} column: {1}",
                    tileCoords.Row, tileCoords.Column));
                return;
            }

            CCTileGidAndFlags currentGID = TileGIDAndFlags(tileCoords);

            if (currentGID == gidAndFlags)
                return;
            CCTileMapDrawBufferManager drawBufferManager = GetDrawBufferManagerByGid(gidAndFlags.Gid);
            if (drawBufferManager == null)
            {
                foreach (CCTileSetInfo tileSetInfo in mapInfo.Tilesets)
                {
                    if (tileSetInfo.FirstGid <= gidAndFlags.Gid && tileSetInfo.LastGid >= gidAndFlags.Gid)
                    {
                        drawBufferManager = InitialiseDrawBuffer(tileSetInfo);
                        break;
                    }
                }
                if (drawBufferManagers == null)
                {
                    Debug.Assert(false, String.Format("CCTileMapLayer: Invalid tile grid id: {0}", gidAndFlags.Gid));
                    return;
                }

                drawBufferManagers.Add(drawBufferManager);
                visibleTileRangeDirty = true;
            }
            SetBatchRenderedTileGID(tileCoords.Column, tileCoords.Row, gidAndFlags);
        }
 int FlattenedTileIndex(CCTileMapCoordinates tileCoords)
 {
     return FlattenedTileIndex(tileCoords.Column, tileCoords.Row);
 }
        CCTileMapLayer(CCTileSetInfo tileSetInfo, CCTileLayerInfo layerInfo, CCTileMapInfo mapInfo, CCTileMapCoordinates layerSize, 
            int totalNumberOfTiles, int tileCapacity, CCTexture2D texture)
        {

            //Debug.Assert(texture.ContentSizeInPixels != CCSize.Zero, string.Format("Tilemap Texture {0} not loaded for layer {1}", tileSetInfo.TilesheetFilename, layerInfo.Name));

            if (texture.ContentSizeInPixels == CCSize.Zero)
                CCLog.Log("Tilemap Layer Texture {0} not loaded for layer {1}", tileSetInfo.TilesheetFilename, layerInfo.Name);

            LayerName = layerInfo.Name;
            LayerSize = layerSize;
            Opacity = layerInfo.Opacity;
            LayerProperties = new Dictionary<string, string>(layerInfo.Properties);

            MapType = mapInfo.MapType;
            TileTexelSize = mapInfo.TileTexelSize;
            TileSetInfo = tileSetInfo;

            Position = LayerOffset(layerInfo.TileCoordOffset);
            ContentSize = LayerSize.Size * TileTexelSize * CCTileMapLayer.DefaultTexelToContentSizeRatios;

            tileSetTexture = texture;
            tileGIDAndFlagsArray = layerInfo.TileGIDAndFlags;

            TileSetInfo.TilesheetSize = tileSetTexture.ContentSizeInPixels;

            UpdateTileCoordsToNodeTransform();

            ParseInternalProperties();

            InitialiseQuadsVertexBuffer();
            InitialiseIndexBuffer();
        }
 void InitializeMap()
 {
     int numberOfColumns = (int)map.MapDimensions.Size.Width;
     int numberOfRows = (int)map.MapDimensions.Size.Height;
     this.nodes = new Node[numberOfColumns, numberOfRows];
     // Loop through the columns and rows to find all tiles
     for (int row = 0; row < numberOfRows; row++)
     {
         for (int column = 0; column < numberOfColumns; column++)
         {
             var currTile = new CCTileMapCoordinates(column,row);
             bool isWalkable = character.checkSingleTileWithProperties(currTile,"walkable","true");
             this.nodes[column, row] = new Node(column, row,isWalkable , endTile);
         }
     }
 }
Exemple #20
0
 public float TileVertexZ(CCTileMapCoordinates tileCoords)
 {
     return(TileVertexZ(tileCoords.Column, tileCoords.Row));
 }
Exemple #21
0
 public void RemoveTile(CCTileMapCoordinates tileCoords)
 {
     RemoveTile(tileCoords.Column, tileCoords.Row);
 }
 public Boolean isTileOccupied(CCTileMapCoordinates checkHere)
 {
     CCTileMapCoordinates characterPosition = LayerNamed("Map").ClosestTileCoordAtNodePosition(user.Position);
     //first check if user occupies a tile
     if (characterPosition.Column == checkHere.Column && characterPosition.Row == checkHere.Row)
         return true;
     //check if any enemies occupy that tile
     foreach (character enemy in enemiesList)
     {
         characterPosition = LayerNamed("Map").ClosestTileCoordAtNodePosition(enemy.Position);
         if (characterPosition.Column == checkHere.Column && characterPosition.Row == checkHere.Row)
             return true;
     }
     //UNOCCUPIED!
     return false;
 }
        //check if the user occupies a tile adjacent to an enemy
        bool isUserNear(CCTileMapCoordinates hostPosition)
        {
            CCTileMapCoordinates up, down, left, right;
            up = new CCTileMapCoordinates(hostPosition.Column, hostPosition.Row-1);
            down = new CCTileMapCoordinates(hostPosition.Column, hostPosition.Row+1);
            left = new CCTileMapCoordinates(hostPosition.Column-1, hostPosition.Row);
            right = new CCTileMapCoordinates(hostPosition.Column+1, hostPosition.Row);

            CCTileMapCoordinates userPosition = LayerNamed("Map").ClosestTileCoordAtNodePosition(user.Position);
            //first check if user occupies a tile
            if (userPosition.Column == up.Column && userPosition.Row == up.Row)
                return true;
            if (userPosition.Column == down.Column && userPosition.Row == down.Row)
                return true;
            if (userPosition.Column == left.Column && userPosition.Row == left.Row)
                return true;
            if (userPosition.Column == right.Column && userPosition.Row == right.Row)
                return true;
            return false;



        }
        List<character> placeEnemiesRandomly()
        {
            List<character> enemies = new List<character>();
            int tileDimension = (int)TileTexelSize.Width;
            int numberOfColumns = (int)MapDimensions.Size.Width;
            int numberOfRows = (int)MapDimensions.Size.Height;
            CCTileMapCoordinates randomTile;
            CCPoint randomLocation;
            for (int i =0; i < (Int32.Parse(MapPropertyNamed("numEnemies"))+level); i++)
            {   
                int randCol = CCRandom.GetRandomInt(0, numberOfColumns - 1);
                int randRow = CCRandom.GetRandomInt(0, numberOfRows - 1);

                randomTile = new CCTileMapCoordinates(randCol, randRow);

                //if you randomly chose a non-walkable tile OR another char is on that tile
                if (character.checkSingleTileWithProperties(randomTile, "walkable", "true")
                    && !isTileOccupied(randomTile))
                {

                    randomLocation = LayerNamed("Map").TilePosition(randomTile);
                    randomLocation = new CCPointI((int)randomLocation.X + tileDimension / 2, (int)randomLocation.Y + tileDimension / 2);
                    enemies.Add(new character("enemyChar", 5, randomLocation, availableWeapons[i+1] ));//CCRandom.GetRandomInt(0,availableWeapons.Count-1)]  ));
                }
                else
                    i--;
                
            }
            return enemies;
        }
 character getEnemyAt(CCTileMapCoordinates checkHere)
 {
     
     foreach (character enemy in enemiesList)
     {
      CCTileMapCoordinates enemyLocation = LayerNamed("Map").ClosestTileCoordAtNodePosition(enemy.Position);
         if (enemyLocation.Column == checkHere.Column && enemyLocation.Row == checkHere.Row)
             return enemy;
     }
     return null;
 }
 private static IEnumerable<CCTileMapCoordinates> GetAdjacentLocations(CCTileMapCoordinates fromLocation)
 {
     return new CCTileMapCoordinates[]
     {
         new CCTileMapCoordinates(fromLocation.Column-1, fromLocation.Row  ),
         new CCTileMapCoordinates(fromLocation.Column,   fromLocation.Row+1),
         new CCTileMapCoordinates(fromLocation.Column+1, fromLocation.Row  ),
         new CCTileMapCoordinates(fromLocation.Column,   fromLocation.Row-1),
     };
 }
Exemple #27
0
 public CCTileGidAndFlags TileGIDAndFlags(CCTileMapCoordinates tileCoords)
 {
     return(TileGIDAndFlags(tileCoords.Column, tileCoords.Row));
 }
Exemple #28
0
 void UpdateQuadAt(CCTileMapDrawBufferManager drawBufferManager, CCTileMapCoordinates tileCoords, bool updateBuffer = true)
 {
     UpdateQuadAt(drawBufferManager, tileCoords.Column, tileCoords.Row, updateBuffer);
 }
 void UpdateQuadAt(CCTileMapDrawBufferManager drawBufferManager, CCTileMapCoordinates tileCoords, bool updateBuffer = true)
 {
     UpdateQuadAt(drawBufferManager, tileCoords.Column, tileCoords.Row, updateBuffer);
 }
        // Private constructor chaining

        CCTileMapLayer(CCTileSetInfo tileSetInfo, CCTileLayerInfo layerInfo, CCTileMapInfo mapInfo, CCTileMapCoordinates layerSize) 
            : this(tileSetInfo, layerInfo, mapInfo, layerSize, (int)(layerSize.Row * layerSize.Column))
        {
        }
Exemple #31
0
 void UpdateQuadAt(CCTileMapCoordinates tileCoords, bool updateBuffer = true)
 {
     UpdateQuadAt(tileCoords.Column, tileCoords.Row, updateBuffer);
 }
        void UpdateVisibleTileRange()
        {
            var culledBounds = AffineWorldTransform.Inverse.Transform(VisibleBoundsWorldspace);
            var contentRect = new CCRect(0.0f, 0.0f, ContentSize.Width, ContentSize.Height);
            culledBounds = culledBounds.Intersection(ref contentRect);

            foreach (var drawBufferManager in drawBufferManagers)
            {
                // The tileset dimensions may in fact be larger than the actual map tile size which will affect culling
                CCSize tileSetTileSize = drawBufferManager.TileSetInfo.TileTexelSize * CCTileMapLayer.DefaultTexelToContentSizeRatios;
                float tileSetTileSizeMax = Math.Max(tileSetTileSize.Width, tileSetTileSize.Height);
                CCSize mapTileSize = TileTexelSize * CCTileMapLayer.DefaultTexelToContentSizeRatios;


                CCRect visibleTiles = nodeToTileCoordsTransform.Transform(culledBounds);
                visibleTiles = visibleTiles.IntegerRoundedUpRect();
                visibleTiles.Origin.Y += 1;
                visibleTiles.Origin.X -= 1;

                int tilesOverX = 0;
                int tilesOverY = 0;

                CCRect overTileRect = new CCRect(0.0f, 0.0f,
                    Math.Max(tileSetTileSizeMax - mapTileSize.Width, 0),
                    Math.Max(tileSetTileSizeMax - mapTileSize.Height, 0));
                overTileRect = nodeToTileCoordsTransform.Transform(overTileRect);

                tilesOverX = (int)(Math.Ceiling(overTileRect.Origin.X + overTileRect.Size.Width) - Math.Floor(overTileRect.Origin.X));
                tilesOverY = (int)(Math.Ceiling(overTileRect.Origin.Y + overTileRect.Size.Height) - Math.Floor(overTileRect.Origin.Y));

                int yBegin = (int)Math.Max(0, visibleTiles.Origin.Y - tilesOverY);
                int yEnd = (int)Math.Min(LayerSize.Row - 1, visibleTiles.Origin.Y + visibleTiles.Size.Height + tilesOverY);
                int xBegin = (int)Math.Max(0, visibleTiles.Origin.X - tilesOverX);
                int xEnd = (int)Math.Min(LayerSize.Column - 1, visibleTiles.Origin.X + visibleTiles.Size.Width + tilesOverX);

                drawBufferManager.StartUpdateVisibleTiles(FlattenedTileIndex(new CCTileMapCoordinates(xBegin, yBegin)));

                for (int y = yBegin; y <= yEnd; ++y)
                {
                    CCTileMapCoordinates startCoord = new CCTileMapCoordinates(xBegin, y);
                    CCTileMapCoordinates endCoord = new CCTileMapCoordinates(xEnd, y);
                    drawBufferManager.AddVisibleTileRange(FlattenedTileIndex(startCoord), FlattenedTileIndex(endCoord));
                }

                drawBufferManager.EndUpdateVisibleTiles();

                visibleTileRangeDirty = false;
            }
        }
 public CCTileGidAndFlags TileGIDAndFlags(CCTileMapCoordinates tileCoords)
 {
     return TileGIDAndFlags(tileCoords.Column, tileCoords.Row);
 }
 public float TileVertexZ(CCTileMapCoordinates tileCoords)
 {
     return TileVertexZ(tileCoords.Column, tileCoords.Row);
 }
Exemple #35
0
        void flipIt(float dt)
        {
            CCTileMapLayer layer = tileMap.LayerNamed("Layer 0");

            //blue diamond 
            var tileCoord = new CCTileMapCoordinates(1, 10);

            CCTileGidAndFlags gidAndFlags = layer.TileGIDAndFlags(tileCoord);
            CCTileFlags flags = gidAndFlags.Flags;
            short GID = gidAndFlags.Gid;

            // Vertical
            if ((flags & CCTileFlags.Vertical) != 0)
                flags &= ~CCTileFlags.Vertical;
            else
                flags |= CCTileFlags.Vertical;


            layer.SetTileGID(new CCTileGidAndFlags(GID, flags), tileCoord);


            tileCoord = new CCTileMapCoordinates(1, 8);
            gidAndFlags = layer.TileGIDAndFlags(tileCoord);
            GID = gidAndFlags.Gid;
            flags = gidAndFlags.Flags;

            // Vertical
            if ((flags & CCTileFlags.Vertical) != 0)
                flags &= ~CCTileFlags.Vertical;
            else
                flags |= CCTileFlags.Vertical;

            layer.SetTileGID(new CCTileGidAndFlags(GID, flags), tileCoord);

            tileCoord = new CCTileMapCoordinates(2, 8);
            gidAndFlags = layer.TileGIDAndFlags(tileCoord);
            GID = gidAndFlags.Gid;
            flags = gidAndFlags.Flags;

            // Horizontal
            if ((flags & CCTileFlags.Horizontal) != 0)
                flags &= ~CCTileFlags.Horizontal;
            else
                flags |= CCTileFlags.Horizontal;

            layer.SetTileGID(new CCTileGidAndFlags(GID, flags), tileCoord);
        }
        public void SetTileGID(CCTileGidAndFlags gidAndFlags, CCTileMapCoordinates tileCoords)
        {
            if (gidAndFlags.Gid == 0 || gidAndFlags.Gid < TileSetInfo.FirstGid)
            {
                Debug.Assert (false, String.Format("CCTileMapLayer: SetTileGID: Invalid GID %n", gidAndFlags.Gid));
                return;
            }

            if (AreValidTileCoordinates(tileCoords) == false)
            {
                Debug.Assert (false, String.Format("CCTileMapLayer: Invalid tile coordinates row: %n column: %n", 
                    tileCoords.Row, tileCoords.Column));
                return;
            }

            CCTileGidAndFlags currentGID = TileGIDAndFlags(tileCoords);

            if(currentGID == gidAndFlags)
                return;

            SetBatchRenderedTileGID(tileCoords.Column, tileCoords.Row, gidAndFlags);
        }
 CCTileMapLayer(CCTileSetInfo tileSetInfo, CCTileLayerInfo layerInfo, CCTileMapInfo mapInfo, CCTileMapCoordinates layerSize, int totalNumberOfTiles) 
     : this(tileSetInfo, layerInfo, mapInfo, layerSize, totalNumberOfTiles, (int)(totalNumberOfTiles * 0.35f + 1), 
         CCTextureCache.SharedTextureCache.AddImage(tileSetInfo.TilesheetFilename))
 {
 }
Exemple #38
0
 /// <summary>
 /// Sets the building in the map.
 /// </summary>
 /// <param name="mapCoordinat">Map coordinate.</param>
 /// <param name="building">Building which should be drawn (or null if it should be erased).</param>
 public void SetBuilding(CCTileMapCoordinates mapCoordinat, Entity building)
 {
     if (building == null)
     {
         m_buildingLayer.SetTileGID(CCTileGidAndFlags.EmptyTile, mapCoordinat);               
     }
     else
     {
         var sort = ViewDefinitions.Sort.Normal;
         if (GameAppDelegate.Account != building.Owner)
         {
             sort = ViewDefinitions.Sort.Enemy;
         }
         var gid = ViewDefinitions.Instance.DefinitionToTileGid(building.Definition, sort);
         m_buildingLayer.SetTileGID(gid, mapCoordinat);
     }                
 }
 bool AreValidTileCoordinates(CCTileMapCoordinates tileCoords)
 {
     return AreValidTileCoordinates(tileCoords.Column, tileCoords.Row);
 }
Exemple #40
0
 CCTileMapLayer(CCTileSetInfo tileSetInfo, CCTileLayerInfo layerInfo, CCTileMapInfo mapInfo, CCTileMapCoordinates layerSize, int totalNumberOfTiles)
     : this(tileSetInfo, layerInfo, mapInfo, layerSize, totalNumberOfTiles, (int)(totalNumberOfTiles * 0.35f + 1),
            CCTextureCache.SharedTextureCache.AddImage(tileSetInfo.TilesheetFilename))
 {
 }
 public CCSprite ExtractTile(CCTileMapCoordinates tileCoords, bool addToTileMapLayer = true)
 {
     return ExtractTile(tileCoords.Column, tileCoords.Row, addToTileMapLayer);
 }
        CCPoint LayerOffset(CCTileMapCoordinates tileCoords)
        {
            CCPoint offsetInNodespace = CCPoint.Zero;
            switch (MapType)
            {
                case CCTileMapType.Ortho:
                    offsetInNodespace = new CCPoint(tileCoords.Column * TileTexelSize.Width, -tileCoords.Row * TileTexelSize.Height);
                    break;
                case CCTileMapType.Iso:
                    offsetInNodespace = new CCPoint((TileTexelSize.Width / 2) * (tileCoords.Column - tileCoords.Row),
                    (TileTexelSize.Height / 2) * (-tileCoords.Column - tileCoords.Row));
                    break;
                case CCTileMapType.Staggered:
                    float diffX = 0;
                    if ((int)tileCoords.Row % 2 == 1)
                        diffX = TileTexelSize.Width / 2;

                    offsetInNodespace = new CCPoint(tileCoords.Column * TileTexelSize.Width + diffX,
                        -tileCoords.Row * TileTexelSize.Height / 2);
                    break;
                case CCTileMapType.Hex:
                    break;
            }

            offsetInNodespace *= CCTileMapLayer.DefaultTexelToContentSizeRatios;

            return offsetInNodespace;
        }
 public CCPoint TilePosition(CCTileMapCoordinates tileCoords)
 {
     return tileCoordsToNodeTransform.Transform(tileCoords.Point);
 }
 //helper function for getSurroundingTilesWithProperties - also can be used individually
 //check a single tile if it satisfies a certain condition ie "walkable" == "true"
 public static Boolean checkSingleTileWithProperties(CCTileMapCoordinates checkTile,string property, string value)
 {
     CCTileGidAndFlags info;
     Dictionary<string, string> properties;
     foreach (CCTileMapLayer layer in map.TileLayersContainer.Children)
     {
         try
         {
             info = layer.TileGIDAndFlags(checkTile.Column, checkTile.Row);
             properties = map.TilePropertiesForGID(info.Gid);
             if (properties.ContainsKey(property) && properties[property] == value)
             {
                 return true;
             }
                 
         }
         catch { }
     }
     return false;
     
 }
 public void RemoveTile(CCTileMapCoordinates tileCoords)
 {
     RemoveTile(tileCoords.Column, tileCoords.Row);
 }
Exemple #46
0
        // Private constructor chaining

        CCTileMapLayer(CCTileSetInfo[] tileSetInfos, CCTileLayerInfo layerInfo, CCTileMapInfo mapInfo, CCTileMapCoordinates layerSize)
            : this(tileSetInfos, layerInfo, mapInfo, layerSize, (int)(layerSize.Row * layerSize.Column))
        {
        }
 void UpdateQuadAt(CCTileMapCoordinates tileCoords, bool updateBuffer = true)
 {
     UpdateQuadAt(tileCoords.Column, tileCoords.Row, updateBuffer);
 }
Exemple #48
0
 CCTileMapLayer(CCTileSetInfo[] tileSetInfos, CCTileLayerInfo layerInfo, CCTileMapInfo mapInfo, CCTileMapCoordinates layerSize, int totalNumberOfTiles)
     : this(tileSetInfos, layerInfo, mapInfo, layerSize, totalNumberOfTiles, (int)(totalNumberOfTiles * 0.35f + 1))
 {
 }
Exemple #49
0
 /// <summary>
 /// Clears the Layers for initialization.
 /// </summary>
 private void ClearLayers()
 {
     var coordHelper = new CCTileMapCoordinates(0, 0);
     m_buildingLayer.RemoveTile(coordHelper);
     m_menueLayer.RemoveTile(coordHelper);
     m_indicatorLayer.RemoveTile(coordHelper);
 }
Exemple #50
0
 bool AreValidTileCoordinates(CCTileMapCoordinates tileCoords)
 {
     return(AreValidTileCoordinates(tileCoords.Column, tileCoords.Row));
 }