Example #1
0
 private void Move(MoveDirectionEnum direction)
 {
     MoveCommand moveCommand = new MoveCommand(moveCommandReciever, direction, moveDistance, objectToMove);
     //moveCommand.Execute();
     //commands.Add(moveCommand);
     //currentCommandNum++;
 }
Example #2
0
        public virtual void Move(MoveDirectionEnum direction, int value)
        {
            var level = GetLevel();

            level[PositionX, PositionY] = new EmptySpace(PositionX, PositionY);
            switch (direction)
            {
            case MoveDirectionEnum.Vertical:
                PositionY += value;
                if (!IsValid(level))
                {
                    PositionY -= value;
                }
                break;

            case MoveDirectionEnum.Horizontal:
                PositionX += value;
                if (!IsValid(level))
                {
                    PositionX -= value;
                }
                break;
            }
            level[PositionX, PositionY] = this;
        }
Example #3
0
 /// <summary>
 /// Collition check after rotation
 /// </summary>
 /// <param name="in1">Object to check</param>
 /// <param name="in2">Object to check against</param>
 /// <param name="m">Move to check</param>
 /// <returns>True if the same position</returns>
 private bool TagCheck(TagObject in1, TagObject in2, MoveDirectionEnum m)
 {
     if (m == MoveDirectionEnum.Down)
     {
         if ((in1.X == in2.X) && (in1.Y == in2.Y - 1))
         {
             return(true);
         }
     }
     if (m == MoveDirectionEnum.Left)
     {
         if ((in1.X == in2.X + 1) && (in1.Y == in2.Y))
         {
             return(true);
         }
     }
     if (m == MoveDirectionEnum.Right)
     {
         if ((in1.X == in2.X - 1) && (in1.Y == in2.Y + 1))
         {
             return(true);
         }
     }
     if (m == MoveDirectionEnum.Top)
     {
         if ((in1.X == in2.X) && (in1.Y == in2.Y + 1))
         {
             return(true);
         }
     }
     return(false);
 }
Example #4
0
 public override void Update()
 {
     if (!Move(move))
     {
         move = (MoveDirectionEnum)Random.Range(0, 4);
     }
 }
Example #5
0
    void HandleInput()
    {
        MoveDirectionEnum moveInput = MoveDirectionEnum.None;

        if (Input.GetKey(KeyCode.UpArrow))
        {
            moveInput = MoveDirectionEnum.Up;
        }
        if (Input.GetKey(KeyCode.DownArrow))
        {
            moveInput = MoveDirectionEnum.Down;
        }
        if (Input.GetKey(KeyCode.LeftArrow))
        {
            moveInput = MoveDirectionEnum.Left;
        }
        if (Input.GetKey(KeyCode.RightArrow))
        {
            moveInput = MoveDirectionEnum.Right;
        }
        if (moveInput != MoveDirectionEnum.None)
        {
            Move(moveInput);
        }
    }
Example #6
0
 //Constructor
 public MoveCommand(MoveCommandReceiver reciever, MoveDirectionEnum direction, float distance, GameObject gameObjectToMove)
 {
     this._receiver   = reciever;
     this._direction  = direction;
     this._distance   = distance;
     this._gameObject = gameObjectToMove;
 }
Example #7
0
        private void MoveCmdEnum(int speed, MoveDirectionEnum dir, float flen)
        {
            const int  port = 1;
            const byte PRINTER_PIPECMDSIZE = 26;

            byte [] m_pData = new byte[PRINTER_PIPECMDSIZE + 2];
            int     len     = 0;

            switch (dir)
            {
            case MoveDirectionEnum.Left:
            case MoveDirectionEnum.Right:
                len = Convert.ToInt32(UIPreference.ToInchLength(m_CurrentUnit, flen) * m_SPrinterProperty.fPulsePerInchX);
                break;

            case MoveDirectionEnum.Down:
            case MoveDirectionEnum.Up:
                //len = Convert.ToInt32(UIPreference.ToInchLength(m_CurrentUnit, flen) * m_SPrinterProperty.fPulsePerInchY);
                float pulse = m_SPrinterProperty.fPulsePerInchY;
                pulse = pulse * UIPreference.ToInchLength(m_CurrentUnit, flen);
                len   = Convert.ToInt32(pulse);
                break;

            case MoveDirectionEnum.Down_Z:
            case MoveDirectionEnum.Up_Z:
                len = Convert.ToInt32(UIPreference.ToInchLength(m_CurrentUnit, flen) * m_SPrinterProperty.fPulsePerInchZ);
                break;
            }
            CoreInterface.MoveCmd((int)dir, len, speed);
        }
Example #8
0
 static public Move Create(Position p, MoveDirectionEnum direction)
 {
     return(new Move()
     {
         Position = p,
         MoveDirection = direction
     });
 }
Example #9
0
 public Candy(Func <Level> getLevel, int i, int j, MoveDirectionEnum direction, int value,
              Action <int> changePlayerHp) : base(i, j, getLevel, changePlayerHp)
 {
     EntityEnumType = GameEntitiesEnum.Candy;
     PerformAction(direction, value);
     CanMove = false;
     Damage  = 2;
     Hp      = 15;
 }
Example #10
0
        private void PerformAction(MoveDirectionEnum direction, int value)
        {
            var task = new Task(() => {
                for (var i = 0; i < moveLength; i++)
                {
                    Move(direction, value);
                    Thread.Sleep(100);
                }
            });

            task.Start();
        }
Example #11
0
        private void buttonMoveB_Click(object sender, System.EventArgs e)
        {
            int               speed;
            float             len     = Decimal.ToSingle(m_NumericUpDownLength.Value);
            MoveDirectionEnum dirEnum = PubFunc.GetRealMoveDir(MoveDirectionEnum.Up, m_SPrinterProperty, m_UIPreference);

            if (!PubFunc.ParseSeedString(m_NumericUpDownMoveYSpeed.Text, out speed, dirEnum))
            {
                return;
            }
            MoveCmdEnum(speed, dirEnum, len);
        }
Example #12
0
        private void button2_Click(object sender, EventArgs e)
        {
            int               speed;
            float             len     = Decimal.ToSingle(m_NumericUpDownLength.Value);
            MoveDirectionEnum dirEnum = MoveDirectionEnum.Down_4;

            if (!PubFunc.ParseSeedString(m_ComboBox4speed.Text, out speed, dirEnum))
            {
                return;
            }
            MoveCmdEnum(speed, dirEnum, len);
        }
Example #13
0
    private void Awake()
    {
        gridPosition      = new Vector2Int(10, 10);
        gridMoveTimerMax  = 0.3f;
        gridMoveTimer     = gridMoveTimerMax;
        gridMoveDirection = new Vector2Int(1, 0);
        moveDirctionEnum  = MoveDirectionEnum.RIGHT;

        snakeBodySize         = 0;
        snakeMovePositionList = new List <SnakeMovePosition>();
        snakeBodyPartsList    = new List <SnakeBodyPart>();
        state = State.Alive;
    }
Example #14
0
        public override void Move(MoveDirectionEnum direction, int value)
        {
            if (!EnoughEnergy())
            {
                return;
            }
            SetAnimation(PlayerAnimationsEnum.Move);
            var level    = GetLevel();
            var willMove = false;

            switch (direction)
            {
            case MoveDirectionEnum.Horizontal:
                var newPositionX = PositionX + value;
                if (IsNewPositionSuitable(level, newPositionX, PositionY))
                {
                    MakePreviousPositionEmpty(level);
                    PositionX = newPositionX;
                    willMove  = true;
                }
                break;

            case MoveDirectionEnum.Vertical:
                var newPositionY = PositionY + value;

                if (level[PositionX, newPositionY] is Rock && Energy > _moveRockEnergyCost)
                {
                    Energy -= _moveRockEnergyCost;
                    level[PositionX, newPositionY].BreakAction(this);
                }

                if (IsNewPositionSuitable(level, PositionX, newPositionY))
                {
                    MakePreviousPositionEmpty(level);
                    PositionY = newPositionY;
                    willMove  = true;
                }
                break;
            }
            if (!willMove)
            {
                return;
            }
            _playSound(SoundFilesEnum.WalkSound);
            Energy -= _moveEnergyCost;
            level[PositionX, PositionY].BreakAction(this);
            level[PositionX, PositionY] = this;
        }
Example #15
0
 /// <summary>
 /// Moves a Piece in a given direction
 /// </summary>
 /// <param name="MoveDirection">Direction to move the piece</param>
 /// <returns></returns>
 public void BeginMove(MoveDirectionEnum MoveDirection, IPiece pieceToMove = null)
 {
     if (pieceToMove == null)
     {
         pieceToMove = currentPiece;
     }
     if (MoveDirection == MoveDirectionEnum.Down)
     {
         movePiece(0, 1, pieceToMove);
     }
     if (MoveDirection == MoveDirectionEnum.Left)
     {
         movePiece(-1, 0, pieceToMove);
     }
     if (MoveDirection == MoveDirectionEnum.Right)
     {
         movePiece(1, 0, pieceToMove);
     }
 }
        public void ChangeAnchorPosition(MoveDirectionEnum direction, int value)
        {
            switch (direction)
            {
            case MoveDirectionEnum.Horizontal:
                if (MapPosX + value >= 0 && MapPosX + value < NewCustomLevel.SizeX)
                {
                    MapPosX += value;
                }
                break;

            case MoveDirectionEnum.Vertical:
                if (MapPosY + value >= 0 && MapPosY + value < NewCustomLevel.SizeY)
                {
                    MapPosY += value;
                }
                break;
            }
        }
Example #17
0
    //Convert the MoveDirection enum to a string for debug
    public string MoveDirectionString(MoveDirectionEnum direction)
    {
        switch (direction)
        {
        case MoveDirectionEnum.up:
            return("up");

        case MoveDirectionEnum.down:
            return("down");

        case MoveDirectionEnum.left:
            return("left");

        case MoveDirectionEnum.right:
            return("right");

        default:
            return("unkown");
        }
    }
Example #18
0
    //invert the direction for undo
    private MoveDirectionEnum InverseDirection(MoveDirectionEnum direction)
    {
        switch (direction)
        {
        case MoveDirectionEnum.up:
            return(MoveDirectionEnum.down);

        case MoveDirectionEnum.down:
            return(MoveDirectionEnum.up);

        case MoveDirectionEnum.left:
            return(MoveDirectionEnum.right);

        case MoveDirectionEnum.right:
            return(MoveDirectionEnum.left);

        default:
            Debug.LogError("Unknown MoveDirection");
            return(MoveDirectionEnum.up);
        }
    }
    public void MoveOperation(GameObject gameObjectToMove, MoveDirectionEnum direction, float distance)
    {
        switch (direction)
        {
        case MoveDirectionEnum.up:
            MoveY(gameObjectToMove, distance);
            break;

        case MoveDirectionEnum.down:
            MoveY(gameObjectToMove, -distance);
            break;

        case MoveDirectionEnum.left:
            MoveX(gameObjectToMove, -distance);
            break;

        case MoveDirectionEnum.right:
            MoveX(gameObjectToMove, distance);
            break;
        }
    }
Example #20
0
 private void HandleInput()
 {
     if ((Input.GetKeyDown(KeyCode.UpArrow) || Input.GetKeyDown(KeyCode.W)) && moveDirctionEnum != MoveDirectionEnum.DOWN)
     {
         moveDirctionEnum  = MoveDirectionEnum.UP;
         gridMoveDirection = new Vector2Int(0, 1);
     }
     else if ((Input.GetKeyDown(KeyCode.DownArrow) || Input.GetKeyDown(KeyCode.S)) && moveDirctionEnum != MoveDirectionEnum.UP)
     {
         moveDirctionEnum  = MoveDirectionEnum.DOWN;
         gridMoveDirection = new Vector2Int(0, -1);
     }
     else if ((Input.GetKeyDown(KeyCode.LeftArrow) || Input.GetKeyDown(KeyCode.A)) && moveDirctionEnum != MoveDirectionEnum.RIGHT)
     {
         moveDirctionEnum  = MoveDirectionEnum.LEFT;
         gridMoveDirection = new Vector2Int(-1, 0);
     }
     else if ((Input.GetKeyDown(KeyCode.RightArrow) || Input.GetKeyDown(KeyCode.D)) && moveDirctionEnum != MoveDirectionEnum.LEFT)
     {
         moveDirctionEnum  = MoveDirectionEnum.RIGHT;
         gridMoveDirection = new Vector2Int(1, 0);
     }
 }
Example #21
0
        /// <summary>
        /// Checks if the current piece can be moved
        /// </summary>
        /// <param name="MoveDirection">The direction of the move</param>
        /// <returns></returns>
        public bool CanMove(MoveDirectionEnum MoveDirection, IPiece pieceToMove = null)
        {
            if (pieceToMove == null)
            {
                pieceToMove = currentPiece;
            }
            foreach (Rectangle r in pieceToMove.BitOfShape)
            {
                if (MoveDirection == MoveDirectionEnum.Down)
                {
                    if (blockList.Any(x => x == r))
                    {
                        pieceToMove.BitOfShape.ForEach(x => x.Fill = Brushes.WhiteSmoke);
                        //blockPos.AddRange(currentPiece.BitOfShape);
                        GeneratePiece();
                        score += 10;
                        OnScoreUpdate(score, new EventArgs());
                        return(false);
                    }

                    if (currentPiece.BitOfShape.Any(rec => _player.CurrentPiece.BitOfShape.Exists(
                                                        x => ((x.Tag as TagObject).Y == (rec.Tag as TagObject).Y + 1) && (
                                                            (x.Tag as TagObject).X == (rec.Tag as TagObject).X))))
                    {
                        OnplayerGameOver(this, new EventArgs());
                        return(false);
                    }

                    //if (blockPos.Any(x => (((TagObject)x.Tag).Y == (((TagObject)r.Tag).Y + 1))
                    //&& (((TagObject)x.Tag).X == (((TagObject)r.Tag).X))))
                    //{
                    //    blockPos.AddRange(currentPiece.BitOfShape);
                    //    if (blockPos.Any(x => blockListTop.Any(y => y == x)))
                    //    {
                    //        OnplayerGameOver(this, new EventArgs());
                    //    }
                    //    else
                    //    {
                    //        GeneratePiece();
                    //    }
                    //    return false;
                    //}
                }
                if (MoveDirection == MoveDirectionEnum.Right)
                {
                    score -= 1;
                    OnScoreUpdate(score, new EventArgs());
                    if (blockListRight.Any(x => x == r))
                    {
                        return(false);
                    }
                    if (blockPos.Any(x => (((TagObject)x.Tag).Y == (((TagObject)r.Tag).Y)) &&
                                     (((TagObject)x.Tag).X == (((TagObject)r.Tag).X + 1))))
                    {
                        return(false);
                    }
                }
                if (MoveDirection == MoveDirectionEnum.Left)
                {
                    score -= 1;
                    OnScoreUpdate(score, new EventArgs());
                    if (blockListLeft.Any(x => x == r))
                    {
                        return(false);
                    }
                    if (blockPos.Any(x => (((TagObject)x.Tag).Y == (((TagObject)r.Tag).Y)) &&
                                     (((TagObject)x.Tag).X == (((TagObject)r.Tag).X - 1))))
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }
Example #22
0
        public void SendPrintData()
        {
            int hPrinterPort = 0;

            try
            {
                bool isFirstRIP = false;
                _bSendExited = _bReadExited = false;
                bool bFileHeader = true;
                while (_cachList.Count < 2048 && !_bReadExited) //缓存一定数量才开始打印16M
                {
                    Thread.Sleep(100);
                }

                while ((hPrinterPort = CoreInterface.Printer_Open()) == 0)
                {
                    Thread.Sleep(100);
                }

                SPrinterSetting ssNew      = this.m_IPrinterChange.GetAllParam().PrinterSetting;
                SJobSetting     sjobseting = new SJobSetting();
                if (UIFunctionOnOff.SupportPrintMode)
                {
                    //todo
                }
                if (UIFunctionOnOff.SupportMediaMode)
                {
                    //todo
                }
                LayoutSetting curLayoutSetting = new LayoutSetting();

                int layoutIdx = 0;
                if (CoreInterface.LayoutIndex >= 0)
                {
                    layoutIdx = CoreInterface.LayoutIndex;
                }

                if (NewLayoutFun.GetLayoutSetting(layoutIdx, ref curLayoutSetting))
                {
                    ssNew.layoutSetting = curLayoutSetting;
                }
                if (ssNew.sExtensionSetting.AutoRunAfterPrint)
                {
                    ssNew.sBaseSetting.fYAddDistance = ssNew.sExtensionSetting.fRunDistanceAfterPrint;
                    ssNew.sExtensionSetting.bEnableAnotherUvLight = ssNew.sExtensionSetting.fRunDistanceAfterPrint > 0;
                    CoreInterface.SetPrinterSetting(ref ssNew, false); //打印结束后继续扫描一段距离生效
                }
                //打印前设置JobSetting
                sjobseting.bReversePrint = ssNew.sBaseSetting.bReversePrint;
                CoreInterface.SetSJobSetting(ref sjobseting);



                LogWriter.WriteLog(new string[] { "[RIP]Printer open" }, true);
                int cbBytesRead = 0;
                isFirstRIP = true;
                while (true)
                {
                    if (_cachList.Count > 0)
                    {
                        MyStruct data = new MyStruct();
                        if (!_cachList.TryDequeue(out data))
                        {
                            continue;
                        }
                        byte[] chRequest = data.buf;
                        cbBytesRead = data.buflen;
#if ADD_HARDKEY
                        {
                            int    subsize   = 32;
                            byte[] lastValue = chRequest;
                            if (bFileHeader)
                            {
                                bFileHeader = false;
                                lastValue   = new byte[BUFSIZE + 8];


                                byte[] mjobhead = new byte[subsize];
                                byte[] retValue = new byte[subsize + Marshal.SizeOf(typeof(int))];
                                for (int j = 0; j < BYHXSoftLock.JOBHEADERSIZE / subsize; j++)
                                {
                                    Buffer.BlockCopy(chRequest, j * mjobhead.Length, mjobhead, 0, mjobhead.Length);
                                    BYHX_SL_RetValue ret = BYHXSoftLock.CheckValidDateWithData(mjobhead, ref retValue);
                                    Buffer.BlockCopy(retValue, 0, lastValue, j * retValue.Length, retValue.Length);
                                }

                                Buffer.BlockCopy(chRequest, BYHXSoftLock.JOBHEADERSIZE, lastValue,
                                                 BYHXSoftLock.JOBHEADERSIZE + 8, chRequest.Length - BYHXSoftLock.JOBHEADERSIZE);
                                int sendBytes = CoreInterface.Printer_Send(hPrinterPort, lastValue, cbBytesRead + 8);
                                Debug.Assert(sendBytes == cbBytesRead + 8);
                            }
                            else
                            {
                                CoreInterface.Printer_Send(hPrinterPort, chRequest, cbBytesRead);
                            }
                        }
#else
                        {
                            if (isFirstRIP)
                            {
                                string strLog            = "";
                                int    nVersion          = 0;
                                byte   bReversePrint     = 0;
                                byte   nPrintLayerNum    = 0;
                                int    printmodePerLayer = 0;
                                isFirstRIP = false;

                                if (cbBytesRead >= 84)
                                {
                                    for (int i = 0; i < 84; i++)
                                    {
                                        strLog += Convert.ToString(chRequest[i], 2) + ",";
                                    }

                                    LogWriter.WriteLog(new string[] { "[RIP]" + strLog }, true);


                                    nVersion = BitConverter.ToInt32(chRequest, 4);
                                    if (nVersion == 4)
                                    {
                                        bReversePrint = chRequest[55];
                                        //nPrintLayerNum = chRequest[56];
                                        //printmodePerLayer = BitConverter.ToInt32(chRequest, 57);

                                        //PrinterSettingHelper.SetPropertyWhiteInkLayer(
                                        //    ref m_IPrinterChange.GetAllParam().PrinterSetting, bReversePrint,
                                        //    nPrintLayerNum,
                                        //    (uint) printmodePerLayer);
                                        CoreInterface.SetPrinterSetting(ref m_IPrinterChange.GetAllParam()
                                                                        .PrinterSetting);
                                        //isSetWhiteFormPrt = true;

                                        sjobseting = new SJobSetting();
                                        sjobseting.bReversePrint = bReversePrint == 1;
                                        CoreInterface.SetSJobSetting(ref sjobseting);
                                    }
                                    else if (nVersion == 6)
                                    {
                                        bReversePrint = chRequest[71];

                                        sjobseting = new SJobSetting();
                                        sjobseting.bReversePrint = bReversePrint == 1;
                                        CoreInterface.SetSJobSetting(ref sjobseting);
                                    }
                                }
                            }

                            //#else
                            CoreInterface.Printer_Send(hPrinterPort, chRequest, cbBytesRead);
                        }
#endif
                    }

                    if (_cachList.Count == 0 && _bReadExited)
                    {
                        LogWriter.WriteLog(
                            new string[]
                        {
                            string.Format("[SendPrintData]  CachList.Count = {0};bReadExited={1}", _cachList.Count,
                                          _bReadExited)
                        }, true);
                        break;
                    }

                    if (_cachList.Count == 0)
                    {
                        LogWriter.WriteLog(
                            new string[]
                        {
                            string.Format("[SendPrintData]  CachList.Count = {0};waittime={1}", _cachList.Count, 10)
                        }, true);
                        Thread.Sleep(10);
                    }
                }

                CoreInterface.Printer_Close(hPrinterPort);
                _bSendExited = true;
                SExtensionSetting extensionSetting = ssNew.sExtensionSetting;
                if (extensionSetting.fRunDistanceAfterPrint > 0 && extensionSetting.BackBeforePrint)
                {
                    while (true)
                    {
                        JetStatusEnum status = CoreInterface.GetBoardStatus();
                        if (status == JetStatusEnum.Ready)
                        {
                            int speed             = ssNew.sMoveSetting.nYMoveSpeed;
                            MoveDirectionEnum dir = MoveDirectionEnum.Up;
                            int len = Convert.ToInt32(extensionSetting.fRunDistanceAfterPrint * m_IPrinterChange.GetAllParam().PrinterProperty.fPulsePerInchY);
                            CoreInterface.MoveCmd((int)dir, len, speed);
                            break;
                        }
                        Thread.Sleep(100);
                    }
                }
            }
            catch (Exception e)
            {
                LogWriter.WriteLog(
                    new string[]
                {
                    string.Format("[SendPrintData]  CachList.Count = {0};Exception={1}", _cachList.Count, e.Message)
                }, true);
                if (hPrinterPort != 0)
                {
                    CoreInterface.Printer_Close(hPrinterPort);
                    _bSendExited = true;
                }
            }
        }
Example #23
0
 public Enemy(GameObject _obj, Point position)
     : base(_obj, position)
 {
     move = (MoveDirectionEnum)Random.Range(0, 4);
 }
Example #24
0
    public virtual bool Move(MoveDirectionEnum dir)
    {
        bool    r   = true;
        Vector2 pos = position;

        switch (dir)
        {
        case MoveDirectionEnum.Up:
            //move object first
            pos.y += speed * Time.deltaTime;
            //corectting move
            if (pos.y > BoardPosition.Real.y)
            {
                if (Movable(BoardPosition.Up))
                {
                    var offset = pos.x - BoardPosition.Real.x;
                    if (!Movable(BoardPosition.Left.Up))
                    {
                        if (offset < -0.2)
                        {
                            pos.y  = BoardPosition.Real.y;
                            pos.x += speed * Time.deltaTime;
                        }
                        else if (offset < 0)
                        {
                            pos.x = BoardPosition.Real.x;
                        }
                    }
                    if (!Movable(boardPosition.Right.Up))
                    {
                        if (offset > 0.2)
                        {
                            pos.y  = BoardPosition.Real.y;
                            pos.x -= speed * Time.deltaTime;
                        }
                        else if (offset > 0)
                        {
                            pos.x = BoardPosition.Real.x;
                        }
                    }
                    r = true;
                }
                else
                {
                    pos.y = BoardPosition.Real.y;
                    r     = false;
                }
            }
            else
            {
                r = true;
            }
            break;

        case MoveDirectionEnum.Down:
            pos.y -= speed * Time.deltaTime;

            //corectting move
            if (pos.y < BoardPosition.Real.y)
            {
                if (Movable(BoardPosition.Down))
                {
                    var offset = pos.x - BoardPosition.Real.x;
                    if (!Movable(BoardPosition.Left.Down))
                    {
                        if (offset < -0.2)
                        {
                            pos.y  = BoardPosition.Real.y;
                            pos.x += speed * Time.deltaTime;
                        }
                        else if (offset < 0)
                        {
                            pos.x = BoardPosition.Real.x;
                        }
                    }
                    if (!Movable(BoardPosition.Right.Down))
                    {
                        if (offset > 0.2)
                        {
                            pos.y  = BoardPosition.Real.y;
                            pos.x -= speed * Time.deltaTime;
                        }
                        else if (offset > 0)
                        {
                            pos.x = BoardPosition.Real.x;
                        }
                    }
                    r = true;
                }
                else
                {
                    pos.y = BoardPosition.Real.y;
                    r     = false;
                }
            }
            else
            {
                r = true;
            }
            break;

        case MoveDirectionEnum.Left:
            pos.x -= speed * Time.deltaTime;

            //corectting move
            if (pos.x < BoardPosition.Real.x)
            {
                if (Movable(BoardPosition.Left))
                {
                    var offset = pos.y - BoardPosition.Real.y;
                    if (!Movable(BoardPosition.Left.Down))
                    {
                        if (offset < -0.2)
                        {
                            pos.x  = BoardPosition.Real.x;
                            pos.y += speed * Time.deltaTime;
                        }
                        else if (offset < 0)
                        {
                            pos.y = BoardPosition.Real.y;
                        }
                    }
                    if (!Movable(boardPosition.Left.Up))
                    {
                        if (offset > 0.2)
                        {
                            pos.x  = BoardPosition.Real.x;
                            pos.y -= speed * Time.deltaTime;
                        }
                        else if (offset > 0)
                        {
                            pos.y = BoardPosition.Real.y;
                        }
                    }
                    r = true;
                }
                else
                {
                    pos.x = BoardPosition.Real.x;
                    r     = false;
                }
            }
            else
            {
                r = true;
            }
            break;

        case MoveDirectionEnum.Right:
            pos.x += speed * Time.deltaTime;
            //corectting move
            if (pos.x > BoardPosition.Real.x)
            {
                if (Movable(BoardPosition.Right))
                {
                    var offset = pos.y - BoardPosition.Real.y;
                    if (!Movable(BoardPosition.Right.Down))
                    {
                        if (offset < -0.2)
                        {
                            pos.x  = BoardPosition.Real.x;
                            pos.y += speed * Time.deltaTime;
                        }
                        else if (offset < 0)
                        {
                            pos.y = BoardPosition.Real.y;
                        }
                    }
                    if (!Movable(boardPosition.Right.Up))
                    {
                        if (offset > 0.2)
                        {
                            pos.x  = BoardPosition.Real.x;
                            pos.y -= speed * Time.deltaTime;
                        }
                        else if (offset > 0)
                        {
                            pos.y = BoardPosition.Real.y;
                        }
                    }
                    r = true;
                }
                else
                {
                    pos.x = BoardPosition.Real.x;
                    r     = false;
                }
            }
            else
            {
                r = true;
            }
            break;
        }

        Position = pos;
        return(r);
    }
Example #25
0
 public SnakeMovePosition(SnakeMovePosition previousSnakeMovePosition, Vector2Int gridPosition, MoveDirectionEnum direction)
 {
     this.previousSnakeMovePosition = previousSnakeMovePosition;
     this.direction    = direction;
     this.gridPosition = gridPosition;
 }