コード例 #1
0
ファイル: StatusAnalyze.cs プロジェクト: swnhieian/Keyboard
 private void analyze()
 {
     //analyze movestatus
     double xAvg = logWindow.Average(x => x.inclinometer_x);
     double yAvg = logWindow.Average(x => x.inclinometer_y);
     double zAvg = logWindow.Average(x => x.inclinometer_z);
     double xVar = 0, yVar = 0, zVar = 0;
     foreach(LogRecord l in logWindow)
     {
         xVar += Math.Pow((l.inclinometer_x - xAvg), 2);
         yVar += Math.Pow((l.inclinometer_y - yAvg), 2);
         zVar += Math.Pow((l.inclinometer_z - zAvg), 2);
     }
     xVar /= logWindow.Count;
     yVar /= logWindow.Count;
     zVar /= logWindow.Count;
     if (xVar < 0.1 && xVar < 0.1 && zVar < 0.1)
     {
         this.moveStatus = MoveStatus.Still;
     } else
     {
         this.moveStatus = MoveStatus.Move;
     }
     window.setMoveStatus(this.moveStatus);
     //window.setTest(String.Format("{0},{1},{2}", xVar,yVar, zVar));
 }
コード例 #2
0
 void FixedUpdate()
 {
     if (moveStatus == MoveStatus.Hurt)
     {
         currentTime += Time.fixedDeltaTime;
         if (currentTime > nextTime)
         {
             moveStatus = MoveStatus.Idle;
         }
         return;
     }
     Movement();
     Jump();
     Crouch();
     SwitchAnim();
 }
コード例 #3
0
 public void StartMove(VInt3 moveVector, VInt speed)
 {
     // 保存方向向量
     dirVector = moveVector;
     // 计算下一步应该要走的位置
     targetPosition = targetPosition + moveVector * LogicFrame.frameIntervalTime * speed;
     // 计算移动速度
     speedNormal = speed;
     speedReal   = VInt3.Distance((VInt3)transform.position, targetPosition) / (LogicFrame.frameIntervalTime + (VInt)Time.deltaTime / (VInt)2.0f);
     if (moveStatus == MoveStatus.Forecast)
     {
         Debug.Log("嘻嘻 => " + speedReal.scalar);
     }
     // 移动的状态
     moveStatus = MoveStatus.Target;
 }
コード例 #4
0
ファイル: CMovement.cs プロジェクト: oForestRain/dog67u
    void updateMoveStatus()
    {
        float velocity = controller.velocity.x;

        mStatus = Mathf.Abs(velocity) > 0 ? MoveStatus.Run : MoveStatus.Stay;
        if (mStatus == MoveStatus.Run)
        {
            //bool sFacingRight = velocity > 0 ? true : false;
            if (facingRight ^ (velocity > 0))
            {
                facingRight = !facingRight;
                oMeidia.playAnimation(AnimationEnum.FacingRight, facingRight);
            }
        }
        oMeidia.playAnimation(AnimationEnum.VelocityX, Mathf.Abs(velocity));
    }
コード例 #5
0
        public void Fall()
        {
            if (_moveStatus != MoveStatus.Air)
            {
                //Debug.Log(_moveStatus + " > Fall");
                _portrait.CrossFade("Air");

                _moveStatus = MoveStatus.Air;

                _isGround = false;

                _jumpPosY = transform.position.y;

                _jumpCount = 1;
            }
        }
コード例 #6
0
        /// <summary>
        /// Update the leader or follower move status.
        /// </summary>
        /// <param name="index">The index of the agent to update.</param>
        /// <param name="status">The move status of the index </param>
        private void UpdateMoveStatus(int index, MoveStatus status)
        {
            // UpdateMoveStatus is registered within OnAwake which could cause the callback to be executed when the task isn't active.
            if (runStatus != TaskStatus.Running)
            {
                return;
            }

            if (leader.Value == null)
            {
                moveStatus[index] = status;
            }
            else
            {
                leaderMoveStatus = status;
            }
        }
コード例 #7
0
    public void StopMove()
    {
        VInt3 currPosition = (VInt3)transform.position;

        if (moveStatus == MoveStatus.Target || moveStatus == MoveStatus.Forecast)
        {
            if (currPosition != targetPosition)
            {
                moveStatus = MoveStatus.Back;
                speedReal  = VInt3.Distance(currPosition, targetPosition) / (LogicFrame.frameIntervalTime + (VInt)Time.deltaTime / (VInt)2.0f);
            }
            else
            {
                moveStatus = MoveStatus.Stop;
            }
        }
    }
コード例 #8
0
        /// <summary>
        /// Ends the current formation.
        /// </summary>
        private void EndFormation()
        {
            if (formationTrees != null)
            {
                // If the status is running then the leader task ended early. Send a status of failure to the group.
                if (runStatus == TaskStatus.Running)
                {
                    runStatus = TaskStatus.Failure;
                }
                for (int i = 0; i < formationTrees.Count; ++i)
                {
                    formationTrees[i].SendEvent("OrdersFinished", runStatus);
                }
                formationAgents.Clear();
                formationTrees.Clear();
                pathStarted.Clear();
                moveStatus.Clear();
                prevMoveStatus = MoveStatus.Full;
#if DEATHMATCH_AI_KIT_PRESENT
                if (TeamManager.IsInstantiated)
                {
                    TeamManager.SetLeader(gameObject, false);
                }
#endif
            }
            else
            {
                if (leaderTree != null)
                {
                    leaderTree.SendEvent("StopListeningToOrders", Owner);
                }
#if DEATHMATCH_AI_KIT_PRESENT
                if (TeamManager.IsInstantiated)
                {
                    TeamManager.RemoveFromFormation(prevLeader, Owner);
                }
#endif
            }
            formationIndex = -1;
            formationAgent.Stop();
            inFormation = false;
            if (agents != null)
            {
                agents.Clear();
            }
        }
コード例 #9
0
ファイル: EnemyBehave.cs プロジェクト: MikawaHeiya/UnityTry
    public void GetInjured()
    {
        if (!isDie)
        {
            moveStatus = 0;
            isDie      = true;
            HandleAnimate();
            gameController.AddScore(scoreOffset);

            if (UnityEngine.Random.Range(0, 1) == 0)
            {
                DropItem();
            }

            StartCoroutine(DestorySelf());
        }
    }
コード例 #10
0
 void SwitchAnim()
 {
     if (rb.velocity.y > 0)
     {
         moveStatus = MoveStatus.Jump;
         anim.SetTrigger("Jump");
     }
     else if (rb.velocity.y < 0)
     {
         moveStatus = MoveStatus.Fall;
         anim.SetTrigger("Fall");
     }
     else
     {
         moveStatus = MoveStatus.Idle;
         anim.SetTrigger("Land");
     }
 }
コード例 #11
0
    // 更新阻挡
    private void UpdateBlockEnemies()
    {
        // 移除死亡敌人
        List <int> emptyIndex = new List <int>();

        for (int index = 0; index < blockEnemies.Count; index++)
        {
            if (blockEnemies[index] == null)
            {
                emptyIndex.Add(index);
            }
        }
        for (int i = 0; i < emptyIndex.Count; i++)
        {
            blockEnemies.RemoveAt(emptyIndex[i] - i);
        }
        if (!originalData.isEnemy)
        {
            if (blockEnemies.Count == 0)
            {
                moveStatus = MoveStatus.WAIT;
            }
            else
            {
                int blockCnt = 0;
                // 更新当前阻挡数
                for (int i = 0; i < blockEnemies.Count; i++)
                {
                    if (runningData.attributes.maxBlockCnt < blockCnt + blockEnemies[i].GetComponent <CharManager>().runningData.attributes.maxBlockCnt)
                    {
                        Object[] obj = new Object[] { };
                        // 发送取消阻挡消息
                        blockEnemies[i].SendMessage("BlockCancel", obj);
                        blockEnemies.RemoveAt(blockEnemies.Count - 1);// 移除最后一个阻挡的人
                        i--;
                    }
                    else
                    {
                        blockCnt += blockEnemies[i].GetComponent <CharManager>().runningData.attributes.maxBlockCnt;
                    }
                }
            }
        }
    }
コード例 #12
0
 protected void OnMovement(bool isMoving)
 {
     if (!isMoving)
     {
         if (AgentMoveStatus != MoveStatus.Idling)
         {
             AgentMoveStatus = MoveStatus.Idling;
             OnAgentIdling.Invoke();
         }
     }
     else
     {
         if (AgentMoveStatus != MoveStatus.Moving)
         {
             AgentMoveStatus = MoveStatus.Moving;
             OnAgentMoving.Invoke();
         }
     }
 }
コード例 #13
0
        //public static void PrintError(int error)
        //{
        //    switch (error)
        //    {
        //        case WrongPiece:
        //            Console.WriteLine("Error: You moved a wrong piece. Please try again.\n");
        //            break;
        //        case IllegalMove:
        //            Console.WriteLine("Error: You moved a piece illegally. Please make sure you follow the rule.\n");
        //            break;
        //    }
        //}

        public static void PrintEror(MoveStatus moveStatus)
        {
            switch (moveStatus)
            {
            case MoveStatus.WrongPiece:
                Console.WriteLine("Error: You moved a wrong piece. Please try again.\n");
                break;

            case MoveStatus.Illegal:
                Console.WriteLine("Error: You moved a piece illegally. Please make sure you follow the rule.\n");
                break;

            case MoveStatus.NoError:
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(moveStatus), moveStatus, null);
            }
        }
コード例 #14
0
ファイル: disk-move.aspx.cs プロジェクト: zhangbo27/bbsmax
        private void Move()
        {
            int newDirectoryID = _Request.Get <int>("dID", Method.Get, 0);
            int sourceID       = _Request.Get <int> ("SourceID", Method.Get, 0);

            if (sourceID == 0)
            {
                sourceID = CurrentDirectory.DirectoryID;
            }

            MoveStatus status = DiskBO.Instance.MoveDiskDirectoriesAndFiles(My.UserID, sourceID, newDirectoryID, new List <int>(files), new List <int>(directories));

            if (status != MoveStatus.Success)
            {
                switch (status)
                {
                case MoveStatus.NoMoveChildDirectory:
                    ShowError("不能移动到子目录");
                    break;

                case MoveStatus.NoMoveSelecteDirectory:
                    ShowError("不能移动到当前目录");
                    break;

                case MoveStatus.DuplicateFileName:
                    ShowError("重复的文件名");
                    break;

                case MoveStatus.DirectoryIDNotExist:
                    ShowError("目录不存在");
                    break;

                default:
                    ShowError("发生错误, 无法移动到指定的目录下");
                    break;
                }
                // ShowError(status);
            }
            else
            {
                Return(true);
            }
        }
コード例 #15
0
ファイル: Program.cs プロジェクト: paulens12/BACKTRACK1
        private static bool Solve()
        {
            int newn = 2;
            int close = 1;
            int newx, newy;

            while (!_maze.Full)
            {
                Write("WAVE {0}, label L=\"{1}\"\n", _maze.Wave, _maze.Wave + 2);
                List <Maze.Position> positions = _maze.OpenCells;
                for (int i = 0; i < positions.Count; i++)
                {
                    Write("    Close CLOSE={0}, X={1}, Y={2}.\n", close++, positions[i].X + 1, positions[i].Y + 1);
                    for (int j = 0; j < _maze.MoveCount; j++)
                    {
                        MoveStatus ms = _maze.ApplyMove(positions[i], j, out newx, out newy);
                        Write("        R{0}. X={1}, Y={2}. ", j + 1, newx, newy);
                        switch (ms)
                        {
                        case MoveStatus.Free:
                            Write("Free. NEWN={0}.\n", newn++);
                            break;

                        case MoveStatus.Thread:
                            Write("CLOSED or OPEN.\n");
                            break;

                        case MoveStatus.Wall:
                            Write("Wall.\n");
                            break;

                        case MoveStatus.Terminal:
                            Write("Free. NEWN={0}. Terminal.\n", newn++);
                            return(true);
                        }
                    }
                    Write("\n");
                }
                _maze.FlushOpenCells();
                //break;
            }
            return(false);
        }
コード例 #16
0
ファイル: ToMove.cs プロジェクト: wywwwwei/3DGameProgramming
 private void Update()
 {
     if (moveStatus == MoveStatus.ToDest)
     {
         this.gameObject.transform.position = Vector3.MoveTowards(this.gameObject.transform.position, destination, moveSpeed * Time.deltaTime);
         if (this.gameObject.transform.position == destination)
         {
             moveStatus = MoveStatus.Stationary;
         }
     }
     if (moveStatus == MoveStatus.ToMiddle)
     {
         this.gameObject.transform.position = Vector3.MoveTowards(this.gameObject.transform.position, middle, moveSpeed * Time.deltaTime);
         if (this.gameObject.transform.position == middle)
         {
             moveStatus = MoveStatus.ToDest;
         }
     }
 }
コード例 #17
0
        public void Land()
        {
            if (transform.position.y < _jumpPosY - 5)
            {
                //높은데서 떨어졌을때
                _portrait.Play("Land");
                _portrait.CrossFadeQueued("Run", 0.1f);
            }
            else
            {
                _portrait.CrossFade("Run", 0.1f);
            }

            _moveStatus = MoveStatus.Run;

            _jumpPosY = transform.position.y;

            _isGround  = true;
            _jumpCount = 0;
        }
コード例 #18
0
    // Use this for initialization
    void Start()
    {
        var entityManager = World.Active.GetOrCreateManager <EntityManager>();
        var entities      = entityManager.GetAllEntities();

        for (int i = 0; i < entities.Length; i++)
        {
            if (entityManager.HasComponent <MoveStatus>(entities[i]))
            {
                MoveStatus moveStatus = new MoveStatus();
                moveStatus.Mass        = 10000;
                moveStatus.VelocityZ   = 0;
                moveStatus.ThrustZ     = 0;
                moveStatus.ResistanceZ = 1000;
                moveStatus.TimeZ       = 0;

                entityManager.SetComponentData(entities[i], moveStatus);
            }
        }
    }
コード例 #19
0
ファイル: LabPlotScript.cs プロジェクト: zhouchuan/Essence
    // 4 - check player press all the buttons (and hold down for seconds)
    private void PlotMovePhysical()
    {
        if (!plotStatusDic["isFinishMove"] && plotStatusDic["isFinishMouse"])
        {
            MoveStatus inputStatus = GetMoveStatus();

            if (inputList.Count != 0)
            {
                if (inputList.Contains(inputStatus))
                {
                    inputList.Remove(inputStatus);
                }
            }
            else
            {
                Invoke("PlayPlot", 2);
                plotStatusDic["isFinishMove"] = true;
            }
        }
    }
コード例 #20
0
        /// <summary>
        /// PerformMove - Выполнить движение
        /// Perform a single move
        /// Выполнить один ход
        /// </summary>
        /// <param name="board">
        /// the board state
        /// состояние правления
        /// </param>
        /// <param name="startRow">
        /// the start row
        /// начальный ряд
        /// </param>
        /// <param name="startCol">
        /// the start column
        /// начальный столбец
        /// </param>
        /// <param name="endRow">
        /// the end row
        /// конец строки
        /// </param>
        /// <param name="endCol">
        /// the end column
        /// конец столбца
        /// </param>
        private static MoveStatus PerformMove(IBoard board, int startRow, int startCol, int endRow, int endCol)
        {
            MoveStatus moveStatus = IsMoveLegal(board, startRow, startCol, endRow, endCol, BoardUtilities.GetPlayer(board[startRow, startCol]));

            if (moveStatus != MoveStatus.Illegal)
            {
                if (Math.Abs(endRow - startRow) == 1)
                {//walk
                 // ходить
                    board[endRow, endCol]     = board[startRow, startCol];
                    board[startRow, startCol] = Piece.None;
                }
                else
                {// jump piece
                 // прыжок
                    int jumpedRow = (startRow + endRow) / 2;
                    int jumpedCol = (startCol + endCol) / 2;
                    board[jumpedRow, jumpedCol] = Piece.None;
                    board[endRow, endCol]       = board[startRow, startCol];
                    board[startRow, startCol]   = Piece.None;
                }

                if ((moveStatus == MoveStatus.Incomplete) && (!CanJump(board, endRow, endCol)))
                {
                    moveStatus = MoveStatus.Legal;
                }

                // check if the piece is now a king
                // проверяем, является ли фигура королем
                if ((board[endRow, endCol] == Piece.BlackMan) && (endRow == BoardConstants.Rows - 1))
                {
                    board[endRow, endCol] = Piece.BlackKing;
                }
                else if ((board[endRow, endCol] == Piece.WhiteMan) && (endRow == 0))
                {
                    board[endRow, endCol] = Piece.WhiteKing;
                }
            }

            return(moveStatus);
        }
コード例 #21
0
 void Crouch()
 {
     if (rb.velocity.y == 0 && Input.GetButton("Crouch"))
     {
         anim.SetBool("Crouch", true);
         if (moveStatus != MoveStatus.Crouch)
         {
             moveSpeed /= 2;
             moveStatus = MoveStatus.Crouch;
         }
     }
     else
     {
         anim.SetBool("Crouch", false);
         if (moveStatus == MoveStatus.Crouch)
         {
             moveSpeed *= 2;
             moveStatus = MoveStatus.Idle;
         }
     }
 }
コード例 #22
0
ファイル: ToMove.cs プロジェクト: wywwwwei/3DGameProgramming
 public void setDestination(Vector3 _destination)
 {
     if (System.Math.Abs(this.gameObject.transform.position.y - _destination.y) < 0.0001f)
     {
         moveStatus  = MoveStatus.ToDest;
         destination = _destination;
     }
     else if (this.gameObject.transform.position.y > _destination.y)
     {
         moveStatus  = MoveStatus.ToMiddle;
         destination = _destination;
         middle      = _destination;
         middle.y    = this.gameObject.transform.position.y;
     }
     else
     {
         moveStatus  = MoveStatus.ToMiddle;
         destination = _destination;
         middle      = _destination;
         middle.x    = this.gameObject.transform.position.x;
     }
 }
コード例 #23
0
 private void SetMoveStatus(Vector3 input)
 {
     if (input != Vector3.zero)
     {
         if (Input.GetKey(KeyCode.R))
         {
             moveStatus = MoveStatus.RunForward;
         }
         else
         {
             moveStatus = MoveStatus.WalkForward;
         }
     }
     else if (!isGround)
     {
         moveStatus = MoveStatus.Jump;
     }
     else
     {
         moveStatus = MoveStatus.Stay;
     }
 }
コード例 #24
0
 /// <summary>
 /// RestSnack
 /// </summary>
 public void SnackReset()
 {
     if (!UIManager._Instance.isBlue)
     {
         gameObject.GetComponent <Image>().sprite = snackImages[5];
     }
     else
     {
         gameObject.GetComponent <Image>().sprite = snackImages[4];
     }
     //删除蛇身,清空list的引用
     foreach (var item in bodys)
     {
         GameObject.Destroy(item);
     }
     bodys.Clear();
     transform.localPosition = new Vector3(0, 0, 0);
     moveStatus         = MoveStatus.up;
     transform.rotation = Quaternion.Euler(0, 0, 0);
     CancelInvoke();
     GameObject.Destroy(CreatIce.Creater.ice);
 }
コード例 #25
0
 private void OnTriggerEnter2D(Collider2D collision)
 {
     if (collision.tag == "Enemy")
     {
         if (rb.velocity.y < 0)
         {
             gameManager.audioManager.PlayOneShot(jumpClip, 2f);
             rb.velocity = new Vector2(rb.velocity.x, jumpSpeed * Time.fixedDeltaTime * 0.5f);
             collision.gameObject.GetComponent <Enemy>().Death();
         }
         else
         {
             life--;
             healthText.text = "X " + life.ToString();
             gameManager.audioManager.PlayOneShot(hurtClip, 2f);
             if (collision.transform.position.x >= transform.position.x)
             {
                 if (currentTime >= nextTime)
                 {
                     nextTime   += hurtTime;
                     rb.velocity = new Vector2(-1f * moveSpeed * Time.fixedDeltaTime, rb.velocity.y);
                     moveStatus  = MoveStatus.Hurt;
                     anim.SetTrigger("Hurt");
                 }
             }
             else
             {
                 if (currentTime >= nextTime)
                 {
                     nextTime   += hurtTime;
                     rb.velocity = new Vector2(1f * moveSpeed * Time.fixedDeltaTime, rb.velocity.y);
                     moveStatus  = MoveStatus.Hurt;
                     anim.SetTrigger("Hurt");
                 }
             }
         }
     }
 }
コード例 #26
0
        // Assumed to be a valid move.
        private void AnimatePiece(Button b, int row, int col, MoveStatus moveStatus)
        {
            FrameworkElement root = (FrameworkElement)b.Template.FindName("TheTemplateRoot", b);

            double distance;
            bool   isMoveHorizontal;

            Debug.Assert(moveStatus != MoveStatus.BadMove);
            if (moveStatus == MoveStatus.Left || moveStatus == MoveStatus.Right)
            {
                isMoveHorizontal = true;
                distance         = (moveStatus == MoveStatus.Left ? -1 : 1) * root.Width;
            }
            else
            {
                isMoveHorizontal = false;
                distance         = (moveStatus == MoveStatus.Up ? -1 : 1) * root.Height;
            }

            // pull the animation after it's complete, because we move change Grid cells.
            DoubleAnimation slideAnim = new DoubleAnimation(distance, TimeSpan.FromSeconds(0.1), FillBehavior.Stop);

            slideAnim.CurrentStateInvalidated += delegate(object sender2, EventArgs e2)
            {
                // Anonymous delegate -- invoke when done.
                Clock clock = (Clock)sender2;
                if (clock.CurrentState != ClockState.Active)
                {
                    // remove the render transform and really move the piece in the Grid.
                    MovePiece(b, row, col);
                }
            };

            DependencyProperty directionProperty =
                isMoveHorizontal ? TranslateTransform.XProperty : TranslateTransform.YProperty;

            root.RenderTransform.BeginAnimation(directionProperty, slideAnim);
        }
コード例 #27
0
ファイル: CameraRotate.cs プロジェクト: luotianqi777/Tetris
    /// <summary>
    /// 镜头旋转
    /// </summary>
    private void Rotate()
    {
        switch (status)
        {
        case MoveStatus.NONE:
            break;

        case MoveStatus.LEFT:
            transform.RotateAround(Vector3.zero, Vector3.up, rotateSpeed);
            count++;
            break;

        case MoveStatus.RIGHT:
            transform.RotateAround(Vector3.zero, Vector3.up, -rotateSpeed);
            count++;
            break;
        }
        if (count == 90 / rotateSpeed)
        {
            count          = 0;
            status         = MoveStatus.NONE;
            Time.timeScale = 1;
        }
    }
コード例 #28
0
ファイル: DiskBO.cs プロジェクト: zhangbo27/bbsmax
        public MoveStatus MoveDiskDirectoriesAndFiles(int userID, int directoryID, int newDirectoryID, List <int> diskFileIdentities, List <int> diskDirectoryIdentities)
        {
            if (diskDirectoryIdentities.Contains(newDirectoryID))
            {
                return(MoveStatus.NoMoveSelecteDirectory);
            }
            Dictionary <int, DiskDirectoryCollection> parentIDs = GetParentDiskDirectories(userID, newDirectoryID);

            foreach (int dID in diskDirectoryIdentities)
            {
                if (parentIDs.ContainsKey(dID))
                {
                    return(MoveStatus.NoMoveSelecteDirectory);
                }
            }

            MoveStatus status = DiskDao.Instance.MoveDiskDirectoriesAndFiles(userID, directoryID, newDirectoryID, diskFileIdentities, diskDirectoryIdentities);

            if (status == MoveStatus.Success)
            {
            }
            RemoveCacheByUser(userID);
            return(status);
        }
コード例 #29
0
        public static bool isDone(this MoveStatus status)
        {
            bool moveStatus;

            switch (status)
            {
            case MoveStatus.DONE:
                moveStatus = true;
                break;

            case MoveStatus.ILLEGAL_MOVE:
                moveStatus = false;
                break;

            case MoveStatus.LEAVES_PLAYER_IN_CHECK:
                moveStatus = false;
                break;

            default:
                moveStatus = false;
                break;
            }
            return(moveStatus);
        }
コード例 #30
0
        /// <summary>
        /// Move the agents in a formation. The TargetPosition method will retrieve the target position for the individual group member.
        /// </summary>
        public override TaskStatus OnUpdate()
        {
            // If the leader has changed then reinitialize with the new leader.
            if (prevLeader != leader.Value)
            {
                EndFormation();
                UpdateLeader();
            }

            if (leader.Value == null)
            {
                if (formationStarted)
                {
                    // Notify following agents if the target position has updated.
                    if (targetTransform.Value != null)
                    {
                        if (targetTransform.Value != prevTargetTransform)
                        {
                            prevTargetTransform = targetTransform.Value;
                            for (int i = 1; i < formationTrees.Count; ++i)
                            {
                                formationTrees[i].SendEvent("UpdateTarget", targetTransform.Value);
                            }
                        }
                    }
                    else if (targetPosition.Value != prevTargetPosition)
                    {
                        prevTargetPosition = targetPosition.Value;
                        for (int i = 1; i < formationTrees.Count; ++i)
                        {
                            formationTrees[i].SendEvent("UpdateTargetPosition", targetPosition.Value);
                        }
                    }

                    // Wait until all of the agents are in position before moving to the target.
                    var waitForAgent = false;
                    for (int i = 1; i < formationAgents.Count; ++i)
                    {
                        if (!pathStarted[i])
                        {
                            pathStarted[i] = formationAgents[i].HasPath;
                        }
                        if (!pathStarted[i] || (moveStatus[0] == MoveStatus.Wait && moveStatus[i] == MoveStatus.Full) || moveStatus[i] == MoveStatus.Catchup)
                        {
                            waitForAgent = true;
                        }
                    }

                    // Send the updated move status to all of the followers.
                    if (waitForAgent)
                    {
                        moveStatus[0] = inFormation ? MoveStatus.Formation : MoveStatus.Wait;
                    }
                    else
                    {
                        moveStatus[0] = MoveStatus.Full;
                    }
                    if (moveStatus[0] != prevMoveStatus)
                    {
                        for (int i = 0; i < formationAgents.Count; ++i)
                        {
                            formationTrees[i].SendEvent("UpdateMoveStatus", 0, moveStatus[0]);
                        }

                        prevMoveStatus = moveStatus[0];
                    }

                    var target = (targetTransform.Value != null ? targetTransform.Value.position : targetPosition.Value);
                    formationAgent.SetDestination(target);

                    // Determine if all of the agents have arrived.
                    var arrived = true;
                    for (int i = 0; i < formationAgents.Count; ++i)
                    {
                        if (formationAgents[i].RemainingDistance > formationAgent.StoppingDistance || formationAgents[i].PathPending)
                        {
                            arrived = false;
                            break;
                        }
                        else
                        {
                            formationAgents[i].Stop();
                        }
                    }
                    if (arrived)
                    {
                        runStatus = TaskStatus.Success;
                        return(runStatus);
                    }

                    // The leader can move if all agents are ready.
                    if (!waitForAgent)
                    {
                        inFormation = true;
                    }
                    formationAgent.Speed = (!waitForAgent ? fullSpeed.Value : (inFormation ? formationSpeed.Value : 0));
                }
            }
            else
            {
                // Send within OnUpdate to ensure the at least one leader behavior tree is active. If registered within OnStart there is a chance that the behavior tree
                // isn't active yet and will never receive the event.
                if (sendListenerEvent)
                {
                    leaderTree.SendEvent("StartListeningForOrders", Owner);
                    return(runStatus);
                }

                // A following agent should never have a formation index of -1. If the index is 0 then the agent hasn't been registered with the leader yet.
                if (formationIndex == -1)
                {
                    return(runStatus);
                }

                // Move towards the starting position and look in the same direction as the leader when just getting started in the formation.
                var targetDistance = (transform.position - TargetPosition(formationIndex, 0)).magnitude;
                if (!inFormation)
                {
                    if (targetDistance <= formationAgent.StoppingDistance + 0.001f)
                    {
                        inFormation = formationAgent.RotateTowards(leader.Value.transform.rotation) || leaderMoveStatus != MoveStatus.Wait;
                    }
                }

                // If the destination is immediately in front of the agent then that agents stopping distance will take over and slow down the agent. This will make the agent
                // lag behind the leader. Prevent this from happening by adding a small look ahead distance.
                var leaderTarget   = targetTransform.Value != null ? targetTransform.Value.position : targetPosition.Value;
                var leaderDistance = (leader.Value.transform.position - leaderTarget).magnitude;
                var zLookAhead     = inFormation ? Mathf.Min(leaderDistance, lookAhead.Value) : 0;
                var target         = TargetPosition(formationIndex, zLookAhead);

                // TargetPosition will be overridden to return the target position for the individual agent.
                formationAgent.SetDestination(target);

#if UNITY_EDITOR
                Debug.DrawRay(TargetPosition(formationIndex, 0), Vector3.up);
#endif
                // Determine the current move status.
                MoveStatus currentMoveStatus;
                if (inFormation)
                {
                    if (formationAgent.RemainingDistance - zLookAhead < -formationAgent.Radius / 2)
                    {
                        currentMoveStatus = leaderAgent != null && leaderMoveStatus == MoveStatus.Wait ? MoveStatus.Wait : MoveStatus.Slowdown;
                    }
                    else
                    {
                        if (targetDistance < (formationAgent.Radius * 2 + formationAgent.StoppingDistance) && leaderAgent != null)
                        {
                            currentMoveStatus = leaderMoveStatus;
                        }
                        else
                        {
                            currentMoveStatus = MoveStatus.Catchup;
                        }
                    }
                }
                else
                {
                    currentMoveStatus = (leaderMoveStatus != MoveStatus.Wait ? MoveStatus.Catchup : MoveStatus.Full);
                }
                // Set the speed according to the move status, and notify the leader.
                if (currentMoveStatus != prevMoveStatus)
                {
                    switch (currentMoveStatus)
                    {
                    case MoveStatus.Wait:
                        formationAgent.Speed = 0;
                        break;

                    case MoveStatus.Slowdown:
                        formationAgent.Speed = slowdownSpeed.Value;
                        break;

                    case MoveStatus.Formation:
                        formationAgent.Speed = formationSpeed.Value;
                        break;

                    case MoveStatus.Full:
                        formationAgent.Speed = fullSpeed.Value;
                        break;

                    case MoveStatus.Catchup:
                        formationAgent.Speed = catchupSpeed.Value;
                        break;
                    }
                    // Prevent auto breaking from slowing the agent down if they are trying to catch up.
                    formationAgent.AutoBreaking = (currentMoveStatus != MoveStatus.Catchup);

                    if (leaderTree != null)
                    {
                        leaderTree.SendEvent("UpdateMoveStatus", formationIndex, currentMoveStatus);
                    }
                    prevMoveStatus = currentMoveStatus;
                }
            }
            return(runStatus);
        }
コード例 #31
0
ファイル: PuzzleGrid.xaml.cs プロジェクト: jasine/KinectQuiz
        // Assumed to be a valid move.
        private void AnimatePiece(KinectTileButton b, int row, int col, MoveStatus moveStatus)
        {
            FrameworkElement root = (FrameworkElement)b.Template.FindName("TheTemplateRoot", b);

            double distance;
            bool isMoveHorizontal;

            Debug.Assert(moveStatus != MoveStatus.BadMove);
            if (moveStatus == MoveStatus.Left || moveStatus == MoveStatus.Right)
            {
                isMoveHorizontal = true;
                distance = (moveStatus == MoveStatus.Left ? -1 : 1) * root.Width;
            }
            else
            {
                isMoveHorizontal = false;
                distance = (moveStatus == MoveStatus.Up ? -1 : 1) * root.Height;
            }
            //XLen = distance;

            // pull the animation after it's complete, because we move change Grid cells.
            //DoubleAnimation slideAnim = new DoubleAnimation(distance, TimeSpan.FromSeconds(0.3), FillBehavior.Stop);
            //slideAnim.CurrentStateInvalidated += delegate(object sender2, EventArgs e2)
            //{
            //    // Anonymous delegate -- invoke when done.
            //    Clock clock = (Clock)sender2;
            //    if (clock.CurrentState != ClockState.Active)
            //    {
            //        // remove the render transform and really move the piece in the Grid.
            //        MovePiece(b, row, col);
            //    }
            //};
            XLen = distance;

            Storyboard sb = (Storyboard)this.FindResource("Storyboard1");
            if (isMoveHorizontal)
            {
                ((DoubleAnimationUsingKeyFrames)sb.Children[0]).KeyFrames[1].Value = distance;
            }
            else
            {
                ((DoubleAnimationUsingKeyFrames)sb.Children[1]).KeyFrames[1].Value = distance;
            }
            sb.CurrentStateInvalidated += delegate(object sender2, EventArgs e2)
            {
                // Anonymous delegate -- invoke when done.
                Clock clock = (Clock)sender2;
                if (clock.CurrentState != ClockState.Active)
                {
                    // remove the render transform and really move the piece in the Grid.
                    MovePiece(b, row, col);
                }
            };

            //DoubleAnimationUsingKeyFrames dauk=new DoubleAnimationUsingKeyFrames();
            //dauk.TargetPropertyType = TranslateTransform.Y;

            //var k = new EasingDoubleKeyFrame(distance, KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(300)));
            //dauk.KeyFrames.Add(k);

            //sb.Children.Add(new DoubleAnimationUsingKeyFrames());

            //sb.Begin();

            //KinectTileButton btn=root.

            //DependencyProperty directionProperty =
            //    isMoveHorizontal ? TranslateTransform.XProperty : TranslateTransform.YProperty;

            //Storyboard sb =(Storyboard) this.FindResource("Storyboard1");
            //sb.GetValue()
            //sb.Begin();
            //sb.BeginAnimation();

            //root.RenderTransform.BeginAnimation(KinectTileButton.RenderTransformProperty.);

            //root.RenderTransform.BeginAnimation((UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.Y), slideAnim);
            //MovePiece(b, row, col);
            //root.RenderTransform.BeginAnimat;
        }
コード例 #32
0
        /// <summary>
        /// Adds the agent to the formation group.
        /// </summary>
        /// <param name="agent">The agent to add.</param>
        /// <param name="index">The index of the agent within the group.</param>
        protected virtual void AddAgentToGroup(Behavior agent, int index)
        {
            if (leader.Value == null)
            {
                if (formationTrees == null)
                {
                    formationTrees  = new List <Behavior>();
                    formationAgents = new List <FormationAgent>();
                    pathStarted     = new List <bool>();
                    moveStatus      = new List <MoveStatus>();
                }
                // Notify the current agent of the existing agents.
                for (int i = 0; i < formationTrees.Count; ++i)
                {
                    agent.SendEvent("AddAgentToGroup", formationTrees[i], i);
                }

                // Insert the agent in the lists.
                formationTrees.Insert(index, agent);
                pathStarted.Insert(index, false);
                moveStatus.Insert(index, index == 0 ? MoveStatus.Wait : MoveStatus.Full);

                // Notify the agent of the target.
                if (targetTransform.Value != null)
                {
                    prevTargetTransform = targetTransform.Value;
                    formationTrees[index].SendEvent("UpdateTarget", targetTransform.Value);
                }
                else
                {
                    prevTargetPosition = targetPosition.Value;
                    formationTrees[index].SendEvent("UpdateTargetPosition", targetPosition.Value);
                }

                // Notify other agents that the current agent has joined the formation.
                for (int i = 1; i < formationTrees.Count; ++i)
                {
                    formationTrees[i].SendEvent("FormationUpdated", i);
                    formationTrees[i].SendEvent("AddAgentToGroup", formationTrees[index], index);
                }
                formationIndex = index;
                if (waitToMove.Value)
                {
                    moveStatus[0] = MoveStatus.Wait;
                }
            }
            else
            {
                sendListenerEvent = false;
                formationAgent.Resume();
            }

            // The agents array is maintained on both the leader and follower.
            if (agents == null)
            {
                agents = new List <Transform>();
            }
            agents.Insert(index, agent.transform);
            if (waitToMove.Value)
            {
                inFormation      = false;
                leaderMoveStatus = MoveStatus.Wait;
                prevMoveStatus   = MoveStatus.Last;
            }
        }
コード例 #33
0
        private void AnimatePiece(Button b, int row, int column, MoveStatus moveStatus)
        {
            double distance; //distance the tile should move
            bool isMoveHorizontal; //determine if move is horizontal or vertical
            if (moveStatus == MoveStatus.Left || moveStatus == MoveStatus.Right)
            {
                isMoveHorizontal = true;
                // If direction is left then the distance = -1, Else direction is right and distance = 1
                distance = (moveStatus == MoveStatus.Left ? -1 : 1)*b.Width;
            }
            else
            {
                isMoveHorizontal = false;
                // If direction is up then the distance = 1, Else direction is down and distance = -1
                distance = (moveStatus == MoveStatus.Up ? -1 : 1)*b.Height;
            }

            // pull the animation after it's complete, because we move change Grid cells.
            var slideAnim = new DoubleAnimation(distance, TimeSpan.FromSeconds(0.5), FillBehavior.Stop);
            slideAnim.CurrentStateInvalidated += delegate(object sender2, EventArgs e2)
                                                     {
                                                         // Anonymous delegate -- invoke when done.
                                                         var clock = (Clock) sender2;
                                                         if (clock.CurrentState == ClockState.Active) return;

                                                         // remove the render transform and really move the piece in the Grid.
                                                         try
                                                         {
                                                             LogicalMovePiece(b, row, column);

                                                             _moveDirection = moveStatus.ToString();
                                                                 //get the move direction and the button number
                                                             _selectedButtonNumber = b.Content.ToString();
                                                             //_previousMove = _selectedButtonNumber;      //Get the current and previously selected buttons
                                                             //_previousTime = _currentTime;
                                                             _currentTime = DateTime.Now;
                                                                 //Set the times when the move was made
                                                             _isAnimating = false;

                                                             PrintToTextFile(); //print data to text file
                                                         }
                                                         catch (Exception ex)
                                                         {
                                                             MessageBox.Show(ex.ToString(), "Error", MessageBoxButton.OK,
                                                                             MessageBoxImage.Error);
                                                         }
                                                     };

            var buttonTransform = new TranslateTransform(0, 0);
            b.RenderTransform = buttonTransform;

            //perform the actual slide animation
            var directionProperty = isMoveHorizontal ? TranslateTransform.XProperty : TranslateTransform.YProperty;
            //rootFE.RenderTransform.BeginAnimation(directionProperty, slideAnim);
            b.RenderTransform.BeginAnimation(directionProperty, slideAnim);
        }
コード例 #34
0
        private void AnimatePiece(DwellTimeButton b, int row, int col, MoveStatus moveStatus)
        {
            double distance; //distance the tile should move
            bool isMoveHorizontal; //determine íf move is horizontal or vertical

            //get the direction the tile should move
            //Debug.Assert(moveStatus != MoveStatus.BadMove);
            _buttonMoveStatus = moveStatus.ToString();
            if (moveStatus != MoveStatus.BadMove)
            {
                if (moveStatus == MoveStatus.Left || moveStatus == MoveStatus.Right)
                {
                    isMoveHorizontal = true;
                    // If direction is left then the distance = -1, Else direction is right and distance = 1
                    //distance = (moveStatus == MoveStatus.Left ? -1 : 1) * rootFE.Width;
                    distance = (moveStatus == MoveStatus.Left ? -1 : 1) * b.Width;
                }
                else
                {
                    isMoveHorizontal = false;
                    // If direction is up then the distance = 1, Else direction is down and distance = -1
                    //distance = (moveStatus == MoveStatus.Up ? -1 : 1) * rootFE.Height;
                    distance = (moveStatus == MoveStatus.Up ? -1 : 1) * b.Height;
                }

                // pull the animation after it's complete, because we move change Grid cells.
                DoubleAnimation slideAnim = new DoubleAnimation(distance, TimeSpan.FromSeconds(0.5), FillBehavior.Stop);

                //play the click sound
                System.Media.SoundPlayer sp = new System.Media.SoundPlayer("Click.wav");
                sp.Play();
                slideAnim.CurrentStateInvalidated += delegate(object sender2, EventArgs e2)
                {
                    // Anonymous delegate -- invoke when done.
                    Clock clock = (Clock)sender2;
                    if (clock.CurrentState != ClockState.Active)
                    {
                        // remove the render transform and really move the piece in the Grid.
                        try
                        {

                            MovePiece(b, row, col);

                            _moveDirection = moveStatus.ToString();   //get the move direction and the button number
                            _selectedButtonNumber = b.Content.ToString();
                            //_previousMove = _selectedButtonNumber;      //Get the current and previously selected buttons
                            //_previousTime = _currentTime;
                            _currentTime = DateTime.Now;            //Set the times when the move was made

                            PrintToTextFile();  //print data to text file
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.ToString(), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                        }
                    }
                };

                TranslateTransform buttonTransform = new TranslateTransform(0, 0);
                b.RenderTransform = buttonTransform;

                //perform the actual slide animation
                DependencyProperty directionProperty = isMoveHorizontal ? TranslateTransform.XProperty : TranslateTransform.YProperty;
                //rootFE.RenderTransform.BeginAnimation(directionProperty, slideAnim);
                b.RenderTransform.BeginAnimation(directionProperty, slideAnim);
            }
        }
コード例 #35
0
        private void OnPuzzleButtonClick(object sender, RoutedEventArgs e)
        {
            //*** ONCE A TILE HAS BEEN CLICKED MOVE IT IF IT IS A VALID MOVE ***

            //The 'way' the button was activated shouldn't matter (mouse/gaze)
            var clickedButton = e.Source as Button;

            if (clickedButton == null || _isAnimating) return;

            //Get the row and column of the button that has been clicked
            var row = (int) clickedButton.GetValue(RowProperty);
            var column = (int) clickedButton.GetValue(ColumnProperty);

            //check to see in which direction the button should be moved
            var moveStatus = _puzzleLogic.GetMoveStatus(row, column);
            ButtonMoveStatus = moveStatus; //todo fix this horrid static-cross-file-malarkey

            if (moveStatus == MoveStatus.BadMove) return;

            //as long as the move is valid, animate the movement by calling AnimatePiece
            _isAnimating = true;
            AnimatePiece(clickedButton, row, column, moveStatus);
        }
コード例 #36
0
ファイル: MainWindow.xaml.cs プロジェクト: swnhieian/Keyboard
 public void setMoveStatus(MoveStatus moveStatus)
 {
     if (moveStatus == MoveStatus.Still)
     {
         this.moveStatusBox.Text = "静止";
     }
     else if (moveStatus == MoveStatus.Move)
     {
         this.moveStatusBox.Text = "运动";
     }
 }
コード例 #37
0
        // Assumed to be a valid move.
        private void AnimatePiece(Button b, int row, int col, MoveStatus moveStatus)
        {
            FrameworkElement root = (FrameworkElement)b.Template.FindName("TheTemplateRoot", b);

            double distance;
            bool isMoveHorizontal;

            Debug.Assert(moveStatus != MoveStatus.BadMove);
            if (moveStatus == MoveStatus.Left || moveStatus == MoveStatus.Right)
            {
                isMoveHorizontal = true;
                distance = (moveStatus == MoveStatus.Left ? -1 : 1) * root.Width;
            }
            else
            {
                isMoveHorizontal = false;
                distance = (moveStatus == MoveStatus.Up ? -1 : 1) * root.Height;
            }

            // pull the animation after it's complete, because we move change Grid cells.
            DoubleAnimation slideAnim = new DoubleAnimation(distance, TimeSpan.FromSeconds(0.3), FillBehavior.Stop);
            slideAnim.CurrentStateInvalidated += delegate(object sender2, EventArgs e2)
            {
                // Anonymous delegate -- invoke when done.
                Clock clock = (Clock)sender2;
                if (clock.CurrentState != ClockState.Active)
                {
                    // remove the render transform and really move the piece in the Grid.
                    MovePiece(b, row, col);
                }
            };

            DependencyProperty directionProperty =
                isMoveHorizontal ? TranslateTransform.XProperty : TranslateTransform.YProperty;

            root.RenderTransform.BeginAnimation(directionProperty, slideAnim);
        }