예제 #1
0
        /// <summary>
        /// Converts a cell position to a tile position (which is a position relative to the region position)
        /// </summary>
        /// <returns>The tile position.</returns>
        /// <param name="cell">Cell position.</param>
        public static CCPoint CellToTile(CellPosition cell)
        {
            var regionSize = new CCSize(
                                 ClientConstants.TILEMAP_HEX_CONTENTSIZE_WIDTH,
                                 ClientConstants.TILEMAP_HEX_CONTENTSIZE_HEIGHT);
            var tilePercent = new CCPoint(
                (float)cell.CellX / Core.Models.Constants.REGION_SIZE_X,
                (Core.Models.Constants.REGION_SIZE_Y - (float)cell.CellY) / Core.Models.Constants.REGION_SIZE_Y);

            var tileCoord = tilePercent * regionSize;
            // if it is an odd tile, it is an half tile below the even tiles
            if ((cell.CellX % 2) == 1)
            {
                var tileHeight = regionSize.Height / ClientConstants.TILEMAP_HEX_HEIGHT;
                tileCoord.Y -= tileHeight / 2;
            }

            return tileCoord;
        }
예제 #2
0
 /// <summary>
 /// Sets the terrain tile in map.
 /// </summary>
 /// <param name="cellPosition">Cell position.</param>
 private void SetTerrainTileInMap(CellPosition cellPosition)
 {
     var region = (Region)this.Model;
     var gid = Client.Common.Views.ViewDefinitions.Instance.DefinitionToTileGid(region.GetTerrain(cellPosition));
     m_terrainLayer.SetTileGID(gid, new CCTileMapCoordinates(cellPosition.CellX, cellPosition.CellY));
 }
예제 #3
0
        /// <summary>
        /// Sets the tiles in a 32x32 map.
        /// </summary>
        private void SetTilesInMap32()
        {
            for (int y = 0; y < Constants.REGION_SIZE_Y; y++)
            {
                for (int x = 0; x < Constants.REGION_SIZE_X; x++)
                {
                    var newCellPosition = new CellPosition(x, y);

                    SetTerrainTileInMap(newCellPosition); 
                }
            }
            LoadEntities(); 
        }
예제 #4
0
 /// <summary>
 /// Sets the indicator gid.
 /// </summary>
 /// <returns>The indicator gid.</returns>
 /// <param name="cellPos">The cell position.</param>
 /// <param name="gid">The gid.</param>
 public CCSprite SetIndicatorGid(CellPosition cellPos, CCTileGidAndFlags gid)
 {            
     m_indicatorLayer.SetTileGID(gid, new CCTileMapCoordinates(cellPos.CellX, cellPos.CellY));
     var sprite = m_indicatorLayer.ExtractTile(new CCTileMapCoordinates(cellPos.CellX, cellPos.CellY), true);
     sprite.Opacity = HelperSpritesGid.INDICATOR_OPACITY;
     return sprite;
 }
예제 #5
0
파일: Position.cs 프로젝트: Lopt/ascendancy
 /// <summary>
 /// Initializes a new instance of the <see cref="Core.Models.Position"/> class.
 /// </summary>
 /// <param name="regionPosition">Region position.</param>
 /// <param name="cellPosition">Cell position.</param>
 public Position(RegionPosition regionPosition, CellPosition cellPosition)
 {
     X = (regionPosition.RegionX * Constants.REGION_SIZE_X) + cellPosition.CellX;
     Y = (regionPosition.RegionY * Constants.REGION_SIZE_Y) + cellPosition.CellY;
 }
예제 #6
0
        /// <summary>
        /// Converts the given world space position to a PositionI
        /// </summary>
        /// <returns>PositionI of the given world space.</returns>
        /// <param name="point">Point which should be converted.</param>
        /// <param name="worldLayer">World layer.</param>
        public static PositionI WorldspaceToPositionI(CCPoint point, WorldLayerHex worldLayer)
        {
            var regionPos = WorldspaceToRegion(point);
            var startRegionPoint = RegionToWorldspace(regionPos);
            var regionView = worldLayer.GetRegionViewHex(regionPos);

            if (regionView != null)
            {
                var tileCoord = regionView.GetTileMap().LayerNamed(ClientConstants.LAYER_TERRAIN).ClosestTileCoordAtNodePosition(point - startRegionPoint);
                tileCoord.Row = Math.Max(tileCoord.Row, -tileCoord.Row);
                tileCoord.Column = Math.Max(tileCoord.Column, -tileCoord.Column);
                var cellPos = new CellPosition(
                    tileCoord.Column % Constants.REGION_SIZE_X,
                    tileCoord.Row % Constants.REGION_SIZE_Y);

                return new PositionI(regionPos, cellPos);
            }
            return null;
        }
예제 #7
0
파일: Region.cs 프로젝트: Lopt/ascendancy
 /// <summary>
 /// Returns the TerrainDefinition of the given CellPosition
 /// </summary>
 /// <returns>Returns the TerrainDefinition of the specific given cellPosition.</returns>
 /// <param name="cellPosition">Cell position.</param>
 public TerrainDefinition GetTerrain(CellPosition cellPosition)
 {
     var value = m_terrains[cellPosition.CellX, cellPosition.CellY];
     // standardvalue
     if (value == null)
     {
         return (TerrainDefinition)World.Instance.DefinitionManager.GetDefinition(EntityType.Forbidden);
     }
     return value;
 }
예제 #8
0
파일: Region.cs 프로젝트: Lopt/ascendancy
 /// <summary>
 /// Returns Buildings or Units at the given position
 /// </summary>
 /// <returns>The entity or null when there was no entity.</returns>
 /// <param name="cellPosition">Cell position.</param>
 public Entity GetEntity(CellPosition cellPosition)
 {
     foreach (var entity in m_entities.Entities)
     {
         if (entity.Position.CellPosition == cellPosition)
         {
             return entity;
         }
     }
     return null;
 }
예제 #9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Core.Models.Position"/> class.
 /// </summary>
 /// <param name="regionPosition">Region position.</param>
 /// <param name="cellPosition">Cell position.</param>
 public Position(RegionPosition regionPosition, CellPosition cellPosition)
 {
     X = (regionPosition.RegionX * Constants.REGION_SIZE_X) + cellPosition.CellX;
     Y = (regionPosition.RegionY * Constants.REGION_SIZE_Y) + cellPosition.CellY;
 }