Exemple #1
0
        public bool BallInlineWithGoal(PlayerWrapper car, BallWrapper ball)
        {
            var ballInlineWithGoal = false;
            var enemyGoal          = GetEnemyGoal();

            var carToGoalAngle  = Math.Atan2(enemyGoal.Y - car.Location.Y, enemyGoal.X - car.Location.X);
            var ballToGoalAngle = Math.Atan2(enemyGoal.Y - ball.Location.Y, enemyGoal.X - ball.Location.X);

            var range = 45;

            if (ballToGoalAngle <= (carToGoalAngle + range) && ballToGoalAngle >= (carToGoalAngle - range))
            {
                // Correct the angle
                if (carToGoalAngle < -Math.PI)
                {
                    carToGoalAngle += 2 * Math.PI;
                }
                else if (carToGoalAngle > Math.PI)
                {
                    carToGoalAngle -= 2 * Math.PI;
                }

                ballInlineWithGoal = true;
            }

            return(ballInlineWithGoal);
        }
Exemple #2
0
        public Vec3 GetStrikeLocation(BallWrapper ballWrappper, Vec3 target)
        {
            var ball = GetProjectedBall();

            // var ball = ballWrappper;
            if (ball == null)
            {
                return(new Vec3(0, 0, 0));
            }

            // var opposite = Math.Abs((ball.Location.X - target.X));
            var hyotenuse     = Field.GetDist(ball.Location, target);
            var opposite      = ball.Location.X - target.X;
            var theta         = Math.Asin(opposite / hyotenuse);
            var newHypotenuse = GameValuesService.BallRadius + hyotenuse;

            var strikeX = GameValuesService.BallRadius * Math.Cos(theta) + ball.Location.X;
            var strikeY = GameValuesService.BallRadius * Math.Sin(theta) + ball.Location.Y;

            strikeX += ball.Velocity.X;
            strikeY += ball.Velocity.Y;

            var strikeLocation = new Vec3((float)strikeX, (float)strikeY, ball.Location.Z);

            System.Console.WriteLine($"===========================");
            System.Console.WriteLine($"Actual: ({Ball.Location.X}, {Ball.Location.Y}, {Ball.Location.Z})");
            System.Console.WriteLine($"Predicted: ({ball.Location.X}, {ball.Location.Y}, {ball.Location.Z})");
            System.Console.WriteLine($"DeltaTime: {ball.DeltaTime}");
            System.Console.WriteLine($"GameTime: {ball.GameTime}");
            System.Console.WriteLine($"ActualTime: {Game.TimeElapsed}");
            System.Console.WriteLine($"===========================");

            return(strikeLocation);
        }
Exemple #3
0
    //  public Transform bulletPrefab;


    // void Start ()
    // {
    //     // Call the Spawn functio

    //     //Transform bullet = Instantiate(bulletPrefab) as Transform;
    //     //Physics.IgnoreCollision(bullet.GetComponent<Collider>(), GetComponent<Collider>());



    //     // for (int i = 1; i <= NumOfNotes; ++i)
    //     //   notes.Add(Resources.Load<AudioClip>(i+""));
    //     // spawnPoints = new Transform[LENGTH];
    //     // for (int i =0; i < LENGTH; ++i)
    //     //   {
    //     //   spawnPoints[i].position = Vector3.forward * 10;
    //     //   }
    // }

    void Update()
    {
        for (int i = 0; i < Parent.BulletBallList.Count;)
        {
            BallWrapper wr = (BallWrapper)Parent.BulletBallList[i];
            GameObject  b  = wr.BulletBall;
            if (b != null && b.transform.position.z <= InnerRadius)
            {
                Parent.BulletBallList.RemoveAt(i);
                //wr.audioSource.Stop();
                Destroy(b);
                double t0 = AudioSettings.dspTime;
                // double clipTime1 = len1;
                // clipTime1 /= cutClip1.frequency;
                wr.audioSource.PlayScheduled(t0);
                wr.audioSource.SetScheduledEndTime(t0 + ClipTime);
            }
            else
            {
                i++;
            }

            //      else
            //{
            //// Vector3 pos = b.transform.position;
            //float updatedZ =  -1 * speed;
            ////Vector3 tmp(pos.x, pos.y, updatedZ);
            //float alpha = wr.angle;
            //b.transform.Translate(updatedZ * Mathf.Sin(alpha), 0, updatedZ * Mathf.Cos(alpha));
            //i++;
            //}
        }
    }
        public static List <LocationPrediction> GetPredictions(BallWrapper ball, FieldService field, GameWrapper game)
        {
            var predictions = new List <LocationPrediction>
            {
                new LocationPrediction
                {
                    DeltaTime = 0,
                    GameTime  = game.TimeElapsed,
                    Location  = new Vec3(ball.Location.X, ball.Location.Y, ball.Location.Z),
                    Velocity  = new Vec3(ball.Velocity.X, ball.Velocity.Y, ball.Velocity.Z)
                }
            };

            var timeSpan = .1f;

            for (var i = 1; i < 10; i++)
            {
                var lastPrediction = predictions[i - 1];
                var newPrediction  = GetPrediction(lastPrediction, field, game, timeSpan);
                predictions.Add(newPrediction);
            }


            return(predictions);
        }
Exemple #5
0
 public WrapBot(string botName, int botTeam, int botIndex) : base(botName, botTeam, botIndex)
 {
     State        = BotState.Kickoff;
     Action       = BotAction.Default;
     Controller   = new Controller();
     Field        = new FieldService(botTeam);
     Ball         = new BallWrapper();
     Info         = new PlayerWrapper();
     Game         = new GameWrapper();
     DesiredState = null;
 }
Exemple #6
0
        public bool BallIsInReach(PlayerWrapper car, BallWrapper ball)
        {
            var ballInReach = false;
            var ballRectX1  = ball.Location.X + (BallRadius() * 2);
            var ballRectX2  = ball.Location.X - (BallRadius() * 2);
            var ballRectY1  = ball.Location.Y + (BallRadius() * 2);
            var ballRectY2  = ball.Location.Y - (BallRadius() * 2);

            if (car.Location.X <= ballRectX1 && car.Location.X >= ballRectX2)
            {
                if (car.Location.Y <= ballRectY1 && car.Location.Y >= ballRectY2)
                {
                    ballInReach = true;
                }
            }

            return(ballInReach);
        }
Exemple #7
0
        public bool TowardMySide(BallWrapper ball)
        {
            var towardMySide = false;

            if (_team == 0)
            {
                if (ball.Velocity.Y < 0)
                {
                    towardMySide = true;
                }
            }
            else
            {
                if (ball.Velocity.Y > 0)
                {
                    towardMySide = true;
                }
            }

            return(towardMySide);
        }
Exemple #8
0
    // // Update is called once per frame
    // void Update () {

    // }
    //-5-------222---2xx--2--2-214---h15--1514
    void Spawn()
    {
        // If the player has no health left...
        // if(playerHealth.currentHealth <= 0f)
        // {
        //     // ... exit the function.
        //     return;
        // }
        //if(NumOfObjects )

        if (NumOfObjects >= MusicNotes.Length)
        {
            NumOfObjects = 0;
        }
        string node = MusicNotes[NumOfObjects];

        if (node == "-1")
        {
            NumOfObjects++;
            return;
        }
        // Find a random index between zero and one less than the number of spawn points.
        // int spawnPointIndex = Random.Range (0, spawnPoints.Length);
        float   alpha         = Random.Range(-10, 10 + 1) * ANGLE / 21.0f;
        Vector3 spawnPosition = new Vector3((float)(Radius * Mathf.Sin(alpha)), 0, (float)(Radius * Mathf.Cos(alpha)));
        // spawnPoints[spawnPointIndex].position = tmp;//.Translate(0, 0, 0);//Translate(X * Random.Range (-1, 1), 0 , Z * Random.Range (-1, 1));
        // spawnPoints[spawnPointIndex].position.z = ;
        // Create an instance of the enemy prefab at the randomly selected spawn point's position and rotation.
        BallWrapper wrapper = new BallWrapper();

        wrapper.BulletBall       = Instantiate(BulletBall, spawnPosition, Quaternion.identity) as GameObject;
        wrapper.angle            = alpha;
        wrapper.audioSource      = buildAudio();
        wrapper.audioSource.clip = (AudioClip)Resources.Load <AudioClip>(node);
        // wrapper.audioSource.Play();
        BulletBallList.Add(wrapper);

        NumOfObjects++;
    }
Exemple #9
0
        public bool IsBallOnMySide(BallWrapper ball)
        {
            var ballY    = ball.Location.Y;
            var onMySide = false;

            if (_team == 0)
            {
                if (ballY < 0)
                {
                    onMySide = true;
                }
            }
            else
            {
                if (ballY > 0)
                {
                    onMySide = true;
                }
            }

            return(onMySide);
        }
Exemple #10
0
    void Spawn()
    {
        // If the player has no health left...
        // if(playerHealth.currentHealth <= 0f)
        // {
        //     // ... exit the function.
        //     return;
        // }

        // Find a random index between zero and one less than the number of spawn points.
        int     spawnPointIndex = Random.Range(0, spawnPoints.Length);
        float   alpha           = Random.Range(-10, 10 + 1) * ANGLE / 21.0f;
        Vector3 tmp             = new Vector3((float)(Radius * Mathf.Sin(alpha)), 0, (float)(Radius * Mathf.Cos(alpha)));

        spawnPoints[spawnPointIndex].position = tmp;//.Translate(0, 0, 0);//Translate(X * Random.Range (-1, 1), 0 , Z * Random.Range (-1, 1));
        // spawnPoints[spawnPointIndex].position.z = ;
        // Create an instance of the enemy prefab at the randomly selected spawn point's position and rotation.
        BallWrapper wrapper = new BallWrapper();

        wrapper.BulletBall = (GameObject)Instantiate(BulletBall, spawnPoints[spawnPointIndex].position, spawnPoints[spawnPointIndex].rotation);
        wrapper.angle      = alpha;
        BulletBallList.Add(wrapper);
    }
Exemple #11
0
    void Update()
    {
        for (int i = 0; i < BulletBallList.Count;)
        {
            BallWrapper wr = (BallWrapper)BulletBallList[i];
            GameObject  b  = wr.BulletBall;
            if (b.transform.position.z <= InnerRadius)
            {
                BulletBallList.RemoveAt(i);
                Destroy(b);
            }

            else
            {
                // Vector3 pos = b.transform.position;
                float updatedZ = -1 * speed;
                //Vector3 tmp(pos.x, pos.y, updatedZ);
                float alpha = wr.angle;
                b.transform.Translate(updatedZ * Mathf.Sin(alpha), 0, updatedZ * Mathf.Cos(alpha));
                i++;
            }
        }
    }