コード例 #1
0
 /**
  * L'ennemi est en attente s'il est arrivé au waypoint prévu
  * */
 public void Move()
 {
     if (_enemyModel.Health > 0)
     {
         if (_enemyView.IsWaiting)
         {
             if (_wavepointIndex >= Waypoints.GetNumberOfWaypoints())
             {
                 //L'ennemi est arrivé au point de fin
                 NotifyObservers();
                 _enemyView.Die();
                 GameController.HealthDown();
             }
             else
             {
                 _enemyView.Move(Waypoints.GetWaypoints(_wavepointIndex), _enemyModel.Speed);
                 ++_wavepointIndex;
             }
         }
         else
         {
             _enemyView.Move(Waypoints.GetWaypoints(_wavepointIndex - 1), _enemyModel.Speed);
         }
     }
     else
     {
         //L'ennemi à été tué
         NotifyObservers();
         Die();
         GameData.Money = GameData.Money + 5;
     }
 }
コード例 #2
0
    // updates the position of the enemy
    private void UpdateMotion()
    {
        eSpeed = enemiesController.GetEnemySpeed();

        RB.MovePosition(transform.position + (transform.TransformDirection(Vector3.up) * eSpeed * Time.deltaTime));
        distanceToWaypoint = Vector3.Distance(heading.position, transform.position);
        flightOrder        = enemiesController.FlightOrder();

        // if enemy reached waypoint, assign new waypoint
        if (distanceToWaypoint < waypointThreshold)
        {
            if (flightOrder)
            {
                // ordered flight pattern
                headingIndex++;

                // check overflow, reassign to 0 if at end
                if (headingIndex > waypoints.GetNumberOfWaypoints() - 1)
                {
                    headingIndex = 0;
                }

                heading = waypoints.GetWaypoint(headingIndex).transform;
            }
            else
            {
                // random flight pattern
                heading = waypoints.GetRNGWaypoint().transform;
            }
            NewDirection();
        }
    }