示例#1
0
    public Vector3 ChooseOptimalPathtoProjectile(GameManager.ProjectileInfo info)
    {
        Vector3 ProjectilePosition = info.Projectile.transform.position;

        if (transform.position.y < ProjectilePosition.y)
        {
            if (info.Projectile.Position.x == manager.controller.BucketBoxPosition(transform.position).x)
            {
                return(info.Projectile.transform.position);
            }
        }

        float   timeNeeded    = CalculateTimeForArrival(transform.position, info.Projectile.transform.position);
        Vector3 newlocation   = PredictProjectileLocationInTime(info, timeNeeded);
        float   newTimeNeeded = CalculateTimeForArrival(transform.position, newlocation);

        if (newTimeNeeded < timeNeeded)
        {
            newlocation.y -= (Projectile.velocity * Mathf.Abs(timeNeeded - newTimeNeeded));
        }


        if (manager.controller.BucketBoxPosition(newlocation) == new Pair(-1, -1))
        {
            if ((int)CalculateTimeForXArrival(transform.position, info.Projectile.transform.position) > (int)ProjectileLifetime(info))
            {
                //Debug.Log("Unable to Reach Projectile");
                //return manager.controller.GetBoxCoordinatesInWorldFrame(manager.GridCenter.x, manager.GridCenter.y);
            }
            return(new Vector3(0, transform.position.y, info.Projectile.transform.position.z));
        }

        return(newlocation);
    }
示例#2
0
    private float ProjectileLifetime(GameManager.ProjectileInfo info)
    {
        Vector3 transformedDestination = manager.controller.UIContainer.transform.TransformPoint(new Vector3(manager.controller.xStartValue, manager.controller.yStartValue, 0));
        float   ydistance = Mathf.Abs(info.Projectile.transform.position.y - manager.mainCamera.ScreenToWorldPoint(new Vector3(transformedDestination.x, transformedDestination.y, 1.1f)).y);

        return(ydistance / -Projectile.velocity);
    }
示例#3
0
 public double RewardWithTime(GameManager.ProjectileInfo info, GameManager manager)
 {
     if (info.IsCaught == GameManager.Caught.Yes)
     {
         return(-((manager.controller.xIntervalCount + manager.controller.yIntervalCount - 2) - ManhattanDistance(manager.GridCenter, info.StartPosition)));
     }
     else
     {
         return(MissedValue);
     }
 }
示例#4
0
    private void FixedUpdate()
    {
        if (manager.controller.Arrow.IsVisible && !IsMoving)
        {
            StopAllCoroutines();
            //StartCoroutine(MoveToHome());
            TeleportHome();
            IsMoving = true;
            return;
        }

        if (IsMoving && TrackedProjectile == null && !(manager.controller.Arrow.IsVisible))
        {
            IsMoving = false;
        }

        if (TrackedProjectile == null)
        {
            TrackedProjectile = manager.GetVisibleProjectile();
            if (TrackedProjectile == null)
            {
                return;
            }
        }

        if (TrackedProjectile.IsCaught == GameManager.Caught.Undetermined)
        {
            if (!IsMoving)
            {
                PredictedPosition = ChooseOptimalPathtoProjectile(TrackedProjectile);
                StartCoroutine(MoveToPosition(PredictedPosition, Velocity));
                IsMoving = true;
            }
            else
            {
                if (PredictedPosition != ChooseOptimalPathtoProjectile(TrackedProjectile))
                {
                    PredictedPosition = ChooseOptimalPathtoProjectile(TrackedProjectile);
                    StopAllCoroutines();
                    StartCoroutine(MoveToPosition(PredictedPosition, Velocity));
                    IsMoving = true;
                }
            }
            //EstimateVelocity();
        }
        else
        {
            TrackedProjectile = null;
            IsMoving          = false;
            StopAllCoroutines();
        }
        UpdateVelocity();
    }
示例#5
0
 public Vector3 PredictProjectileLocationInTime(GameManager.ProjectileInfo info, float additionaltime)
 {
     //additionaltime -= Mathf.Abs(CalculateTimeForArrival(Mathf.Abs(transform.position.y - info.Projectile.transform.position.y)) / 3f);
     if (info.IsCaught == GameManager.Caught.Undetermined)
     {
         Vector3 predicted_position = info.Projectile.transform.position;
         predicted_position.y += (Projectile.velocity * additionaltime);
         return(predicted_position);
     }
     else
     {
         return(new Vector3(0, 0, 0));
     }
 }
示例#6
0
    public Vector3 PredictProjectileLocationInTime(GameManager.ProjectileInfo info, float additionaltime)
    {
        if (info.IsCaught == GameManager.Caught.Undetermined)
        {
            float deltay = info.Projectile.rigidBody.velocity.y * additionaltime;

            Vector3 predicted_position = info.Projectile.transform.position;
            predicted_position.y += deltay;

            return(predicted_position);
        }
        else
        {
            return(new Vector3(0, 0, 0));
        }
    }
示例#7
0
 public void SendBucketCoordinates(GameManager.ProjectileInfo projectile, double elapsed_time, Pair user_pos)
 {
     if (projectile == null)
     {
         return;
     }
     if (!projectile.Position.IsValid())
     {
         return;
     }
     bucket_coordinates.msg = new Message("|" + projectile.ID + "|" + ((int)(user_pos.x)) + "|" + ((int)user_pos.y) + "|" + projectile.IsCaught.ToString() + "|" + ((int)projectile.Position.x) + "|" + ((int)projectile.Position.y) + "|" + elapsed_time.ToString() + "|");
     if (ws.IsAlive && (("|" + projectile.ID + "|" + user_pos.x + "|" + user_pos.y + "|" + projectile.IsCaught.ToString() + "|" + projectile.Position.x + "|" + projectile.Position.y + "|") != projectile.LastSubmitted))
     {
         ws.Send(JsonUtility.ToJson(bucket_coordinates));
         projectile.LastSubmitted = "|" + projectile.ID + "|" + user_pos.x + "|" + user_pos.y + "|" + projectile.IsCaught.ToString() + "|" + projectile.Position.x + "|" + projectile.Position.y + "|";
     }
 }
示例#8
0
    public Vector3 ChooseOptimalPathtoProjectile(GameManager.ProjectileInfo info)
    {
        Vector3 PlayerPosition     = manager.controller.UIContainer.transform.InverseTransformPoint(manager.mainCamera.WorldToScreenPoint(User.transform.position));
        Vector3 ProjectilePosition = manager.controller.UIContainer.transform.InverseTransformPoint(manager.mainCamera.WorldToScreenPoint(info.Projectile.transform.position));

        if (PlayerPosition.y < ProjectilePosition.y)
        {
            if (info.Projectile.Position.x == manager.controller.BucketBoxPosition(User.transform.position).x)
            {
                return(info.Projectile.transform.position);
            }
        }

        float timeNeeded = CalculateTimeForArrival(PlayerPosition, info.Projectile.Position, CurrentSpeed);

        return(PredictProjectileLocationInTime(info, timeNeeded));
    }
示例#9
0
 // Update is called once per frame
 void FixedUpdate()
 {
     if (manager.controller.Arrow.IsVisible && !Moving)
     {
         StopAllCoroutines();
         StartCoroutine(MoveToHome());
         Moving = true;
         return;
     }
     if (CurrentProjectile == null)
     {
         CurrentProjectile = manager.GetVisibleProjectile();
     }
     else
     {
         if (CurrentProjectile.IsCaught == GameManager.Caught.Undetermined)
         {
             if (!Moving)
             {
                 PredictedPosition = ChooseOptimalPathtoProjectile(CurrentProjectile);
                 //StartCoroutine(MoveToPosition(PredictedPosition, CurrentSpeed));
                 StartCoroutine(test.MoveToPosition(PredictedPosition, 1));
                 Moving = true;
             }
             else
             {
                 if (PredictedPosition != ChooseOptimalPathtoProjectile(CurrentProjectile))
                 {
                     PredictedPosition = ChooseOptimalPathtoProjectile(CurrentProjectile);
                     StopCoroutine(test.MoveToPosition(PredictedPosition, 1));
                     StartCoroutine(test.MoveToPosition(PredictedPosition, 1));
                     //StopCoroutine("MoveToPosition");
                     //StartCoroutine(MoveToPosition(PredictedPosition, CurrentSpeed));
                 }
             }
         }
         else
         {
             CurrentProjectile = null;
             Moving            = false;
             StopAllCoroutines();
         }
     }
 }
示例#10
0
 private int TimeReward(GameManager.ProjectileInfo info)
 {
     return(TimePenalty * (int)((info.TimeLanded - info.TimeLaunched) / 1000));
 }