public void AddWorldObjectsToChunk(int seed, ChunkScript chunk) { List <ChestScript> chunkChests = new List <ChestScript>(); int numToSpawn = Random.Range(MinObjPerChunk, MaxObjPerChunk); if (c_Pool.Count < numToSpawn) { numToSpawn = c_Pool.Count; } for (int i = 0; i < numToSpawn; i++) { if (c_Pool.Count < 1) { return; } GameObject tile = chunk.GetRandomTile(); ChestScript chest = c_Pool[0]; chest.Init(tile.transform.position); chunkChests.Add(chest); c_Pool.Remove(chest); } c_Active.Add(seed, chunkChests); }
void Awake() { random = new System.Random(); chunkScript = GetComponentInParent <ChunkScript>(); chunkScript.OnMapNodeGiven += mapNode => Make(mapNode.frame); gizmosColor = gizmosColors[chunkIndex++ % gizmosColors.Count]; }
public ChunkScript ActivateRandomChunk(Vector2 playerPos, int seed) { ChunkScript cs = c_Pool[Random.Range(0, c_Pool.Count)]; cs.Use(playerPos); c_Pool.Remove(cs); c_Active.Add(seed, cs); return(cs); }
void Awake() { grid = GetComponentInChildren <Grid>(); groundTile = groundTileOptions[groundTileIndex++ % groundTileOptions.Length]; chunkScript = GetComponentInParent <ChunkScript>(); chunkScript.OnChartSet += Make; }
public void LoadChunk() // Loads new Chunk. Used in ChunkScript { previousChunk = currentChunk; // Makes currentChunk the previousChunk currentChunk = LoadedChunk; // Makes LoadedChunk the currentChunk BoxCollider2D prevCollider = currentChunk.GetComponent <BoxCollider2D>(); prevCollider.enabled = false; // Disables previous chunk spawn collider int i = Random.Range(0, chunks.Length); // gives i random value if (chunks.Length > 1) { while (i == lastNumber) // if i is same as last chunk number then re roll { i = Random.Range(0, chunks.Length); } } else if (chunks.Length == 1) { i = Random.Range(0, chunks.Length); } lastNumber = i; distanceFromStart = distanceFromStart - chunkSize; // changes distance from spawn depending on size of chunk newPos = new Vector3(0f, (float)distanceFromStart, 0f); // sets spawn point of next chunk to distanceFromStart chunkToLoad = chunks[i]; // makes chunkToLoad a random chunk based on i if (chunkNumber < stageAmount) { LoadedChunk = Instantiate(chunkToLoad, transform.position + newPos, Quaternion.identity, chunkParent.transform); } // creates new chunk and assigns it to LoadedChunk if (chunkNumber == stageAmount) { Instantiate(bossChunk, transform.position + newPos, Quaternion.identity, chunkParent.transform); } chunkNumber++; statsheet.stage = chunkNumber; print("ChunkNumber: " + chunkNumber); chunkScript = LoadedChunk.GetComponent <ChunkScript>(); print("loaded " + chunkToLoad.name); print("chunknumber " + chunkNumber); }
void SpawnChunk(GameObject chunk) { ChunkScript script = chunk.GetComponent <ChunkScript> (); chunk.transform.position = currentPosition - script.StartPoint.transform.localPosition; chunk.transform.rotation = Quaternion.Euler(currentRotation); currentPosition = script.EndPoint.transform.position; currentRotation += script.EndPoint.transform.localRotation.eulerAngles; ArrangeChunkList(chunk); }
public void DeactivateChunk(int seed) { if (!c_Active.ContainsKey(seed)) { return; } ChunkScript cs = c_Active[seed]; c_Pool.Add(cs); cs.Hide(); c_Active.Remove(seed); }
void AddChunk(MapNode mapNode) { GameObject chunkPrefab = mapMaker.NodeToFrameMaker[mapNode].transform.root.gameObject; GameObject chunk = Instantiate(chunkPrefab, transform); chunk.name = "Chunk " + chunkIndex++; ChunkScript chunkScript = chunk.GetComponent <ChunkScript>(); chunkScript.mapNode = mapNode; chunkScripts.Add(chunkScript); }
private void SpawnChunk() { ChunkScript newChunk = Instantiate(ChunksPrefs[Random.Range(0, ChunksPrefs.Length)]); newChunk.transform.position = spawnedChunks[spawnedChunks.Count - 1].endPoint.position - newChunk.startPoint.localPosition; spawnedChunks.Add(newChunk); if (spawnedChunks.Count >= despawnCount) { Destroy(spawnedChunks[0].gameObject.gameObject); spawnedChunks.RemoveAt(0); } }
public void Init(Sprite[] t_Sprites, Sprite[] w_Sprites, int c_Number, float c_Width, float c_Height) { for (int i = 0; i < c_Number; i++) { GameObject obj = Instantiate(chunk); obj.transform.parent = gameObject.transform; ChunkScript cs = obj.GetComponent <ChunkScript>(); cs.InitWalledTerrain(t_Sprites, w_Sprites, c_Width, c_Height); cs.Hide(); s_size = cs.GetSpriteSize(); c_Pool.Add(cs); } }
/// <summary> /// Defines what the new target position is /// </summary> /// <param name="e">E.</param> public void PlayerProgression(ChunkEnteredEvent e) { if (numberOfPreviousChunks == -1) { EventManager.Instance.TriggerEvent(new PlayerHitsTheFirstRoadChunk()); gameStarted = true; ProgBar.SetActive(true); } ChunkScript script = e.chunk.GetComponent <ChunkScript>(); startPoint = script.StartPoint.transform.position; endPoint = script.EndPoint.transform.position; chunkLength = Vector3.Distance(startPoint, endPoint); numberOfPreviousChunks++; }
public void CheckForNewSeeds(List <Vector2> playerNodes) { foreach (Vector2 v2 in playerNodes) { Vector2 roundedPos = new Vector2(RoundOff(v2.x, c_Width * s_size), RoundOff(v2.y, c_Height * s_size)); int seed = GetSeed(roundedPos); if (seed != -1) { ActiveSeeds.Add(seed, roundedPos); //New seed found Do all loading factory call here ChunkScript chunk = t_Factory.ActivateRandomChunk(roundedPos, seed); w_Factory.AddWorldObjectsToChunk(seed, chunk); } } }
void SpreadLoadAndUnload(int depth, int loadToDepth, Vector3 position, Loader loadOrigin) { if (depth <= loadToDepth) { TryLoad(position, loadOrigin); } else { TryUnload(loadOrigin); return; } foreach (KeyValuePair <Edge, MapNode> item in chunkScript.mapNode.Neighbors) { ChunkScript neighborChunkScript = item.Value.chunkScript; Loader neighborLoader = neighborChunkScript.GetComponentInChildren <Loader>(); Vector3 deltaPos = chunkScript.mapNode.frame.CenterToEntry(item.Key) - neighborChunkScript.mapNode.frame.CenterToEntry(item.Key.Opposite()); neighborLoader.SpreadLoadAndUnload(depth + 1, loadToDepth, position + deltaPos, loadOrigin); } }
//====================================================== // //====================================================== // Use this for initialization void Start() { _chunkPrefabs.AddRange(GameManagerScript.Instance.EnvironmentChunks); _chunkPrefabs.AddRange(GameManagerScript.Instance.EnvironmentChunks); _chunks.Add(_startChunk.GetComponent <ChunkScript>()); if (GameManagerScript.Instance.UseBackgroundSprite) { GameObject newBackground = Instantiate <GameObject>(_backgroundPrefab, this.transform); ChunkScript bgScript = newBackground.GetComponent <ChunkScript>(); _backgrounds.Add(bgScript); } //********************************** _chunkSpawnXPositions.Add(0); float possibleChunkXPos = _chunkSpawnOffsetInterval; while (possibleChunkXPos <= _maxChunkSpawnOffset) { _chunkSpawnXPositions.Add(possibleChunkXPos); possibleChunkXPos += _chunkSpawnOffsetInterval; } possibleChunkXPos = -_chunkSpawnOffsetInterval; while (possibleChunkXPos >= -_maxChunkSpawnOffset) { _chunkSpawnXPositions.Add(possibleChunkXPos); possibleChunkXPos -= _chunkSpawnOffsetInterval; } if (GameManagerScript.Instance.SpawnRocks) { Invoke("SpawnRock", Random.Range(GameManagerScript.Instance.MinRockSpawnTimer, GameManagerScript.Instance.MaxRockSpawnTimer)); } }
//public List<Swapper> neighborSwappers; void Awake() { chunkScript = GetComponentInParent <ChunkScript>(); chunkScript.OnMapNodeGiven += mapNode => Make(mapNode.frame); }
protected virtual void Awake() { chunkScript = GetComponentInParent <ChunkScript>(); chunkScript.OnChartSet += Make; InitRandom(chunkScript.ChunkRandom); }
//====================================================== // //====================================================== // Update is called once per frame void Update() { //********************************************** // chunk spawning Camera camera = Camera.main; float cameraUpperYPos = camera.transform.position.y + camera.orthographicSize; float chunksUpperYPos = _chunks[_chunks.Count - 1].TopPosition.y; if (cameraUpperYPos + 1 >= chunksUpperYPos) { int randomIndex = Random.Range(0, _chunkPrefabs.Count - 1); GameObject newChunk = Instantiate <GameObject>(_chunkPrefabs[randomIndex], this.transform); ChunkScript newChunkScript = newChunk.GetComponent <ChunkScript>(); float newChunkHalfHeight = Mathf.Abs(newChunkScript.BottomPosition.y - newChunkScript.transform.position.y); float newChunkXPos = _chunkSpawnXPositions[Random.Range(0, _chunkSpawnXPositions.Count - 1)]; newChunk.transform.position = new Vector3(newChunkXPos, chunksUpperYPos + newChunkHalfHeight); _chunks.Add(newChunkScript); } //********************************************** // bg spawning float bgsUpperYPos = _backgrounds[_backgrounds.Count - 1].TopPosition.y; if (cameraUpperYPos + 1 >= bgsUpperYPos) { GameObject newBackground = Instantiate <GameObject>(_backgroundPrefab, this.transform); ChunkScript bgScript = newBackground.GetComponent <ChunkScript>(); float newBackgroundHalfHeight = Mathf.Abs(bgScript.BottomPosition.y - bgScript.transform.position.y); newBackground.transform.position = new Vector3(0, bgsUpperYPos + newBackgroundHalfHeight); _backgrounds.Add(bgScript); } //********************************************** // chunk despawning ChunkScript oldestChunk = _chunks[0]; float cameraBottomYPos = camera.transform.position.y - camera.orthographicSize; float oldestChunkTopYPos = oldestChunk.TopPosition.y; if (cameraBottomYPos > oldestChunkTopYPos) { _chunks.Remove(oldestChunk); Destroy(oldestChunk.gameObject); } //********************************************** // bg despawning ChunkScript oldestBg = _backgrounds[0]; float oldestBgTopYPos = oldestBg.TopPosition.y; if (cameraBottomYPos > oldestBgTopYPos) { _backgrounds.Remove(oldestBg); Destroy(oldestBg.gameObject); } }
//private int depth = int.MaxValue; //private int maxDepth = 1; //private static float loadTimeDelay = 1; void Awake() { swapper = GetComponent <Swapper>(); swapper.OnSwapped += CheckForLoad; chunkScript = GetComponentInParent <ChunkScript>(); }
void Awake() { edgeColliders = new List <EdgeCollider2D>(); chunkScript = GetComponentInParent <ChunkScript>(); chunkScript.OnMapNodeGiven += mapNode => Make(mapNode.frame); }