Exemple #1
0
        /// <summary>
        /// 指定位置のMapの内容を調べる
        /// </summary>
        /// <param name="pos">位置</param>
        /// <returns>内容</returns>
        public int GetBlockData(Vector2 pos)
        {
            BlockIndex blockIndex = GetBlockIndex(pos);

            //調べたい位置は地図外とすると、-1(内容なし)を返す
            if (blockIndex.X == -1 || blockIndex.Y == -1)
            {
                return(-1);
            }
            else
            {
                return(Data[blockIndex.Y, blockIndex.X]);
            }
        }
Exemple #2
0
        /// <summary>
        /// 指定位置からBlockのIndexを調べる
        /// </summary>
        /// <param name="pos">調べたい位置</param>
        /// <returns>その位置のBlockIndex</returns>
        public BlockIndex GetBlockIndex(Vector2 pos)
        {
            float      x          = pos.X / BlockSize;
            float      y          = pos.Y / BlockSize;
            BlockIndex blockIndex = new BlockIndex(0, 0);

            // 範囲のチェック
            if (x < 0 || x >= HorizontalBlockNum || y < 0 || y >= VerticalBlockNum)
            {
                // 範囲外
                blockIndex.SetIndex(-1, -1);
            }
            else
            {
                blockIndex.SetIndex((int)x, (int)y);
            }

            return(blockIndex);
        }
Exemple #3
0
        /// <summary>
        /// その位置は指定の地形であるかどうかを調べる
        /// </summary>
        /// <param name="pos">位置</param>
        /// <param name="blockIndex">その位置のBlockIndexを返す</param>
        /// <param name="data">指定の地形種類の配列</param>
        /// <returns></returns>
        public bool IsInBlock(Vector2 pos, ref Vector2 blockPos, int[] data)
        {
            BlockIndex blockIndex = GetBlockIndex(pos);
            bool       flag       = false;

            if (blockIndex.X == -1 || blockIndex.Y == -1)
            {
                return(false);
            }

            foreach (var d in data)
            {
                if (d == Data[blockIndex.Y, blockIndex.X])
                {
                    flag     = true;
                    blockPos = GetBlockPosition(blockIndex);
                    break;
                }
            }

            return(flag);
        }
Exemple #4
0
        /// <summary>
        /// 指定BlockIndexから、位置を調べる
        /// </summary>
        /// <param name="blockIndex">調べたいBlockIndex</param>
        /// <returns>その位置</returns>
        public Vector2 GetBlockPosition(BlockIndex blockIndex)
        {
            Vector2 pos = new Vector2(blockIndex.X * BlockSize, blockIndex.Y * BlockSize);

            return(pos);
        }