Esempio n. 1
0
    private void Awake()
    {
        _waypoints = new List <Waypoint>();
        GetRailGridFromFile(testLevel);
        print(_waypoints.Count);
        SpawnPoint = _waypoints[0];
        TrainSpawner trainSpawner = spawnTrack.GetComponent <TrainSpawner>();

        trainSpawner.Spawnpoints[0].AdjecentWaypoints[0] = spawnWaypoint;
    }
Esempio n. 2
0
	// Use this for initialization
	void Start () {
		if(ts == null)
			ts = GetComponentInParent<TrainSpawner>();
		isFromRight= ts.isFromRight;
		destination = ts.trainSpawnPosition;
		if(isFromRight){
			speed = -ts.speed;
			destination.x -= ts.trainWidth - BoardManager.instance.boardWidth; 
		}
		else{
			destination.x += ts.trainWidth + BoardManager.instance.boardWidth; 
			speed = ts.speed;
		}
	}
Esempio n. 3
0
    void Start()
    {
        MainTrain           = (TrainEngineMainPlayer)GameObject.FindGameObjectWithTag("MainPlayer").GetComponent(typeof(TrainEngineMainPlayer));
        MainTrain.gameState = gameState;

        GameObject[] enemyTrains = GameObject.FindGameObjectsWithTag("EnemyPlayer");
        trainsSpawned += enemyTrains.Length;
        foreach (GameObject enemys in enemyTrains)
        {
            TrainEngineEnemy enemy = (TrainEngineEnemy)enemys.GetComponent(typeof(TrainEngineEnemy));
            enemy.gameState = gameState;
        }

        GameObject[] TrainCars = GameObject.FindGameObjectsWithTag("TrainCar");
        foreach (GameObject trainCar in TrainCars)
        {
            TrainCarController trainC = (TrainCarController)trainCar.GetComponent(typeof(TrainCarController));
            trainC.gameState = gameState;
        }

        GameObject[] TrainSpawners = GameObject.FindGameObjectsWithTag("TrainSpawner");
        foreach (GameObject TrainSpawner in TrainSpawners)
        {
            TrainSpawner spawner = (TrainSpawner)TrainSpawner.GetComponent(typeof(TrainSpawner));
            spawner.gameState = gameState;
        }

        GameObject[] CoalSpawners = GameObject.FindGameObjectsWithTag("CoalSpawner");
        foreach (GameObject CoalSpawner in CoalSpawners)
        {
            CoalSpawner spawner = (CoalSpawner)CoalSpawner.GetComponent(typeof(CoalSpawner));
            spawner.gameState = gameState;
        }

        PlayerPrefs.SetInt("Level", Application.loadedLevel - 2);
        timeOfLastTrainSpawn = 0;

        scoreText.text = "score: " + PlayerPrefs.GetInt("Score", 0);
        switch (gameState)
        {
        case 0:
            //scoreText.text = "trains to Destroy: " + PlayerPrefs.GetInt("Score", 0) + "/" + (totalTrainsSpawned);
            break;

        case 1:

            break;

        case 2:

            break;

        case 3:
            totalTrainsSpawned = 30 - PlayerPrefs.GetInt(Zone + "0", 0);
            scoreText.text     = "trains to Destroy: " + PlayerPrefs.GetInt("Score", 0) + "/" + (totalTrainsSpawned);
            MainTrain.coal     = (PlayerPrefs.GetInt(Zone + "1", 0));
            int CarsCollected = PlayerPrefs.GetInt(Zone + "2", 0);
            PlayerPrefs.SetString("zone", Zone);
            break;
        }

        Time.timeScale = 0;             //pause game

        PlayerPrefs.SetInt("Score", 0); //set score for the game to zero (reset it)

        //load sound bank
        uint bankID;

        AkSoundEngine.LoadBank("Trainwrex.bnk", AkSoundEngine.AK_DEFAULT_POOL_ID, out bankID);
        AkSoundEngine.PostEvent("Gameplay_Train_Loop_Stop", MainTrain.gameObject);
    }
Esempio n. 4
0
	void SpawnBoardPerType(){
		if(rowBoardPooling.Count < longPerBoard){
			if(boardState == BoardState.DONE){
				//Random whats next? Grass/Road/River
				RandomNextBoardType();

				lastSpeedLog = 0;
			}
			Transform rowInstance = new GameObject("Row " + yPos.ToString()).transform;
			rowInstance.position = new Vector3(0, 0, yPos);
			rowInstance.SetParent(boardParent);

			if(boardState == BoardState.GRASS){
				if(rows <= 0){
					rows = UnityEngine.Random.Range(minLongGrass, maxLongGrass + 1);
					xSafeLand = UnityEngine.Random.Range(xMinEffectiveBoard, xMaxEffectiveBoard+1);
				}
				RandomTree();
				
				int xPos = xMinBoard;
				while(xPos < xMaxBoard){
					//GetFromPool

					//Spawning
					SpawnGrass(xPos, rowInstance);
					xPos++;
				}
#if SOFT_PROCESS
				SpawnOrMoveObject(rowInstance, grassPacked);
#endif
			}
			else if(boardState == BoardState.ROAD){
				if(rows <= 0){
					rows = UnityEngine.Random.Range(minLongRoad, maxLongRoad + 1);
					if(rows == 1)
						roadType = RoadType.SINGLE;
					else{
						roadType = RoadType.TOP;
					}
				}
#if SOFT_PROCESS
				if(roadType == RoadType.SINGLE){
					SpawnOrMoveObject(rowInstance, roadPacked);
				}
				else if(roadType == RoadType.TOP){
					SpawnOrMoveObject(rowInstance, roadTopLinePacked);

				}
				else if(roadType == RoadType.MIDDLE)
				{
					SpawnOrMoveObject(rowInstance, roadBothLinePacked);

				}	
				else if(roadType == RoadType.BOTTOM)
				{
					SpawnOrMoveObject(rowInstance, roadBottomLinePacked);

				}	
#else
				int xPos = xMinBoard;
				while(xPos < xMaxBoard){
					SpawnRoad(xPos, rowInstance);
					xPos++;
				}
#endif
				CarSpawner cs = rowInstance.gameObject.AddComponent<CarSpawner>();
				cs.speedCar = UnityEngine.Random.Range(minSpeedCar, maxSpeedCar);
				cs.minSpawnCarTime = minSpawnCarTime;
				cs.maxSpawnCarTime = maxSpawnCarTime;
				cs.car = car[UnityEngine.Random.Range(0, car.Length)];

				if(rows == 2)
					roadType = RoadType.BOTTOM;
				else if(roadType == RoadType.TOP)
					roadType = RoadType.MIDDLE;
			}
			else if(boardState == BoardState.RIVER){
				if(rows <= 0)
					rows = UnityEngine.Random.Range(minLongRiver, maxLongRiver + 1);
#if !SOFT_PROCESS
				int xPos = xMinBoard;
				while(xPos < xMaxBoard){
					SpawnRiver(xPos, rowInstance);
					xPos++;
				}
#elif SOFT_PROCESS
				SpawnOrMoveObject(rowInstance, riverPacked);
#endif
				LogSpawner ls = rowInstance.gameObject.AddComponent<LogSpawner>();
				//do{
				ls.speed = UnityEngine.Random.Range(minSpeedLog, maxSpeedLog);
				//}while(ls.speed - speedLogBalancer <= lastSpeedLog && ls.speed + speedLogBalancer >= lastSpeedLog);
				if(ls.speed <= lastSpeedLog + speedLogBalancer/2 && ls.speed >= lastSpeedLog){
					if(ls.speed - speedLogBalancer <= .8f){
						ls.speed += speedLogBalancer*1.5f;
					}
					else
						ls.speed -= speedLogBalancer;
				}
				else if(ls.speed >= lastSpeedLog - speedLogBalancer/2 && ls.speed <= lastSpeedLog){
					ls.speed += speedLogBalancer;
				}
				ls.minSpawnTime = minLogSpawnTime;
				ls.maxSpawnTime = maxLogSpawnTime;
				ls.log = log[UnityEngine.Random.Range(0, log.Length)];
				lastSpeedLog = ls.speed;
			}
			else if(boardState == BoardState.RAIL){
				if(rows <= 0){
					rows = UnityEngine.Random.Range(minLongRail, maxLongRail + 1);
					xLampPos = UnityEngine.Random.Range(xMinEffectiveBoard + 1, xMaxEffectiveBoard);
				}

#if !SOFT_PROCESS
				int xPos = xMinBoard;
				while(xPos < xMaxBoard){
					SpawnRail(xPos, rowInstance);
					xPos++;
				}
#elif SOFT_PROCESS
				SpawnOrMoveObject(rowInstance, railPacked);
				SpawnRail(xLampPos, rowInstance);
#endif
				TrainSpawner ts = rowInstance.gameObject.AddComponent<TrainSpawner>();
				ts.speed = trainSpeed;
				ts.spawnTrainTime = UnityEngine.Random.Range(minTrainSpawnTime, maxTrainSpawnTime);
				ts.warningTime = trainWarningTime;
				ts.light = rowInstance.GetComponentInChildren<Light>();
			}

			rows--;
			
			if(rows <= 0){
				boardState = BoardState.DONE;
			}

			treeCounter=0;
			xPosTree.Clear();

			rowBoardPooling.Add(rowInstance.gameObject);

			yPos+=1;
		}
	}
Esempio n. 5
0
 private void Start()
 {
     trainSpawner = FindObjectOfType <TrainSpawner>();
 }