예제 #1
0
        private bool translateEvent(EEventType type, object[] args, out EEventType out_type, out object[] out_args)
        {
            switch (type)
            {
            case EEventType.TILE_MOVE_RELATIVETY:
            {
                var tile      = args[0] as Logic.Tile;
                var direction = (EDirection)args[1];

                out_type = EEventType.TILE_MOVE;

                out_args    = new object[2];
                out_args[0] = tile;

                if (direction == EDirection.UP)
                {
                    if (tile.Position.Row >= tile.Parent.LayerCollide.Height)
                    {
                        return(false);
                    }

                    out_args[1] = new Logic.TilePosition(tile.Position.Row + 1, tile.Position.Col);
                }
                else if (direction == EDirection.DOWN)
                {
                    if (tile.Position.Row <= 0)
                    {
                        return(false);
                    }

                    out_args[1] = new Logic.TilePosition(tile.Position.Row - 1, tile.Position.Col);
                }
                else if (direction == EDirection.LEFT)
                {
                    if (tile.Position.Col <= 0)
                    {
                        return(false);
                    }

                    out_args[1] = new Logic.TilePosition(tile.Position.Row, tile.Position.Col - 1);
                }
                else if (direction == EDirection.RIGHT)
                {
                    if (tile.Position.Col >= tile.Parent.LayerCollide.Width)
                    {
                        return(false);
                    }

                    out_args[1] = new Logic.TilePosition(tile.Position.Row, tile.Position.Col + 1);
                }

                return(true);
            }
            }

            out_type = type;
            out_args = args;

            return(true);
        }
예제 #2
0
        public Tile this[TilePosition pos]
        {
            get
            {
                try
                {
                    return(mTiles[(uint)pos.Row, (uint)pos.Col]);
                }
                catch
                {
                    return(null);
                }
            }
            set
            {
                mTiles[(uint)pos.Row, (uint)pos.Col] = value;

                if (value != null)
                {
                    value.Position = pos;
                }
            }
        }
예제 #3
0
        /// <summary>
        /// tile移动逻辑
        /// </summary>
        /// <param name="tile">要移动的tile</param>
        /// <param name="destination">目标坐标</param>
        /// <returns></returns>
        public IEnumerator MoveTileTo(Tile tile, TilePosition destination)
        {
            do
            {
                // 移动中不能移动
                if (tile == null || tile.IsMoving || tile.Position == destination)
                {
                    break;
                }

                // 判断碰撞层是否允许移动
                var dst_collide_tile = mCurTileMap.LayerCollide[destination];
                if (dst_collide_tile != null && !dst_collide_tile.ValidateMove(tile))
                {
                    break;
                }

                // 判断地板层是否允许移动
                var dst_floor_tile = mCurTileMap.LayerFloor[destination];
                if (dst_floor_tile != null && !dst_floor_tile.ValidateMove(tile))
                {
                    break;
                }

                // 开始移动
                tile.IsMoving = true;

                if (dst_collide_tile != null)
                {
                    // 先trigger碰撞层
                    yield return(dst_collide_tile.BeginTrigger(tile));

                    if ((bool)SafeCoroutine.Coroutine.GlobalResult == false)
                    {
                        break;
                    }
                }

                if (dst_floor_tile != null)
                {
                    // trigger地板层
                    yield return(dst_floor_tile.BeginTrigger(tile));

                    if ((bool)SafeCoroutine.Coroutine.GlobalResult == false)
                    {
                        break;
                    }
                }

                tile.BeginMove();

                // 等待移动
                yield return(tile.MoveTo(destination));

                tile.EndMove();

                // 碰撞层没有trigger结束
                // 因为现在layer里同一个位置不允许有多个tile,所以moveto后,原tile就被干掉了,所以不需要trigger结束
                if (dst_collide_tile != null && !dst_collide_tile.IsDead)
                {
                    yield return(dst_collide_tile.EndTrigger(tile));
                }

                if (dst_floor_tile != null && !dst_floor_tile.IsDead)
                {
                    // 地板层trigger结束
                    yield return(dst_floor_tile.EndTrigger(tile));
                }
            } while (false);

            tile.IsMoving = false;
        }