Exemplo n.º 1
0
        void IEcsRunSystem.Run()
        {
            if (!_moveFilter.IsEmpty())
            {
                List <GameObject> squaresToMove = _moveFilter.Get1(0).SquaresToMove;
                List <Vector3>    dstPos        = _moveFilter.Get1(0).DstPos;
                Direction         moveDirection = _moveFilter.Get1(0).Direction;

                Vector2Int moveDirectionInt = Const.DirToVecI(moveDirection);
                Vector3    moveDirectionF   = Const.DirToVecF(moveDirection);


                foreach (GameObject o in _moveFilter.Get1(0).SquaresToMove)
                {
                    float d = Const.MoveSpeed * Time.deltaTime;
                    if (d > 9)
                    {
                        d = 9;
                    }
                    o.transform.position += moveDirectionF * d;
                }


                for (int i = 0; i < _moveFilter.Get1(0).SquaresToMove.Count; i++)
                {
                    if (Vector3.Distance(squaresToMove[i].transform.position, dstPos[i]) < 10)
                    {
                        squaresToMove[i].transform.position = dstPos[i];


                        if (_globalData.GameField[_moveFilter.Get1(0).DstPosInts[i].x,
                                                  _moveFilter.Get1(0).DstPosInts[i].y].ChangeDirection != Direction.None)
                        {
                            squaresToMove[i].GetComponent <SquareScript>().SetDirection(_globalData.GameField[_moveFilter.Get1(0).DstPosInts[i].x, _moveFilter.Get1(0).DstPosInts[i].y].ChangeDirection);
                        }


                        GameObject o = _globalData.GameField[_moveFilter.Get1(0).SrcPosInts[i].x, _moveFilter.Get1(0).SrcPosInts[i].y].Obj;
                        _globalData.GameField[_moveFilter.Get1(0).SrcPosInts[i].x, _moveFilter.Get1(0).SrcPosInts[i].y].Obj = null;
                        _globalData.GameField[_moveFilter.Get1(0).DstPosInts[i].x, _moveFilter.Get1(0).DstPosInts[i].y].Obj = o;

                        _moveFilter.Get1(0).SquaresToMove.RemoveAt(i);
                        _moveFilter.Get1(0).DstPos.RemoveAt(i);
                        _moveFilter.Get1(0).SrcPosInts.RemoveAt(i);
                        _moveFilter.Get1(0).DstPosInts.RemoveAt(i);
                        i--;
                    }
                }


                if (_moveFilter.Get1(0).SquaresToMove.Count == 0)
                {
                    _moveFilter.GetEntity(0).Destroy();

                    EcsEntity ent1 = _world.NewEntity();
                    ent1.Get <CheckFinishComponent>();
                }
            }
        }
Exemplo n.º 2
0
        void IEcsRunSystem.Run()
        {
            if (!_checkFilter.IsEmpty())
            {
                GameObject touchSquare      = _checkFilter.Get1(0).obj;
                Direction  moveDirection    = touchSquare.GetComponent <SquareScript>().SquareDirection;
                Vector2Int touchPos         = new Vector2Int((int)touchSquare.transform.position.x / Const.CellSizePx, (int)touchSquare.transform.position.y / -Const.CellSizePx);
                Vector2Int moveDirectionInt = Const.DirToVecI(moveDirection);


                _checkFilter.GetEntity(0).Destroy();


                if (!CheckMove(touchPos, moveDirectionInt))
                {
                    EcsEntity ent = _world.NewEntity();
                    ent.Get <WaitForTochComponent>();

                    EcsEntity        ent4 = _world.NewEntity();
                    SoundFxComponent ss   = new SoundFxComponent();
                    ss.Fx = SoundFx.SquareMoveError;
                    ent4.Get <SoundFxComponent>() = ss;

                    return;
                }


                List <GameObject> SquaresToMove = new List <GameObject>();

                SquaresToMove.Add(_globalData.GameField[touchPos.x, touchPos.y].Obj);


                Vector2Int npos = touchPos;
                do
                {
                    npos = npos + moveDirectionInt;
                    if (npos.x < 0 || npos.x >= Const.MapSize || npos.y < 0 || npos.y >= Const.MapSize)
                    {
                        break;
                    }
                    if (_globalData.GameField[npos.x, npos.y].Obj is null)
                    {
                        break;
                    }

                    SquaresToMove.Add(_globalData.GameField[npos.x, npos.y].Obj);
                } while (true);


                SquaresToMove.Reverse();

                SaveUndo();


                EcsEntity ent1 = _world.NewEntity();
                ent1.Get <MoveComponent>().SquaresToMove = SquaresToMove;
                ent1.Get <MoveComponent>().Direction     = moveDirection;

                Vector3 moveDirectionF = Const.DirToVecF(moveDirection);

                List <Vector3>    dstPos    = new List <Vector3>();
                List <Vector2Int> srcPosInt = new List <Vector2Int>();
                List <Vector2Int> dstPosInt = new List <Vector2Int>();

                foreach (GameObject o in SquaresToMove)
                {
                    Vector3 dst = o.transform.position + moveDirectionF * Const.CellSizePx;
                    dstPos.Add(dst);
                    Vector2Int di = new Vector2Int((int)dst.x / Const.CellSizePx, (int)dst.y / -Const.CellSizePx);
                    dstPosInt.Add(di);
                    Vector2Int si = new Vector2Int((int)o.transform.position.x / Const.CellSizePx, (int)o.transform.position.y / -Const.CellSizePx);
                    srcPosInt.Add(si);
                }

                ent1.Get <MoveComponent>().DstPos     = dstPos;
                ent1.Get <MoveComponent>().SrcPosInts = srcPosInt;
                ent1.Get <MoveComponent>().DstPosInts = dstPosInt;


                EcsEntity        ent3 = _world.NewEntity();
                SoundFxComponent s    = new SoundFxComponent();
                s.Fx = SoundFx.SquareMove;
                ent3.Get <SoundFxComponent>() = s;
            }
        }