コード例 #1
0
        public void DoAfterInit()
        {
            for (int i = 0; i < gridInfo.tileMaps.Length; i++)
            {
                var tilemap = gridInfo.tileMaps[i];
                if (tilemap.isTagMap)
                {
                    continue;
                }
                var tilemapMin  = tilemap.min;
                var tilemapSize = tilemap.size;
                mapDataMin.x = LMath.Min(mapDataMin.x, tilemapMin.x);
                mapDataMin.y = LMath.Min(mapDataMin.y, tilemapMin.y);
                mapDataMax.x = LMath.Max(mapDataMax.y, tilemapMin.x + tilemapSize.x);
                mapDataMax.y = LMath.Max(mapDataMax.y, tilemapMin.y + tilemapSize.y);
            }

            mapDataSize = (mapDataMax - mapDataMin) + LVector2Int.one;
            mapDataIds  = new ushort[mapDataSize.x, mapDataSize.y];
            for (int x = 0; x < mapDataSize.x; x++)
            {
                for (int y = 0; y < mapDataSize.y; y++)
                {
                    var pos = new Vector2Int(mapDataMin.x + x, mapDataMin.y + y);
                    mapDataIds[x, y] = RawPos2TileId(pos, true);
                }
            }
        }
コード例 #2
0
 public CmdSetTile(TileInfos tilemap, LVector2Int pos, ushort srcId, ushort dstId)
 {
     this.tilemap = tilemap;
     this.pos     = pos;
     this.srcId   = srcId;
     this.dstId   = dstId;
 }
コード例 #3
0
 public void DoAfterInit()
 {
     for (int i = 0; i < this.gridInfo.tileMaps.Length; i++)
     {
         TileInfos tileInfos = this.gridInfo.tileMaps[i];
         bool      isTagMap  = tileInfos.isTagMap;
         if (!isTagMap)
         {
             LVector2Int min  = tileInfos.min;
             LVector2Int size = tileInfos.size;
             this.mapDataMin.x = LMath.Min(this.mapDataMin.x, min.x);
             this.mapDataMin.y = LMath.Min(this.mapDataMin.y, min.y);
             this.mapDataMax.x = LMath.Max(this.mapDataMax.y, min.x + size.x);
             this.mapDataMax.y = LMath.Max(this.mapDataMax.y, min.y + size.y);
         }
     }
     this.mapDataSize = this.mapDataMax - this.mapDataMin + LVector2Int.one;
     this.mapDataIds  = new ushort[this.mapDataSize.x, this.mapDataSize.y];
     for (int j = 0; j < this.mapDataSize.x; j++)
     {
         for (int k = 0; k < this.mapDataSize.y; k++)
         {
             LVector2Int pos = new LVector2Int(mapDataMin.x + j, mapDataMin.y + k);
             this.mapDataIds[j, k] = this.RawPos2TileId(pos, false);
         }
     }
 }
コード例 #4
0
        public LFloat GetMaxMoveDist(EDir dir, LVector2 fHeadPos, LVector2 fTargetHeadPos, LFloat borderSize)
        {
            var iTargetHeadPos =
                new LVector2Int(LMath.FloorToInt(fTargetHeadPos.x), LMath.FloorToInt(fTargetHeadPos.y));
            var hasCollider = HasColliderWithBorder(dir, fTargetHeadPos, borderSize);
            var maxMoveDist = LFloat.MaxValue;

            if (hasCollider)
            {
                switch (dir)
                {
                case EDir.Up:
                    maxMoveDist = iTargetHeadPos.y - fHeadPos.y;
                    break;

                case EDir.Right:
                    maxMoveDist = iTargetHeadPos.x - fHeadPos.x;
                    break;

                case EDir.Down:
                    maxMoveDist = fHeadPos.y - iTargetHeadPos.y - 1;
                    break;

                case EDir.Left:
                    maxMoveDist = fHeadPos.x - iTargetHeadPos.x - 1;
                    break;
                }
            }

            return(maxMoveDist);
        }
コード例 #5
0
        public static void CheckBulletWithMap(LVector2Int iPos, GameEntity entity, IGameAudioService audioService, IMap2DService map2DService)
        {
            var unit   = entity.unit;
            var bullet = entity.bullet;
            var id     = map2DService.Pos2TileId(iPos, false);

            if (id != 0 && unit.health > 0)
            {
                //collide bullet with world
                if (id == TilemapUtil.TileID_Brick)
                {
                    if (unit.camp == ECampType.Player)
                    {
                        audioService.PlayClipHitBrick();
                    }

                    map2DService.ReplaceTile(iPos, id, 0);
                    unit.health--;
                }
                else if (id == TilemapUtil.TileID_Iron)
                {
                    if (!bullet.canDestoryIron)
                    {
                        if (unit.camp == ECampType.Player)
                        {
                            audioService.PlayClipHitIron();
                        }

                        unit.health = 0;
                    }
                    else
                    {
                        if (unit.camp == ECampType.Player)
                        {
                            audioService.PlayClipDestroyIron();
                        }

                        unit.health = LMath.Max(unit.health - 2, 0);
                        map2DService.ReplaceTile(iPos, id, 0);
                    }
                }
                else if (id == TilemapUtil.TileID_Grass)
                {
                    if (bullet.canDestoryGrass)
                    {
                        if (unit.camp == ECampType.Player)
                        {
                            audioService.PlayClipDestroyGrass();
                        }

                        unit.health -= 0;
                        map2DService.ReplaceTile(iPos, id, 0);
                    }
                }
                else if (id == TilemapUtil.TileID_Wall)
                {
                    unit.health = 0;
                }
            }
        }
コード例 #6
0
ファイル: Utils.cs プロジェクト: tuita520/LockstepPlatform
 public static bool TestCollision(Circle a, LVector2Int vec)
 {
     return(TestCircleAABB(
                a.pos, a.radius,                                      //Circle1
                new LVector2(true, vec.x * LFloat.Precision, vec.y * LFloat.Precision)
                + LVector2.half, new LFloat(true, 707), LVector2.half //AABB2
                ));
 }
コード例 #7
0
        public void ReplaceTile(LVector2Int pos, ushort srcId, ushort dstId)
        {
            bool flag = pos.x > this.mapDataMax.x || pos.x <this.mapDataMin.x || pos.y> this.mapDataMax.y || pos.y < this.mapDataMin.y;

            if (!flag)
            {
                LVector2Int lvector2Int = pos - this.mapDataMin;
                this.mapDataIds[lvector2Int.x, lvector2Int.y] = dstId;
                this.OnReplaceTile(pos, srcId, dstId);
            }
        }
コード例 #8
0
        public ushort Pos2TileId(LVector2Int pos, bool isCollider)
        {
            if (pos.x > mapDataMax.x || pos.x < mapDataMin.x ||
                pos.y > mapDataMax.y || pos.y < mapDataMin.y)
            {
                return(0);
            }
            var diff = pos - mapDataMin;

            return(mapDataIds[diff.x, diff.y]);
        }
コード例 #9
0
        public void ReplaceTile(LVector2Int pos, ushort srcId, ushort dstId)
        {
            if (pos.x > mapDataMax.x || pos.x < mapDataMin.x ||
                pos.y > mapDataMax.y || pos.y < mapDataMin.y)
            {
                return;
            }
            var diff = pos - mapDataMin;

            mapDataIds[diff.x, diff.y] = dstId;
            OnReplaceTile(pos, srcId, dstId);
        }
コード例 #10
0
 private void OnReplaceTile(LVector2Int pos, ushort srcId, ushort dstId)
 {
     for (int i = 0; i < this.gridInfo.tileMaps.Length; i++)
     {
         TileInfos tileInfos = this.gridInfo.tileMaps[i];
         ushort    tileID    = tileInfos.GetTileID(pos);
         bool      flag      = tileID == srcId;
         if (flag)
         {
             this.cmdBuffer.Execute(base.CurTick, new BaseMap2DService.CmdSetTile(tileInfos, pos, srcId, dstId));
         }
     }
 }
コード例 #11
0
        public bool IsOutOfBound(LVector2 fpos, LVector2Int min, LVector2Int max)
        {
            var pos = fpos.Floor();

            if (pos.x < min.x || pos.x > max.x ||
                pos.y < min.y || pos.y > max.y
                )
            {
                return(true);
            }

            return(false);
        }
コード例 #12
0
        public void Execute()
        {
            foreach (var entity in _AIGroup.GetEntities())
            {
                var aiInfo = entity.aI;
                aiInfo.timer += _gameStateService.DeltaTime;
                if (aiInfo.timer < aiInfo.updateInterval)
                {
                    continue;
                }

                aiInfo.timer = LFloat.zero;
                LVector2Int dir           = LVector2Int.zero;
                var         curPos        = entity.pos.value;
                var         headPos       = TankUtil.GetHeadPos(entity.pos.value, entity.dir.value);
                var         isReachTheEnd = _gameCollisionService.HasColliderWithBorder(entity.dir.value, headPos);
                if (isReachTheEnd)
                {
                    List <int> allWalkableDir = new List <int>();
                    for (int i = 0; i < (int)(EDir.EnumCount); i++)
                    {
                        var vec = DirUtil.GetDirLVec((EDir)i) * TankUtil.TANK_HALF_LEN;
                        var pos = curPos + vec;
                        if (!_gameCollisionService.HasCollider(pos))
                        {
                            allWalkableDir.Add(i);
                        }
                    }

                    var count = allWalkableDir.Count;
                    if (count > 0)
                    {
                        entity.dir.value         = (EDir)(allWalkableDir[_randomService.Range(0, count)]);
                        entity.move.isChangedDir = true;
                    }
                }

                //Fire skill
                var isNeedFire = _randomService.value < aiInfo.fireRate;
                if (isNeedFire)
                {
                    if (entity.skill.cdTimer <= LFloat.zero)
                    {
                        entity.skill.cdTimer = entity.skill.cd;
                        //Fire
                        _gameUnitService.CreateBullet(entity.pos.value, entity.dir.value, (ushort)entity.skill.bulletId,
                                                      entity);
                    }
                }
            }
        }
コード例 #13
0
        private void OnReplaceTile(LVector2Int pos, ushort srcId, ushort dstId)
        {
            var uPos = pos.ToVector2Int();

            for (int i = 0; i < gridInfo.tileMaps.Length; i++)
            {
                var tilemap = gridInfo.tileMaps[i];
                var tile    = tilemap.GetTileID(uPos);
                if (tile == srcId)
                {
                    cmdBuffer.Execute(CurTick, new CmdSetTile(tilemap, uPos, srcId, dstId));
                }
            }
        }
コード例 #14
0
        public ushort Pos2TileId(LVector2Int pos, bool isCollider)
        {
            bool   flag = pos.x > this.mapDataMax.x || pos.x <this.mapDataMin.x || pos.y> this.mapDataMax.y || pos.y < this.mapDataMin.y;
            ushort result;

            if (flag)
            {
                result = 0;
            }
            else
            {
                LVector2Int lvector2Int = pos - this.mapDataMin;
                result = this.mapDataIds[lvector2Int.x, lvector2Int.y];
            }
            return(result);
        }
コード例 #15
0
        public void SetTileID(LVector2Int pos, ushort id)
        {
            LVector2Int lvector2Int = pos - this.min;
            bool        flag        = lvector2Int.x < 0 || lvector2Int.y < 0 || lvector2Int.x >= this.size.x || lvector2Int.y >= this.size.y;

            if (!flag)
            {
                int num = lvector2Int.y * this.size.x + lvector2Int.x;
                this.tileIDs[num] = id;
                ITileInfosView tileInfosView = this.view;
                if (tileInfosView != null)
                {
                    tileInfosView.SetTileID(num, pos, id);
                }
            }
        }
コード例 #16
0
        public ushort GetTileID(LVector2Int pos)
        {
            LVector2Int lvector2Int = pos - this.min;
            bool        flag        = lvector2Int.x < 0 || lvector2Int.y < 0 || lvector2Int.x >= this.size.x || lvector2Int.y >= this.size.y;
            ushort      result;

            if (flag)
            {
                result = 0;
            }
            else
            {
                ushort num = this.tileIDs[lvector2Int.y * this.size.x + lvector2Int.x];
                result = num;
            }
            return(result);
        }
コード例 #17
0
 public ushort RawPos2TileId(LVector2Int pos, bool isCollider)
 {
     for (int i = 0; i < this.gridInfo.tileMaps.Length; i++)
     {
         TileInfos tileInfos = this.gridInfo.tileMaps[i];
         bool      isTagMap  = tileInfos.isTagMap;
         if (!isTagMap)
         {
             bool flag = isCollider && !tileInfos.hasCollider;
             if (!flag)
             {
                 ushort tileID = tileInfos.GetTileID(pos);
                 bool   flag2  = tileID > 0;
                 if (flag2)
                 {
                     return(tileID);
                 }
             }
         }
     }
     return(0);
 }
コード例 #18
0
    public static byte[] WriteGrid(Grid grid, Func <TileBase, ushort> FuncGetTileIdx)
    {
        bool flag = grid == null;

        byte[] result;
        if (flag)
        {
            result = null;
        }
        else
        {
            Serializer  serializer           = new Serializer();
            LVector2Int val                  = new LVector2Int(2147483647, 2147483647);
            LVector2Int val2                 = new LVector2Int(-2147483648, -2147483648);
            Tilemap[]   componentsInChildren = grid.GetComponentsInChildren <Tilemap>();
            foreach (Tilemap tilemap in componentsInChildren)
            {
                Vector3Int min   = tilemap.cellBounds.min;
                Vector3Int max   = tilemap.cellBounds.max;
                bool       flag2 = min.x < val.x;
                if (flag2)
                {
                    val.x = min.x;
                }
                bool flag3 = min.y < val.y;
                if (flag3)
                {
                    val.y = min.y;
                }
                bool flag4 = max.x > val2.x;
                if (flag4)
                {
                    val2.x = max.x;
                }
                bool flag5 = max.y > val2.y;
                if (flag5)
                {
                    val2.y = max.y;
                }
            }
            serializer.Write(val);
            serializer.Write(val2);
            serializer.Write(grid.cellSize.ToLVector3());
            serializer.Write(grid.cellGap.ToLVector3());
            serializer.Write((int)grid.cellLayout);
            serializer.Write((int)grid.cellSwizzle);
            Tilemap[] componentsInChildren2 = grid.GetComponentsInChildren <Tilemap>();
            serializer.Write(componentsInChildren2.Length);
            foreach (Tilemap tilemap2 in componentsInChildren2)
            {
                serializer.Write(tilemap2.name);
            }
            foreach (Tilemap tilemap3 in componentsInChildren2)
            {
                TilemapRenderer component = tilemap3.GetComponent <TilemapRenderer>();
                Debug.Log(tilemap3.name + " " + component.sortingOrder);
                serializer.Write(component.sortingOrder);
            }
            foreach (Tilemap map in componentsInChildren2)
            {
                TileMapSerializer.WriteMap(serializer, map, FuncGetTileIdx);
            }
            result = serializer.CopyData();
        }
        return(result);
    }
コード例 #19
0
        public void SetTileID(int idx, LVector2Int pos, ushort id)
        {
            TileBase tileBase = UnityMap2DUtil.ID2Tile(id);

            this.tilemap.SetTile(new Vector3Int(pos.x, pos.y, 0), tileBase);
        }
コード例 #20
0
 public void Write(LVector2Int val)
 {
     Write(val.x); Write(val.y);
 }
コード例 #21
0
 public ushort Pos2TileId(LVector2Int pos, bool isCollider)
 {
     return(Pos2TileId(pos.ToVector2Int(), isCollider));
 }
コード例 #22
0
 public void ReplaceTile(LVector2Int pos, ushort srcId, ushort dstId)
 {
     ReplaceTile(pos.ToVector2Int(), srcId, dstId);
 }
コード例 #23
0
 public ushort Pos2TileId(LVector2Int pos, bool isCollider)
 {
     //TODO
     return(1);
 }
コード例 #24
0
 public void ReplaceTile(LVector2Int pos, ushort srcId, ushort dstId)
 {
 }
コード例 #25
0
 public static LVector2 ToLVector2(this LVector2Int vec)
 {
     return(new LVector2(true, vec.x * LFloat.Precision, vec.y * LFloat.Precision));
 }