Exemple #1
0
 // Update is called once per frame
 void Update()
 {
     if (!controller.playerInfo.dead)
     {
         if (controller.playerInfo.inputEnabled)
         {
             input = new Vector2(Input.GetAxisRaw(horizontal), Input.GetAxisRaw(vertical));
             input = input.normalized;
             controller.playerInfo.input = input;
             if (Input.GetButtonDown(driveOne))
             {
                 powerupController.UsePowerup(0);
             }
             else if (Input.GetButtonDown(driveTwo))
             {
                 powerupController.UsePowerup(1);
             }
         }
     }
 }
Exemple #2
0
    public void NextMovement(ref Vector2 input)
    {
        if (controller.playerInfo.inputEnabled)
        {
            Vector2 direction = Vector2.zero;
            if (dangerZone)
            {
                RaycastHit2D hit = Physics2D.Raycast(ball.transform.position, ball.velocity, Mathf.Infinity, ballCollisionMask);

                if (hit)
                {
                    if (!controller.playerInfo.onDash)
                    {
                        for (int i = 0; i < powerupController.powerups.Length; i++)
                        {
                            if (powerupController.powerups[i] == PowerupController.Powerups.Dash)
                            {
                                powerupController.UsePowerup(i);
                                break;
                            }
                        }
                    }
                    if (!controller.playerInfo.onZhonya)
                    {
                        for (int i = 0; i < powerupController.powerups.Length; i++)
                        {
                            if (powerupController.powerups[i] == PowerupController.Powerups.Zhonya)
                            {
                                powerupController.UsePowerup(i);
                                break;
                            }
                        }
                    }
                }
                else
                {
                    dangerZone = false;
                }
            }
            if (!dangerZone && spawner.instantiatedPickup != null && timeToCatchPickupRemaining < timeToCatchPickup)
            {
                timeToCatchPickupRemaining += Time.deltaTime;
                if (path != null)
                {
                    if (currentWaypoint < path.vectorPath.Count)
                    {
                        // Direction to the next waypoint
                        direction = (path.vectorPath[currentWaypoint] - transform.position).normalized;
                        if (Vector2.Distance(transform.position, path.vectorPath[currentWaypoint]) < nextWaypointDistance)
                        {
                            currentWaypoint++;
                        }
                    }
                    else
                    {
                        path = null;
                    }
                }
                else
                {
                    seeker.StartPath(transform.position, spawner.instantiatedPickup.transform.position, OnPathComplete);
                }
                //	Calculate path to powerup
                //Vector2 powerupPosition = spawner.instantiatedPowerup.transform.position;

                //direction = new Vector2(powerupPosition.x - transform.position.x, powerupPosition.y - transform.position.y);
            }
            else
            {
                for (int i = 0; i < powerupController.powerups.Length; i++)
                {
                    if (powerupController.powerups[i] == PowerupController.Powerups.Freeze)
                    {
                        if (Random.Range((int)1, (int)100000) < 10)
                        {
                            powerupController.UsePowerup(i);
                        }
                    }
                }

                //	Reset try to catch pickup
                if (spawner.instantiatedPickup == null)
                {
                    timeToCatchPickupRemaining = 0f;
                }
                direction = ball.velocity.Rotate(90f);

                if (Mathf.Sign(ball.velocity.x) == 1 &&
                    transform.position.x <= ball.transform.position.x &&
                    Mathf.Sign(direction.x) == 1)
                {
                    direction.x *= -1;
                }

                if (Mathf.Sign(ball.velocity.x) == -1 &&
                    transform.position.x >= ball.transform.position.x &&
                    Mathf.Sign(direction.x) == -1)
                {
                    direction.x *= -1;
                }

                if (Mathf.Sign(ball.velocity.y) == 1 &&
                    transform.position.y <= ball.transform.position.y &&
                    Mathf.Sign(direction.y) == 1)
                {
                    direction.y *= -1;
                }

                if (Mathf.Sign(ball.velocity.y) == -1 &&
                    transform.position.y >= ball.transform.position.y &&
                    Mathf.Sign(direction.y) == -1)
                {
                    direction.y *= -1;
                }
            }
            input = direction.normalized;
            controller.playerInfo.input = input;
        }
    }