コード例 #1
0
ファイル: Map.cs プロジェクト: chasay2002/UATanks
        private void SpawnRemainingTiles(List <Tile> activeTiles)
        {
            int  currentIndex = activeTiles.Count - 1;
            Tile currentTile  = activeTiles[currentIndex];

            if (currentTile.IsInitialized)
            {
                activeTiles.RemoveAt(currentIndex);
                return;
            }

            Enums.CardinalDirection direction = currentTile.GetRandomUnintializedDirection();
            MapVector2 newTilePosition        = currentTile.TilePosition + direction.ToMapVector2();

            if (this.IsValidCoordinate(newTilePosition))
            {
                Tile neighbor = GetTile(newTilePosition);

                if (neighbor == null)
                {
                    neighbor = CreateTile(newTilePosition);
                    BuildConnector(currentTile, neighbor, direction);
                    activeTiles.Add(neighbor);
                }
                else
                {
                    BuildWall(currentTile, neighbor, direction);
                }
            }
            else
            {
                BuildWall(currentTile, null, direction);
            }
        }
コード例 #2
0
 int GetWayIndex(MapVector2 start, MapVector2 end)
 {
     if (start.x != end.x)
     {
         if (start.x > end.x)
         {
             return(0);
         }
         else
         {
             return(2);
         }
     }
     else
     {
         if (start.y < end.y)
         {
             return(1);
         }
         else
         {
             return(3);
         }
     }
 }
コード例 #3
0
ファイル: Map.cs プロジェクト: chasay2002/UATanks
        private Tile CreateTile(MapVector2 cellPosition)
        {
            Tile newTile;

            switch (Random.Range(0, 2))
            {
            case 0:
                newTile = Instantiate(Resources.Load <GameObject>("Blocks/Arena")).GetComponent <Tile>();
                break;

            case 1:
                newTile = Instantiate(Resources.Load <GameObject>("Blocks/Pipes")).GetComponent <Tile>();
                break;

            default:
                newTile = Instantiate(Resources.Load <GameObject>("Blocks/Arena")).GetComponent <Tile>();
                break;
            }

            this.TileMap[cellPosition.x, cellPosition.z] = newTile;

            newTile.TilePosition            = new MapVector2(cellPosition.x, cellPosition.z);
            newTile.name                   += " Tile " + cellPosition.x + ", " + cellPosition.z;
            newTile.transform.parent        = this.transform;
            newTile.transform.localPosition = new Vector3(cellPosition.x * 75, 0f, cellPosition.z * 75);

            return(newTile);
        }
コード例 #4
0
ファイル: Npc_Protocol.cs プロジェクト: zuojiashun/src
    public void Execute(GameCmd.stNpcMoveMoveUserCmd cmd)
    {
        IEntitySystem es = ClientGlobal.Instance().GetEntitySystem();

        if (es == null)
        {
            Engine.Utility.Log.Error("严重错误:EntitySystem is null!");
            return;
        }

        MapVector2 mapPos = MapVector2.FromCoordinate(cmd.dst_x, cmd.dst_y);
        Vector3    pos    = new Vector3(mapPos.x, 0, -mapPos.y); // 服务器到客户端坐标转换
        IEntity    en     = null;

        en = es.FindNPC(cmd.dwNpcTempID);
        if (en == null)
        {
            //Engine.Utility.Log.Info("机器人 移动pos {0}", pos);
            en = es.FindRobot(cmd.dwNpcTempID);
        }
        if (en != null)
        {
            Engine.Utility.Log.LogGroup("XXF", "{0}Move to{1},{2}", en.GetName(), pos.x, pos.z);

            Move move = new Move();
            //move.m_dir = Global.S2CDirection(cmd.dir);
            move.strRunAct = EntityAction.Run; // 动作名需要统一处理
            move.m_target  = pos;
            move.m_speed   = en.GetProp((int)WorldObjProp.MoveSpeed) * EntityConst.MOVE_SPEED_RATE;
            // Log.Error( "npc pos is" + pos.ToString() );
            en.SendMessage(EntityMessage.EntityCommand_MoveTo, (object)move);
        }
    }
コード例 #5
0
    public bool canMove(Direction direction)
    {
        MapVector2 tryMovePos = GetPositionAfterTryMove(direction);

        if (tryMovePos.x < 0 || tryMovePos.x >= MapManager.I.MapSize.x ||
            tryMovePos.y < 0 || tryMovePos.y >= MapManager.I.MapSize.y)
        {
            return(false);
        }
        BoxUnit box = BoxManager.I.ExistBoxAtPos(tryMovePos);

        if (box != null)
        {
            Debug.Log("运动方向上有box");
            if (!box.canMove(direction))
            {
                return(false);
            }
        }
        ElementType element = MapManager.I.GetElementAt(tryMovePos.x, tryMovePos.y);

        if (element == ElementType.Wall)
        {
            return(false);
        }
        return(true);
    }
コード例 #6
0
ファイル: Map.cs プロジェクト: chasay2002/UATanks
 private bool IsValidCoordinate(MapVector2 vector)
 {
     return(vector.x >= 0 &&
            vector.x < this.MapSize.x &&
            vector.z >= 0 &&
            vector.z < this.MapSize.z);
 }
コード例 #7
0
    public MapVector2 GetPositionAfterTryMove(Direction direction)
    {
        MapVector2 rtn = new MapVector2();

        switch (direction)
        {
        case Direction.Left:
            rtn = new MapVector2(-1, 0);
            break;

        case Direction.Up:
            rtn = new MapVector2(0, 1);
            break;

        case Direction.Right:
            rtn = new MapVector2(1, 0);
            break;

        case Direction.Down:
            rtn = new MapVector2(0, -1);
            break;
        }
        rtn.x += Mathf.RoundToInt(Position.x);
        rtn.y += Mathf.RoundToInt(Position.y);
        return(rtn);
    }
コード例 #8
0
ファイル: MapGrid.cs プロジェクト: sjb8100/src
 // 转换成格子坐标
 public static MapGrid GetMapGrid(MapVector2 pos)
 {
     return(new MapGrid()
     {
         x = (int)(pos.x / Width), z = (int)(pos.y / Height)
     });
 }
コード例 #9
0
ファイル: MapLayer.cs プロジェクト: tianjihx/RollBox
    public void CreateUnit(BlockUnit template, MapVector2 pos)
    {
        BlockUnit newUnit = Instantiate(template.gameObject).GetComponent <BlockUnit>();

        newUnit.transform.SetParent(transform);
        newUnit.Position = new Vector3(pos.x, pos.y, m_Floor);
    }
コード例 #10
0
    /// <summary>
    /// Inits the map.
    /// </summary>
    /// <param name="group">Group type id.</param>
    /// <param name="row">Row 每行的group数量.</param>
    /// <param name="col">Col 每列的group数量.</param>
    public override void InitMap(int group, int row, int col)
    {
        base.InitMap(group, row * GameConst.RANDOM_GROUP_SIZE, col * GameConst.RANDOM_GROUP_SIZE);

        i_mapmaindepth = row * col / 2;
        maparr         = new int[row, col];

        Dictionary <string, List <MapGroupConf> > conflist = ConfigManager.mapGroupConfManager.dataWayGroupMap[group];

        if (conflist == null && conflist.Count <= 0)
        {
            Debug.LogError("no map conf!! group : " + group);
            return;
        }
        //随机地图
        MapVector2 startPos = new MapVector2(Random.Range(0, row), Random.Range(0, col));

        mapTree          = new MapTree(startPos);
        mapTree.treetype = MapTree.MapTreeType.start;
        maparr[startPos.x, startPos.y] = 1;
        this.i_mapBreathCount++;
        RandomMap(this.mapTree);

        Debug.Log(LitJson.JsonMapper.ToJson(maparr));

        //for (int i = 0; i < maparr.GetLength(0); i++)
        //{
        //    for (int j = 0; j < maparr.GetLength(1); j++)
        //    {
        //        if (maparr[i, j] > 0)
        //        {
        //            string waystring = GetWayString(i,j);

        //if(!conflist.ContainsKey(waystring)){

        //    Debug.Log(" no group : " + waystring);
        //    continue;
        //}
        //List<MapGroupConf> mapList = conflist[waystring];
        //if (mapList.Count <= 0) {
        //    Debug.Log(" no group : " + waystring);
        //    continue;
        //}
        //InsertGroup(new Vector2(i*GameConst.RANDOM_GROUP_SIZE, j*GameConst.RANDOM_GROUP_SIZE), mapList[Random.Range(0,mapList.Count)].id);
        //        }
        //    }
        //}

        GenerateGroup(mapTree);

        if (startPointList.Count > 0)
        {
            startPoint = startPointList[Random.Range(0, startPointList.Count)];
        }
        else
        {
            startPoint = GetRandomWay();
        }
    }
コード例 #11
0
ファイル: BoxManager.cs プロジェクト: tianjihx/RollBox
    public BoxUnit CreateBox(MapVector2 pos, Color color)
    {
        BoxUnit newUnit = Instantiate(m_BoxUnitTemplate.gameObject).GetComponent <BoxUnit>();

        newUnit.Position      = new Vector3(pos.x, pos.y, m_Floor);
        newUnit.PositionInMap = pos;
        return(newUnit);
    }
コード例 #12
0
 public void addElement(MapVector2 pos, ElementType type)
 {
     if (!elementDict.ContainsKey(pos))
     {
         elementDict.Add(pos, type);
     }
     else
     {
         Debug.LogError(pos + "已经存在元素" + type.ToString() + ",请勿重复添加!");
     }
 }
コード例 #13
0
 public void addTerrain(MapVector2 pos, TerrainType type)
 {
     if (!terrainDict.ContainsKey(pos))
     {
         terrainDict.Add(pos, type);
     }
     else
     {
         Debug.LogError(pos + "已经存在地形" + type.ToString() + ",请勿重复添加!");
     }
 }
コード例 #14
0
ファイル: MapManager.cs プロジェクト: tianjihx/RollBox
    public void LoadMap(MapDescription desc)
    {
        mapSize = desc.Size;
        //加载地形
        m_Terrain.Size = MapSize;
        terrainLayer   = new TerrainType[MapSize.x, MapSize.y];
        generateTerrain(desc.terrainDict);

        //加载元素
        m_Element.Size = MapSize;
        elementLayer   = new ElementType[MapSize.x, MapSize.y];
        generateElement(desc.elementDict);
    }
コード例 #15
0
ファイル: BoxManager.cs プロジェクト: tianjihx/RollBox
 /// <summary>
 /// 检查指定底图位置上是否有箱子,有的话返回这个箱子
 /// </summary>
 /// <param name="pos">要检查的位置</param>
 public BoxUnit ExistBoxAtPos(MapVector2 pos)
 {
     Debug.Log("检查运动路径有没有箱子");
     foreach (var box in boxList)
     {
         Debug.Log("box:" + box.PositionInMap);
         Debug.Log("pos:" + pos);
         if (box.PositionInMap == pos)
         {
             return(box);
         }
     }
     return(null);
 }
コード例 #16
0
    public void MoveDirection(Direction direction)
    {
        if (IsMoving)
        {
            return;
        }
        if (!canMove(direction))
        {
            return;
        }
        IsMoving = true; //start move to direction
        Vector3 axis            = Vector3.up;
        Vector3 aroundPointSlef = Vector3.zero;

        switch (direction)
        {
        case Direction.Left:
            axis            = Vector3.forward;
            aroundPointSlef = new Vector3(-0.5f, -0.5f, 0);
            PositionInMap  += new MapVector2(-1, 0);
            break;

        case Direction.Up:
            axis            = Vector3.right;
            aroundPointSlef = new Vector3(0, -0.5f, 0.5f);
            PositionInMap  += new MapVector2(0, 1);
            break;

        case Direction.Right:
            axis            = Vector3.back;
            aroundPointSlef = new Vector3(0.5f, -0.5f, 0);
            PositionInMap  += new MapVector2(1, 0);
            break;

        case Direction.Down:
            axis            = Vector3.left;
            aroundPointSlef = new Vector3(0, -0.5f, -0.5f);
            PositionInMap  += new MapVector2(0, -1);
            break;
        }
        StartCoroutine(rotateAround(aroundPointSlef, axis, 90f, m_Duration));
    }
コード例 #17
0
ファイル: Map.cs プロジェクト: chasay2002/UATanks
 private Tile GetTile(MapVector2 cellPosition)
 {
     return(this.TileMap[cellPosition.x, cellPosition.z]);
 }
コード例 #18
0
ファイル: BoxManager.cs プロジェクト: tianjihx/RollBox
    public void AddBox(MapVector2 spawnPos)
    {
        var box = CreateBox(spawnPos, Color.red);

        boxList.Add(box);
    }
コード例 #19
0
 public MapTree(MapVector2 pos)
 {
     this.pos = pos;
 }