bool CheckReachedWaypoint()
    {
        //Debug.Log("CheckReachedWaypoint");
        if (waypoints.Count == 0 || activeWaypoint >= waypoints.Count)
        {
            return(true);
        }

        // There should not be any empty waypoints!
        //Assert.AreNotEqual(waypoints[activeWaypoint], null);
        if (waypoints[activeWaypoint] == null)
        {
            return(true);
        }

        Vector3 currentPos  = transform.position;
        Vector3 destination = waypoints[activeWaypoint].transform.position;

        if (GameplayHelper.GetSquaredDistanceBetween(currentPos, destination) < distanceToWaypoint * distanceToWaypoint)
        {
            return(true);
        }

        return(false);
    }
    /*「黒より黒く闇より暗き漆黒に我が深紅の混淆を望みたもう。
     * 覚醒のとき来たれり。無謬の境界に落ちし理。
     * 無行の歪みとなりて現出せよ!踊れ踊れ踊れ、我が力の奔流に望むは崩壊なり。
     * 並ぶ者なき崩壊なり。万象等しく灰塵に帰し、深淵より来たれ!
     * これが人類最大の威力の攻撃手段、これこそが究極の攻撃魔法、エクスプロージョン!」*/
    void エクスプロージョン()
    {
        //Debug.Log("エクスプロージョン");
        // Create an explosion.
        GameObject explosion = GameObject.Instantiate(explosionObject);

        explosion.transform.position = gameObject.transform.position;

        // Deal damage to the player.
        Vector3 directionToPlayer = player.transform.position - gameObject.transform.position;

        if (directionToPlayer.sqrMagnitude <= explosionRange * explosionRange)
        {
            // Raycast to ensure that nothing is blocking the explosion.
            if (!GameplayHelper.HasObstaclesBetween(gameObject.transform.position, player.transform.position, explosionBlockerTags))
            {
                Health playerHealth = player.GetComponent <Health>();
                //Assert.AreNotEqual(playerHealth, null);
                if (playerHealth != null)
                {
                    playerHealth.DecreaseHealth(explosionDamage);
                }
            }
        }

        // Kill this gameobject.
        gameObject.SetActive(false);
    }
        public void CheckForWinningSquare_WinIsNotPossible_ReturnsNull()
        {
            Board board = new Board();

            board.Squares[2, 2].State = SquareState.X;
            List <int[]> availableMoves = GameplayHelper.ListEmptySquares(board.Squares);

            var actual = GameplayHelper.CheckForWinningSquare(board.Squares, availableMoves, SquareState.X);

            Assert.Null(actual);
        }
    bool PlayerInAttackRange()
    {
        //Debug.Log("PlayerInAttackRange");
        Assert.AreNotEqual(player, null);

        if (CanSeePlayer())
        {
            return(GameplayHelper.GetSquaredDistanceBetween(lastKnownPlayerPosition, gameObject.transform.position) < attackRange * attackRange);
        }

        return(false);
    }
        public void CheckForWin_ReturnsTrueForWin_ReturnsFalseForNoWin(int firstColumn, int firstRow, int secondColumn, int secondRow, int thirdColumn, int thirdRow, bool isWin)
        {
            var board = new Board();

            board.Squares[firstColumn, firstRow].State   = SquareState.X;
            board.Squares[secondColumn, secondRow].State = SquareState.X;
            board.Squares[thirdColumn, thirdRow].State   = SquareState.X;

            bool actual = GameplayHelper.CheckForWin(board.Squares, SquareState.X);

            Assert.Equal(isWin, actual);
        }
Example #6
0
        void Update()
        {
            if (path != null)
            {
                var target = path[currentNode];

                var   distance             = target - transform.position;
                float distanceSqrMagnitude = distance.sqrMagnitude;

                distance.y = 0;

                if (distanceSqrMagnitude < 2)
                {
                    // reached
                    ++currentNode;
                    if (currentNode >= path.Count)
                    {
                        animationController.State = AnturaAnimationStates.idle;
                        path = null;
                    }
                }
                else
                {
                    if (isSniffing)
                    {
                        return;
                    }

                    randomSniffTime -= Time.deltaTime;

                    if (randomSniffTime < 0)
                    {
                        randomSniffTime = UnityEngine.Random.Range(3, 6);
                        isSniffing      = true;
                        speed           = 0;
                        animationController.DoSniff(() => { isSniffing = false; });
                        Audio.AudioManager.I.PlaySound(Sfx.DogSnorting);
                    }
                    else
                    {
                        distance.Normalize();

                        speed = Mathf.Min(12, speed + 20 * Time.deltaTime);

                        //transform.position += distance * Mathf.Abs(Vector3.Dot(distance, transform.forward)) * speed * Time.deltaTime;
                        Vector3 direction = Vector3.Slerp(distance, transform.forward, Mathf.Sqrt(distanceSqrMagnitude) / 2);

                        transform.position += direction * speed * Time.deltaTime;
                        GameplayHelper.LerpLookAtPlanar(transform, target, Time.deltaTime * 4);
                    }
                }
            }
        }
        public void ListEmptySquares_AllSquaresFilled_ReturnsEmptyList()
        {
            var board = new Board();

            foreach (var square in board.Squares)
            {
                square.State = SquareState.O;
            }

            var actual = GameplayHelper.ListEmptySquares(board.Squares);

            Assert.Empty(actual);
        }
        public void CheckForWinningSquare_WinIsPossible_ReturnsCorrectResult()
        {
            var   expected = new int[] { 0, 1 };
            Board board    = new Board();

            board.Squares[0, 0].State = SquareState.X;
            board.Squares[0, 2].State = SquareState.X;
            List <int[]> availableMoves = GameplayHelper.ListEmptySquares(board.Squares);

            var actual = GameplayHelper.CheckForWinningSquare(board.Squares, availableMoves, SquareState.X);

            Assert.Equal(expected, actual);
        }
Example #9
0
        public Gameplay()
        {
            InitializeComponent();
            CenterToScreen();
            //Generate Random Number
            db = new DataConnection();
            //GET ALL QUESTION
            questions      = db.Questions.ToList();
            gameplayHelper = new GameplayHelper();
            //GENERATE RANDOM NUMBER FOR QUESTION
            randomNumber = new RandomGenerator().create(db.Questions.Count());
            Question que = questions[randomNumber[questionIndex]];

            gameplayHelper.setQuestion(que);
            LblQuestion.Text = gameplayHelper.question.question;
            LblAnswer.Text   = gameplayHelper.Guest(' ');
        }
Example #10
0
        void Update()
        {
            var distance = target - transform.position;

            distance.y = 0;


            if (IsAnturaTime)
            {
                if (nextAnturaBarkTimer <= 0)
                {
                    PrepareNextAnturaBark();
                    TakeMeHomeConfiguration.Instance.Context.GetAudioManager().PlaySound(Sfx.DogBarking);
                }
                else
                {
                    nextAnturaBarkTimer -= Time.deltaTime;
                }
            }

            if (distance.sqrMagnitude < 0.1f)
            {
                transform.position = target;
                // reached
                //if (IsAnturaTime)
                //	SetRandomTarget();
                if (IsAnturaTime)
                {
                    //SetAnturaTime (false, initialPosition);
                    GetComponent <AnturaAnimationController>().State = AnturaAnimationStates.sitting;

                    //GetComponent<Antura> ().SetAnimation (AnturaAnim.SitBreath);
                    StartCoroutine(waitAndReturn(1));
                }
            }
            else
            {
                distance.Normalize();
                transform.position += distance * Vector3.Dot(distance, transform.forward) * ANTURA_SPEED * Time.deltaTime;
                GameplayHelper.LerpLookAtPlanar(transform, target, Time.deltaTime * 3);
            }
        }
Example #11
0
        public void MediumComputerPlayer_NeitherComputerNorHumanCanWin_ComputerMakesMove(int col1, int row1, int col2, int row2, int col3, int row3, int col4, int row4)
        {
            var board = new Board();

            board.Squares[col1, row1].State = SquareState.O;
            board.Squares[col2, row2].State = SquareState.O;
            board.Squares[col3, row3].State = SquareState.X;
            board.Squares[col4, row4].State = SquareState.X;

            List <int[]> emptySquaresBeforeMove = GameplayHelper.ListEmptySquares(board.Squares);

            Assert.Equal(5, emptySquaresBeforeMove.Count);

            var player = new MediumComputerPlayer();
            var actual = player.PlayerInput(board.Squares);

            List <int[]> emptySquaresAfterMove = GameplayHelper.ListEmptySquares(actual);

            Assert.Equal(4, emptySquaresAfterMove.Count);
        }
        public void ListEmptySquares_AllSquaresEmpty_ListContainsAllSquares()
        {
            var board    = new Board();
            var expected = new List <int[]>
            {
                new int[] { 0, 0 },
                new int[] { 0, 1 },
                new int[] { 0, 2 },
                new int[] { 1, 0 },
                new int[] { 1, 1 },
                new int[] { 1, 2 },
                new int[] { 2, 0 },
                new int[] { 2, 1 },
                new int[] { 2, 2 },
            };

            var actual = GameplayHelper.ListEmptySquares(board.Squares);

            Assert.Equal(expected, actual);
        }
        public void ListEmptySquares_SomeSquaresFilled_ListContainsOnlyEmptySquares()
        {
            var board = new Board();

            board.Squares[0, 1].State = SquareState.O;
            board.Squares[0, 0].State = SquareState.O;
            board.Squares[1, 1].State = SquareState.X;
            board.Squares[2, 0].State = SquareState.X;

            var expected = new List <int[]>
            {
                new int[] { 0, 2 },
                new int[] { 1, 0 },
                new int[] { 1, 2 },
                new int[] { 2, 1 },
                new int[] { 2, 2 },
            };

            var actual = GameplayHelper.ListEmptySquares(board.Squares);

            Assert.Equal(expected, actual);
        }
        void Update()
        {
            var distance = target - transform.position;

            distance.y = 0;

            if (IsAnturaTime)
            {
                if (nextAnturaBarkTimer <= 0)
                {
                    PrepareNextAnturaBark();
                    antura.DoShout(() =>
                    {
                        AudioManager.I.PlaySound(Sfx.DogBarking);
                    });
                }
                else
                {
                    nextAnturaBarkTimer -= Time.deltaTime;
                }
            }

            if (distance.sqrMagnitude < 0.1f)
            {
                // reached
                if (IsAnturaTime)
                {
                    SetRandomTarget();
                }
            }
            else
            {
                distance.Normalize();
                transform.position += distance * Mathf.Abs(Vector3.Dot(distance, transform.forward)) * ANTURA_SPEED * Time.deltaTime;
                GameplayHelper.LerpLookAtPlanar(transform, target, Time.deltaTime * 4);
            }
        }
    void PlayerSpottedEvent(Vector3 _playerPosition)
    {
        if (ignoreAlert)
        {
            return;
        }
        if (GameplayHelper.GetSquaredDistanceBetween(_playerPosition, gameObject.transform.position) > alertDistance * alertDistance)
        {
            return;
        }

        //Debug.Log("PlayerSpottedEvent");
        lastKnownPlayerPosition = _playerPosition;

        // We already see the player.
        if (canSeePlayerPrevious)
        {
            return;
        }

        chaseGiveUpTimer = chaseGiveUpDuration;
        // flowAI.Swap(chaseNodeId, flowAI.currentNode.localId);
        flowAI.Transition(chaseNodeId);
    }
Example #16
0
        void Update()
        {
            if (isSliping)
            {
                transform.position += lastVelocity * Time.deltaTime;

                var velMagnitude = lastVelocity.magnitude;

                if (velMagnitude > 1)
                {
                    lastVelocity -= 10 * lastVelocity.normalized * Time.deltaTime;
                }
                else
                {
                    lastVelocity = Vector3.Lerp(lastVelocity, Vector3.zero, 4 * Time.deltaTime);
                }

                if (lastVelocity.magnitude < 0.2f)
                {
                    isSliping   = false;
                    runningTime = 0;
                    AnimationController.OnSlipEnded();
                }

                return;
            }

            if (!IsSleeping && !IsJumping && target != null)
            {
                var distance = target.position - transform.position;
                distance.y = 0;

                var   distMagnitude = distance.magnitude;
                float speed         = 0;

                if (!IsNearTargetPosition)
                {
                    wasNearPosition = false;
                    float speedFactor = Mathf.Lerp(0, 1, distMagnitude / 10);
                    speed = Mathf.Lerp(WALK_SPEED, RUN_SPEED, speedFactor) * Mathf.Lerp(0, 1, distMagnitude);
                    AnimationController.SetWalkingSpeed(speedFactor);

                    if (speedFactor > 0.75f)
                    {
                        runningTime += Time.deltaTime;
                    }
                    else
                    {
                        if (runningTime > 1.3f && Excited)
                        {
                            // Slip!
                            runningTime = 0;
                            isSliping   = true;
                            AnimationController.OnSlipStarted();
                            Update();
                            return;
                        }

                        runningTime = 0;
                    }
                }
                else
                {
                    wasNearPosition = true;
                }

                if (speed > 0.05f)
                {
                    AnimationController.State = AnturaAnimationStates.walking;

                    if (AnimationController.IsAnimationActuallyWalking)
                    {
                        distance.Normalize();

                        var steeringMovement = transform.forward * speed * Time.deltaTime;
                        var normalMovement   = distance * Mathf.Abs(Vector3.Dot(distance, transform.forward)) * speed * Time.deltaTime;

                        transform.position += Vector3.Lerp(steeringMovement, normalMovement,
                                                           10.0f * Vector3.Dot(transform.forward.normalized, distance.normalized));

                        GameplayHelper.LerpLookAtPlanar(transform, target.position, Time.deltaTime * 2);
                    }
                }
                else
                {
                    var dot = Mathf.Max(0, Vector3.Dot(target.forward.normalized, transform.forward.normalized));

                    if (rotatingBase)
                    {
                        Quaternion targetRotation;

                        transform.SetParent(rotatingBase);

                        if (rotateAsTarget)
                        {
                            targetRotation = target.rotation * rotatingBase.rotation;
                        }
                        else
                        {
                            targetRotation = rotatingBase.rotation;
                        }
                        transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, Time.deltaTime * 4);
                    }
                    else
                    {
                        if (rotateAsTarget)
                        {
                            transform.rotation = Quaternion.Slerp(transform.rotation, target.rotation,
                                                                  Time.deltaTime * 4 * (0.2f + 0.8f * dot));
                        }
                        if ((!rotateAsTarget || dot > 0.9f) && AnimationController.State == AnturaAnimationStates.walking)
                        {
                            AnimationController.State = AnturaAnimationStates.idle;
                        }
                    }
                }
            }
            lastVelocity = (transform.position - lastPosition) / Time.deltaTime;
            lastPosition = transform.position;
        }
 public void LerpLookAt(Vector3 position, float t)
 {
     GameplayHelper.LerpLookAtPlanar(transform, position, t);
 }
 public void LookAt(Vector3 position)
 {
     GameplayHelper.LerpLookAtPlanar(transform, position, 1);
 }