Esempio n. 1
0
 /// <summary>
 /// Activate this lane
 /// </summary>
 /// <param name="rowNumber">Indacates how far into the map the lane is</param>
 /// <param name="prevPassableTileArray">Passable tile array of the previous lane</param>
 /// <param name="prevDir">Direction of previous lane</param>
 public override void Activate(int rowNumber, bool[] prevPassableTileArray, LaneDirection prevDir)
 {
     base.Activate(rowNumber, prevPassableTileArray, prevDir);
     DeactivateWarningLights();
     CreateTrain();
     SpawnCoin();
 }
Esempio n. 2
0
        public RoadLane(Road road, LaneDirection lanedirection, LaneType lanetype, int laneindex, double width,
                        double translation)
        {
            int colorindex;

            if (lanedirection == LaneDirection.Backward)
                colorindex = laneindex;
            else
                colorindex = -laneindex - 1;

            curvecolor = Colors.GetSaturatedColor(colorindex);
            ILaneContainer = road;
            LaneDirection = lanedirection;
            LaneIndex = laneindex;
            LaneType = lanetype;
            linecolor = road.LineColor;
            this.road = road;
            roadcolor = road.RoadColor;
            this.translation = translation;
            vehiclelist = new List<Vehicle>();
            Width = width;

            setbeziers();
            setgaplengths();

            Length = beziers.Sum(bezier => bezier.Length);
            spawndistance = 2*road.GetMaximumSpeed("Vehicle")/beziers[0].Length;
        }
Esempio n. 3
0
 /// <summary>
 /// Activate this lane
 /// </summary>
 /// <param name="rowNumber">Indacates how far into the map the lane is</param>
 /// <param name="prevPassableTileArray">Passable tile array of the previous lane</param>
 /// <param name="prevDir">Direction of previous lane</param>
 public override void Activate(int rowNumber, bool[] prevPassableTileArray, LaneDirection prevDir)
 {
     base.Activate(rowNumber, prevPassableTileArray, prevDir);
     CreateEdgeItems();
     CreateObstacles(rowNumber, prevPassableTileArray);
     if (rowNumber > 1)
     {
         SpawnCoin();
     }
 }
    /// <summary>
    /// Positions the new lane and activates it
    /// </summary>
    /// <param name="newLane"></param>
    protected void ActivateLane(Lane newLane)
    {
        float laneZPos = (m_startRowCoord + m_currentCount) * m_mapManager.TileSize;

        newLane.transform.SetPosZ(laneZPos);
        newLane.gameObject.SetActive(true);
        newLane.Activate(m_startRowCoord + m_currentCount, m_prevPassableTileArray, m_prevDir);
        m_prevPassableTileArray = newLane.PassableActiveTileArray;
        m_prevDir = newLane.Direction;
        m_currentCount++;
    }
 /// <summary>
 /// Creates platforms
 /// </summary>
 private void CreatePlatforms(bool[] prevPassableTileArray, LaneDirection prevDir)
 {
     // Determine whether to spawn logs or lily pads
     if (Random.value <= m_lilyPadLaneProb)
     {
         SpawnLilyPads(prevPassableTileArray, prevDir);
     }
     else
     {
         StartLogSpawning(prevPassableTileArray, prevDir);
     }
 }
    /*
     * Spawns a random enemy
     */
    void SpawnEnemy()
    {
        if (normalVehicles.Count > 0 && emergencyVehicles.Count > 0)
        {
            GameObject    vehicle       = normalVehicles[0];
            LaneDirection laneDirection = null;

            // diferentiate between avenue or normal road
            if (avenue)
            {
                Lane lane = (Lane)Random.Range(2, 6);
                laneDirection = GetVehicleStartPointOnLane(lane);
            }
            else
            {
                Lane lane = (Lane)Random.Range(0, 2);
                laneDirection = GetVehicleStartPointOnLane(lane);
            }

            // generates emergency vehicle
            if (Random.value < Constants.Probability.ProbabilityLow)
            {
                vehicle = emergencyVehicles[Random.Range(0, emergencyVehicles.Count)];
            }
            else             // generates normal vehicle
            {
                vehicle = normalVehicles[Random.Range(0, normalVehicles.Count)];
            }


            // instantiates enemy at position
            GameObject enemy = InstantiateSceneObject(vehicle, laneDirection.startPosition);

            // saves new enemy on the list
            vehiclesOnLanes.Add(enemy);

            // sets the direction and orders to go
            VehicleController model = enemy.GetComponent <VehicleController>();
            model.SetDirection(laneDirection.direction);
            model.Go();
        }
    }
    public static LaneDirection GetEndDirection(LaneDirection direction)
    { // Converts a turn lane direction into an end direction.  ex. west_south turns into south_south
        string[] directions = direction.ToString().Split(new char[1] {
            '_'
        });                                                                    // index 0 is from direction, index 1 is to direction
        switch (directions[1])
        {
        case "north":
            return(LaneDirection.north_north);

        case "south":
            return(LaneDirection.south_south);

        case "east":
            return(LaneDirection.east_east);

        case "west":
            return(LaneDirection.west_west);
        }
        return(direction);
    }
Esempio n. 8
0
    /// <summary>
    /// Creates vehicles
    /// </summary>
    private void CreateVehicles(LaneDirection prevDir)
    {
        // Determine a random "regular" vehicle type
        VehicleType vehType   = (VehicleType)Random.Range(0, (int)VehicleType.Train);
        Vehicle     vehSample = m_mapAssetPool.GetVehicleAssetPool(vehType).GetAsset();

        // Determine speed and no. of vehicles
        float speed = vehSample.GetRandomSpeed();
        float spaceBetweenVehicles = Random.Range(m_minSpace, m_maxSpace) * m_tileSize;
        float totalMoveSpace       = (m_activeTileCount + (m_edgeTileCount * 2.0f)) * m_tileSize;
        float vehicleAndSpaceSize  = spaceBetweenVehicles + vehSample.VehicleLength;

        totalMoveSpace += vehSample.VehicleLength;
        int vehicleCount = Mathf.FloorToInt(totalMoveSpace / vehicleAndSpaceSize);

        // Randomly determine lane direction
        // Determine log direction
        switch (prevDir)
        {
        case LaneDirection.NONE:
            // Random direction
            m_direction = (Random.Range(0, 2) == 1) ? LaneDirection.RIGHT : LaneDirection.LEFT;
            break;

        case LaneDirection.LEFT:
        case LaneDirection.RIGHT:
            if (Random.value <= m_oppositeDirProb)
            {
                m_direction = (prevDir == LaneDirection.LEFT) ? LaneDirection.RIGHT : LaneDirection.LEFT;
            }
            else
            {
                m_direction = prevDir;
            }
            break;
        }

        // Spawn the vehicles properly spaced apart
        Vector3 pos1 = new Vector3(totalMoveSpace * -0.5f, m_height, 0f) + transform.position;
        Vector3 pos2 = new Vector3(totalMoveSpace * 0.5f, m_height, 0f) + transform.position;

        if (m_direction == LaneDirection.LEFT)
        {
            Vector3 temp = pos1;
            pos1 = pos2;
            pos2 = temp;
        }

        // Create the array of vehicles
        m_vehicles = new Vehicle[vehicleCount];

        m_vehicles[0] = vehSample;
        m_vehicles[0].gameObject.SetActive(true);
        m_vehicles[0].SetMapManagerInstance(m_mapManager);
        m_vehicles[0].StartMovement(speed, pos1, pos2, 0f);

        for (int i = 1; i < vehicleCount; ++i)
        {
            m_vehicles[i] = m_mapAssetPool.GetVehicleAssetPool(vehType).GetAsset();
            m_vehicles[i].gameObject.SetActive(true);
            float timeFactor = i / (float)vehicleCount;
            m_vehicles[i].SetMapManagerInstance(m_mapManager);
            m_vehicles[i].StartMovement(speed, pos1, pos2, timeFactor);
        }
    }
Esempio n. 9
0
 /// <summary>
 /// Activate this lane
 /// </summary>
 /// <param name="rowNumber">Indacates how far into the map the lane is</param>
 /// <param name="prevPassableTileArray">Passable tile array of the previous lane</param>
 /// <param name="prevDir">Direction of previous lane</param>
 public virtual void Activate(int rowNumber, bool[] prevPassableTileArray, LaneDirection prevDir)
 {
     Reset();
     m_isActivated = true;
 }
Esempio n. 10
0
 public Lane(LaneType type, LaneDirection direction, float width)
 {
     Type      = type;
     Direction = direction;
     Width     = width;
 }
 /// <summary>
 /// Activate this lane
 /// </summary>
 /// <param name="rowNumber">Indacates how far into the map the lane is</param>
 /// <param name="prevPassableTileArray">Passable tile array of the previous lane</param>
 /// <param name="prevDir">Direction of previous lane</param>
 public override void Activate(int rowNumber, bool[] prevPassableTileArray, LaneDirection prevDir)
 {
     base.Activate(rowNumber, prevPassableTileArray, prevDir);
     PlayRiverSound();
     CreatePlatforms(prevPassableTileArray, prevDir);
 }
Esempio n. 12
0
 public int GetLaneCount(LaneDirection lanedirection)
 {
     return lanelist.Count(lane => lane.LaneDirection == lanedirection);
 }
 /// <summary>
 /// Sets the previous lane direction
 /// </summary>
 public void SetPrevLaneDirection(LaneDirection prevDir)
 {
     m_prevDir = prevDir;
 }
    /// <summary>
    /// Start spawning logs
    /// </summary>
    private void StartLogSpawning(bool[] prevPassableTileArray, LaneDirection prevDir)
    {
        // Set a random spawn time
        m_spawnTime  = Random.Range(m_minSpawnTime, m_maxSpawnTime);
        m_spawnTimer = Random.Range(0f, m_spawnTime);

        // Determine log direction
        switch (prevDir)
        {
        case LaneDirection.NONE:
            // Random direction
            m_direction = (Random.Range(0, 2) == 1) ? LaneDirection.RIGHT : LaneDirection.LEFT;
            break;

        case LaneDirection.LEFT:
        case LaneDirection.RIGHT:
            if (Random.value <= m_oppositeDirProb)
            {
                m_direction = (prevDir == LaneDirection.LEFT) ? LaneDirection.RIGHT : LaneDirection.LEFT;
            }
            else
            {
                m_direction = prevDir;
            }
            break;
        }

        // Update passable tiles
        if (m_direction == LaneDirection.RIGHT)
        {
            // Rightward
            m_isActiveTilePassable[0] = false;
            for (int i = 1; i < m_activeTileCount; ++i)
            {
                m_isActiveTilePassable[i] = m_isActiveTilePassable[i - 1] || prevPassableTileArray[i];
            }
        }
        else
        {
            // Leftward
            m_isActiveTilePassable[m_activeTileCount - 1] = false;
            for (int i = m_activeTileCount - 2; i <= 0; --i)
            {
                m_isActiveTilePassable[i] = m_isActiveTilePassable[i + 1] || prevPassableTileArray[i];
            }
        }

        // Determine log speed
        m_logSpeed = Random.Range(m_minSpeed, m_maxSpeed);

        // Ready the log list
        if (m_logs != null)
        {
            m_logs.Clear();
        }
        else
        {
            m_logs = new List <Log>();
        }

        // Determine log movement positions
        // Left
        int tileCountToEdge = Mathf.FloorToInt(m_activeTileCount * 0.5f) + 1;

        m_activeLeftPos = new Vector3(tileCountToEdge * -m_tileSize, m_height, transform.position.z);
        m_edgeLeftPos   = new Vector3(m_activeLeftPos.x + (m_edgeTileCount * -m_tileSize),
                                      m_height, transform.position.z);
        // Right
        tileCountToEdge = Mathf.FloorToInt(m_activeTileCount * 0.5f);
        if (m_activeTileCount % 2 != 0)
        {
            tileCountToEdge++;
        }
        m_activeRightPos = new Vector3(tileCountToEdge * m_tileSize, m_height, transform.position.z);
        m_edgeRightPos   = new Vector3(m_activeRightPos.x + (m_edgeTileCount * m_tileSize),
                                       m_height, transform.position.z);

        // Create logs to fill the initial space
        float   randomXPos = Random.Range(m_activeLeftPos.x + m_tileSize * 3f, 0f);
        Vector3 startPos   = new Vector3(randomXPos, m_height, transform.position.z);

        CreateLog(true, startPos);
        randomXPos = Random.Range(m_tileSize * 3f, m_activeRightPos.x);
        startPos   = new Vector3(randomXPos, m_height, transform.position.z);
        CreateLog(true, startPos);
    }
    /// <summary>
    /// Spawns lily pads
    /// </summary>
    private void SpawnLilyPads(bool[] prevPassableTileArray, LaneDirection prevDir)
    {
        m_direction = LaneDirection.NONE;

        // Check the list of passable tiles and choose a path where you can pass
        // Choose the center tile by default
        int mainPassableTile = Mathf.FloorToInt(m_activeTileCount * 0.5f);

        if (prevPassableTileArray != null)
        {
            List <int> passableTiles = new List <int>(prevPassableTileArray.Length);
            for (int i = 0; i < prevPassableTileArray.Length; ++i)
            {
                if (prevPassableTileArray[i])
                {
                    passableTiles.Add(i);
                }
            }
            for (int i = 6; i >= 0; --i)
            {
                if (passableTiles.Count > i)
                {
                    // Avoid the edge columns if possible
                    int j = i / 2;
                    mainPassableTile = passableTiles[Random.Range(j, passableTiles.Count - j)];
                    break;
                }
            }
        }

        // Create the lily pad array
        m_lilyPads = new Platform[m_maxLilyPadCount];

        // Spawn the lily pads
        int     lilyPadCount     = 0;
        float   leftmostXPos     = Mathf.FloorToInt(m_activeTileCount * 0.5f) * -m_tileSize;
        Vector3 leftmostPosition = new Vector3(leftmostXPos, m_height, 0f) + transform.position;

        // TODO: Make spawning logic better
        for (int i = 0; i < m_activeTileCount; ++i)
        {
            bool spawnFlag = false;

            // Determine whether to spawn
            if (i == mainPassableTile)
            {
                spawnFlag = true;
            }
            else
            {
                float prob = Random.value;
                if (prevPassableTileArray[i])
                {
                    if (prob <= m_lilyPadProbOpen && lilyPadCount < m_maxLilyPadCount - 1)
                    {
                        spawnFlag = true;
                    }
                }
                else
                {
                    if (prob <= m_lilyPadProbClosed && lilyPadCount < m_maxLilyPadCount - 1)
                    {
                        spawnFlag = true;
                    }
                }
            }

            if (spawnFlag)
            {
                // Spawn a lily pad and position it correctly
                m_lilyPads[lilyPadCount] = m_mapAssetPool.GetPlatformAssetPool(MapItemType.LilyPad).GetAsset();
                m_lilyPads[lilyPadCount].transform.position = leftmostPosition + (Vector3.right * i * m_tileSize);
                m_lilyPads[lilyPadCount].gameObject.SetActive(true);
                m_lilyPads[lilyPadCount].Activate();
                // Temporarily indicate where lily pads are
                m_isActiveTilePassable[i] = true;
                // Spawn a coin
                SpawnCoin(m_lilyPads[lilyPadCount]);
                lilyPadCount++;
            }
            else
            {
                // If no lily pad spawned, tile is not passable
                m_isActiveTilePassable[i] = false;
            }
        }

        // Evaluate passable tiles branching from the main tile
        m_isActiveTilePassable[mainPassableTile] = true;
        // Leftward
        for (int i = mainPassableTile - 1; i >= 0; --i)
        {
            m_isActiveTilePassable[i] = m_isActiveTilePassable[i] &&
                                        (m_isActiveTilePassable[i + 1] || prevPassableTileArray[i]);
        }
        // Rightward
        for (int i = mainPassableTile + 1; i < m_activeTileCount; ++i)
        {
            m_isActiveTilePassable[i] = m_isActiveTilePassable[i] &&
                                        (m_isActiveTilePassable[i - 1] || prevPassableTileArray[i]);
        }
    }
Esempio n. 16
0
 /// <summary>
 /// Activate this lane
 /// </summary>
 /// <param name="rowNumber">Indacates how far into the map the lane is</param>
 /// <param name="prevPassableTileArray">Passable tile array of the previous lane</param>
 /// <param name="prevDir">Direction of previous lane</param>
 public override void Activate(int rowNumber, bool[] prevPassableTileArray, LaneDirection prevDir)
 {
     base.Activate(rowNumber, prevPassableTileArray, prevDir);
     CreateVehicles(prevDir);
     SpawnCoin();
 }
Esempio n. 17
0
 public TrafficLane(SDL.SDL_Point origin, SDL.SDL_Point endPoint, LaneDirection direction)
 {
     Origin = origin;
     EndPoint = endPoint;
     Direction = direction;
 }
Esempio n. 18
0
        private void addlane(LaneDirection lanedirection, LaneType lanetype)
        {
            List<RoadLane> sublanelist = lanelist.Where(l => l.LaneDirection == lanedirection).ToList();
            sublanelist.Sort((l1, l2) => l1.LaneIndex.CompareTo(l2.LaneIndex));

            double translation = sublanelist.Sum(l => l.Width);
            translation += roaddata.LaneWidth/2;

            var lane = new RoadLane(this, lanedirection, lanetype, lanelist.Count(l => l.LaneDirection == lanedirection),
                                    roaddata.LaneWidth, translation);

            if (sublanelist.Count > 0 && lane.LaneType != LaneType.Shoulder)
            {
                lane.LeftLane = sublanelist[sublanelist.Count - 1];
                sublanelist[sublanelist.Count - 1].RightLane = lane;
            }

            lanelist.Add(lane);
        }