Ejemplo n.º 1
0
 public void Init(VehicleDirection vehicleDirection, RelativePositionCars relativePositionCars, SignPriorityWay signValue)
 {
     _movementAtCrossroad  = GetComponent <PointMovement>();
     _signValue            = signValue;
     _relativePositionCars = relativePositionCars;
     _vehicleDirection     = vehicleDirection;
     EnableTurnSignalCar(vehicleDirection);
 }
Ejemplo n.º 2
0
    public void Init(Car car)
    {
        VehicleDirection vehicleDirection = car.direction;

        _sidesMovement[(int)vehicleDirection].SetActive(true);                             //включаем необходимые точки и коллайдер

        car.movementAtCrossroad.SetPointsMovement(_pointsMovement[(int)vehicleDirection]); //задаем точки текущего направления для NavMesh
        _colliderPointsMovement = _colliderSides[(int)vehicleDirection];                   //коллайдер текущего направления для определения пересечений
        car.SetCarRoute(_colliderPointsMovement.bounds);                                   //Границы коллайдера
    }
Ejemplo n.º 3
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="Vehicle" /> class.
        ///     Precondition: speed &gt; 0
        ///     Postcondition: A vehicle objected is created
        /// </summary>
        /// <param name="direction">The direction of the vehicle's movement.</param>
        /// <param name="speed">The speed of the vehicle.</param>
        /// <exception cref="ArgumentOutOfRangeException">speed</exception>
        protected Vehicle(VehicleDirection direction, int speed)
        {
            if (speed <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(speed));
            }

            this.Direction = direction;
            SetSpeed(speed, 0);
        }
Ejemplo n.º 4
0
 public void EnableTurnSignalCar(VehicleDirection vehicleDirection)
 {
     if (vehicleDirection == VehicleDirection.left)
     {
         _turnSignalLeft.SetActive(true);
     }
     else if (vehicleDirection == VehicleDirection.right)
     {
         _turnSignalRight.SetActive(true);
     }
 }
Ejemplo n.º 5
0
    /*
     * Spawns a random enemy
     */
    void SpawnEnemy(float roadZ)
    {
        //TODO: Generate random enemy

        // generates random side position
        float enemyX = 0;
        float enemyZ = 0;


        // chooses what enemy to spawn
        int        enemyType = Random.Range(0, 3);
        GameObject vehicle   = pfVehicles[0];

        if (enemyType == 0)
        {
            vehicle = pfPoliceCar;
        }
        if (enemyType == 1)
        {
            vehicle = pfAmbulance;
        }
        if (enemyType == 2)
        {
            vehicle = pfVehicles[Random.Range(0, pfVehicles.Count)];
        }

        // defines a direction (left or right) and sets the lane position
        VehicleDirection direction = (VehicleDirection)Random.Range(0, 2);

        switch (direction)
        {
        case VehicleDirection.Left:
            enemyX = settings.GameRightBoundary;
            enemyZ = roadZ + (2 * Constants.PathSizeZ + 1) + Constants.PathSizeZ / 2;
            break;

        case VehicleDirection.Right:
            enemyX = settings.GameLeftBoundary;
            enemyZ = roadZ + Constants.PathSizeZ + Constants.PathSizeZ / 2;
            break;
        }
        Vector3 enemyPosition = new Vector3(enemyX, 2, enemyZ);

        // instantiates enemy at position
        GameObject enemy = InstantiateSceneObject(vehicle, enemyPosition);
        VehicleAI  model = enemy.GetComponent <VehicleAI>();

        model.SetDirection(direction);
        model.Go();
    }
Ejemplo n.º 6
0
    /*
     * Sets the direction of this vehicle
     */
    public void SetDirection(VehicleDirection d)
    {
        direction = d;

        // define target point
        if (d == VehicleDirection.Left)
        {
            target = new Vector3(settings.GameLeftBoundary - 50, transform.position.y, transform.position.z);
        }
        else if (d == VehicleDirection.Right)
        {
            transform.rotation *= Quaternion.Euler(0, 0, 180f);
            target              = new Vector3(settings.GameRightBoundary + 50, transform.position.y, transform.position.z);
        }
    }
Ejemplo n.º 7
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="models">The list of vehicle models in this row</param>
 /// <param name="offsetDistance">The offset distance (fudge factor)</param>
 /// <param name="pixelsPerSecond">Speed</param>
 /// <param name="ghost">Ghosting</param>
 /// <param name="direction">Direction of travel</param>
 /// <param name="cooldownPeriod">Cooldown period</param>
 public VehicleRowModel(IEnumerable <VehicleModel> models,
                        float offsetDistance       = 0f,
                        float pixelsPerSecond      = 32f,
                        VehicleGhost ghost         = VehicleGhost.Ghost,
                        VehicleDirection direction = VehicleDirection.LeftToRight,
                        float cooldownPeriod       = -1)
 {
     Vehicles.AddRange(models);
     OffsetRight    = Vector2.Zero;
     Speed          = pixelsPerSecond;
     OffsetLeft     = new Vector2(-(224 + offsetDistance), 0);
     Ghost          = ghost;
     OffsetDistance = offsetDistance;
     Direction      = direction;
     CooldownPeriod = cooldownPeriod;
 }
Ejemplo n.º 8
0
    /*
     * Given a lane, returns the start position of the vehicle on the chosen lane
     */
    LaneDirection GetVehicleStartPointOnLane(Lane lane)
    {
        Vector3          lanePosition = new Vector3(0, settings.vehicleDefaultY, 0);
        VehicleDirection direction    = VehicleDirection.Left;

        switch (lane)
        {
        case Lane.NormalLeftDirection:
            lanePosition.x = settings.GameRightBoundary;
            lanePosition.z = transform.position.z + Constants.LaneNormalLeftDirectionZ;
            direction      = VehicleDirection.Left;
            break;

        case Lane.NormalRightDirection:
            lanePosition.x = settings.GameLeftBoundary;
            lanePosition.z = transform.position.z + Constants.LaneNormalRightDirectionZ;
            direction      = VehicleDirection.Right;
            break;

        case Lane.AvenueLeftDirectionL:
            lanePosition.x = settings.GameRightBoundary;
            lanePosition.z = transform.position.z + Constants.LaneAvenueLeftDirectionLZ;
            direction      = VehicleDirection.Left;
            break;

        case Lane.AvenueLeftDirectionR:
            lanePosition.x = settings.GameRightBoundary;
            lanePosition.z = transform.position.z + Constants.LaneAvenueLeftDirectionRZ;
            direction      = VehicleDirection.Left;
            break;

        case Lane.AvenueRightDirectionL:
            lanePosition.x = settings.GameLeftBoundary;
            lanePosition.z = transform.position.z + Constants.LaneAvenueRightDirectionLZ;
            direction      = VehicleDirection.Right;
            break;

        case Lane.AvenueRightDirectionR:
            lanePosition.x = settings.GameLeftBoundary;
            lanePosition.z = transform.position.z + Constants.LaneAvenueRightDirectionRZ;
            direction      = VehicleDirection.Right;
            break;
        }

        return(new LaneDirection(lanePosition, direction));
    }
Ejemplo n.º 9
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="Car" /> class.
 ///     Precondition: none
 ///     Postcondition: A new Car object is created
 /// </summary>
 /// <param name="direction">The Direction.</param>
 /// <param name="speed">The speed.</param>
 public Car(VehicleDirection direction, int speed) :
     base(direction, speed)
 {
     this.initializeCarSprite();
 }
Ejemplo n.º 10
0
 public LaneDirection(Vector3 pos, VehicleDirection dir)
 {
     direction     = dir;
     startPosition = pos;
 }
Ejemplo n.º 11
0
 public RiverRowModel(IEnumerable <VehicleModel> models, float offsetDistance, float pixelsPerSecond, VehicleDirection direction, Rectangle bounds)
     : base(models, offsetDistance, pixelsPerSecond, VehicleGhost.Ghost, direction, -1)
 {
     Bounds = bounds;
 }
Ejemplo n.º 12
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="Truck" /> class.
 ///     Precondition: None
 ///     Postcondition: A Truck object is created
 /// </summary>
 /// <param name="direction">The Direction.</param>
 /// <param name="speed">The speed.</param>
 public Truck(VehicleDirection direction, int speed) :
     base(direction, speed)
 {
     this.initializeTruckSprite();
 }