Esempio n. 1
0
    void CalculateDownSpeedInc()
    {
        float toMaxSpeed = currentMoveAfter - maxMoveAfter; //we find how much we need to increase the currentMoveAfter till we reach the max value

        downSpeedInc = toMaxSpeed / distance;               //then we check how much to increase the current moveAfter each time the aliens move down
        downSpeedInc = ProjectMethods.TwoDecimalRound(downSpeedInc);
    }
Esempio n. 2
0
    void Move()
    {
        //moves in the direction of the x axis
        Vector2 newPosition = transform.right * speed * Time.deltaTime;
        Vector2 moveTo      = rb2d.position + newPosition;

        moveTo.x = ProjectMethods.TwoDecimalRound(moveTo.x);
        rb2d.MovePosition(moveTo);
    }
Esempio n. 3
0
    void MoveDown()
    {
        Vector3 moveTo = transform.position;

        moveTo.y          -= moveDownBy;
        moveTo.y           = ProjectMethods.TwoDecimalRound(moveTo.y);
        transform.position = moveTo;
        GoingDownSpeedUp();
    }
Esempio n. 4
0
    public void Move(float direction)
    {
        Vector2 newPosition = new Vector2(direction * speed * Time.deltaTime, 0f);

        BoundToScreen(rb2d.position, ref newPosition);
        Vector2 moveTo = rb2d.position + newPosition;

        moveTo.x = ProjectMethods.TwoDecimalRound(moveTo.x);
        rb2d.MovePosition(moveTo); //apply the new position to the object
    }
Esempio n. 5
0
    private void BoundToScreen(Vector2 startPos, ref Vector2 position)
    {
        //we add the speed to the current position
        Vector2 positionToCheck = startPos + position;

        positionToCheck.x = ProjectMethods.TwoDecimalRound(positionToCheck.x);
        //check if the player is going to go off the screen
        if (Camera.main.WorldToScreenPoint(positionToCheck + (bc2d.size / 2)).x > Screen.width || Camera.main.WorldToScreenPoint(positionToCheck - bc2d.size / 2).x < 0)
        {
            //if it does the speed gets set to zero
            position = Vector2.zero;
        }
    }
Esempio n. 6
0
    /* Delta time Movement
     * void MoveAliens()
     * {
     *  Vector2 newPosition = new Vector2(currentSpeed * Time.deltaTime, 0f); //we calculate the newposition
     *  ChangeDirection(newPosition); //checks to see if direction should change
     *  newPosition *= direction; //apply the direction to the newposition
     *  for (int i = 0; i < alienRb2ds.Count; i++) //apply the newposition to all aliens
     *  {
     *      Vector2 moveTo = alienRb2ds[i].position + newPosition;
     *      moveTo.x = ProjectMethods.PixelRound(moveTo.x);
     *      alienRb2ds[i].MovePosition(moveTo);
     *  }
     * }
     */
    void MoveAliens()
    {
        Vector2 newPosition = new Vector2(speed, 0f); //we calculate the newposition

        ChangeDirection(newPosition);                 //checks to see if direction should change
        newPosition *= direction;                     //apply the direction to the newposition
        for (int i = 0; i < alienComps.Count; i++)    //apply the newposition to all aliens
        {
            Vector2 moveTo = alienComps[i].rb2d.position + newPosition;
            moveTo.x = ProjectMethods.TwoDecimalRound(moveTo.x);
            if (alienComps[i].rb2d != null)
            {
                alienComps[i].rb2d.MovePosition(moveTo);
            }
            alienComps[i].animController.SetTick();
        }
    }
Esempio n. 7
0
 void ChangeDirection(Vector2 moveBy)
 {
     //Here we look for the alien that is going to reach the edge of the screen
     for (int i = 0; i < alienComps.Count; i++)
     {
         //we apply the current direction to the newposition
         //and we add it to the current position of the allien
         Vector2 moveTo = alienComps[i].rb2d.position + (moveBy * direction);
         moveTo.x = ProjectMethods.TwoDecimalRound(moveTo.x); //rounds the position so it had 2 decimal points
         //then we check if we reached the edge of the screen
         if (Camera.main.WorldToScreenPoint(moveTo + (alienComps[i].bc2d.size / 2)).x > Screen.width || Camera.main.WorldToScreenPoint(moveTo - (alienComps[i].bc2d.size / 2)).x < 0)
         {
             direction *= -1; //direction gets changed
             MoveDown();      //and all aliens are moved down
             break;           //we break from the loop because we changed direction
         }
     }
 }