/// <summary> /// Spawns a particular obstacle with the specified parameters /// </summary> /// <param name="index">The Obstacles index of the object to be spawned</param> /// <param name="position">The position at which to spawn the obstacle</param> /// <param name="moving">Whether the object should move</param> /// <param name="rotation">The amount to rotate the object</param> protected void SpawnObstacle(int index, Vector3 position, bool moving, Quaternion rotation = new Quaternion()) { // Spawn the specified obstacle at the specified position and rotation GameObject newObstacle = Instantiate(this.ObstaclePrefabs[index], position, rotation); // Set the obstacle's public properties based on its stats in obstacleStats ObstacleStats stats = obstacleStats[index]; Environment newObst = newObstacle.GetComponent <Environment>(); newObst.EnvironmentType = EnvironmentType.Obstacle; // Make the object move first based on forceMove (if not null) and otherwise based on a random probability if (moving) { newObst.Movement = stats.Movement; newObst.Speed = stats.Speed.GetValue(this.DifficultyMultiplier); } // If the obstacle blocks its Y position, add its top and bottom to curYBlocks if (stats.YBlock > 0) { this.curYBlocks.Add(new Vector2(position.x + stats.YBlock + playerSpace * 2, position.y + stats.YOffset)); this.curYBlocks.Add(new Vector2(position.x + stats.YBlock + playerSpace * 2, position.y - stats.YOffset)); } }
void FixedUpdate() { hitObstacle = Physics2D.OverlapCircle(transform.position, 0.1f, obstacleMask); if (hitObstacle) { ObstacleStats hitObjectStats = Physics2D.OverlapCircle(transform.position, 0.1f, obstacleMask).GetComponent <ObstacleStats>(); manager.money += hitObjectStats.moneyToAdd; if (hitObjectStats.velocityToAdd > 0) { audioSource.PlayOneShot(audioClips[0], 0.1f); playerRB.AddForce(new Vector2(0, hitObjectStats.velocityToAdd * speedUp), ForceMode2D.Impulse); } if (hitObjectStats.velocityToAdd < 0) { audioSource.PlayOneShot(audioClips[1], 0.1f); playerRB.AddForce(new Vector2(0, hitObjectStats.velocityToAdd - hitObjectStats.velocityToAdd * slowDown), ForceMode2D.Impulse); } spawner.obstaclesCount -= 1; Destroy(Physics2D.OverlapCircle(transform.position, 0.1f, obstacleMask).gameObject); } }
// Start is called before the first frame update void Start() { obstacleStats = obstacle.GetComponent <ObstacleStats>(); if (prevObstacle != null) { prevLevelObstStats = prevObstacle.GetComponent <ObstacleStats>(); } }
private void PlaceObstacle(int id) { int indexRoad = Random.Range(0, Roads.transform.childCount); ObstacleStats obs = obstacles[id]; GameObject obj = new GameObject(); //obj = obs.mesh; obj.AddComponent <MeshFilter>(); obj.AddComponent <MeshRenderer>(); obj.AddComponent <Obstacle>(); obj.GetComponent <Obstacle>().Init(obs.name, obs.mesh, obs.type, obs.attacks, obs.attackDamage, obs.collisionDamage, obs.healthPoints, obs.armorPoints); obj.name = obs.name; obj.transform.position = Roads.transform.GetChild(indexRoad).transform.position; }
public double GetAllDestroyerValue() { double value = 0; foreach (var level in levelsList) { ObstacleStats levelStats = level.GetComponent <ObstacleStats>(); if (levelStats.isUnlocked) { value += levelStats.obstacleValue / levelStats.obstacleDifficulty; } } return(value); }
/// <summary> /// Spawns an obstacle type at a given position including handling obstacles consisting of multiple objects /// </summary> /// <param name="index">The Obstacle index of the obstacle type to be spawned</param> /// <param name="position">The position at which to center the obstacle type</param> /// <param name="forceStatic">Forces obstacle to either move (true) or not move (false)</param> protected void SpawnObstaclePre(int index, Vector3 position, bool?forceMove = null) { ObstacleStats stats = obstacleStats[index]; bool moving = ((forceMove ?? true) && Random.value < stats.MovementProb.GetValue(this.DifficultyMultiplier)) || (forceMove ?? false); // For pipes, spawn two obstacles (top and bottom) and a pipe score in between if (index == Obstacles.Pipe.GetHashCode()) { float spacing = stats.YGap.GetValue(DifficultyMultiplier); this.SpawnObstacle(index, position + Vector3.down * spacing, moving); this.SpawnObstacle(index, position + Vector3.up * spacing, moving, Quaternion.Euler(0, 0, 180)); this.SpawnConsumable(Consumables.Pipe.GetHashCode(), position); } else { this.SpawnObstacle(index, position, moving); } }
// Start is called before the first frame update void Start() { obstacleStats = obstacleSet.GetComponent <ObstacleStats>(); ChangeObstacleValueText(); }
// Start is called before the first frame update void Start() { obstacleStats = obstacleSet.GetComponent <ObstacleStats>(); }
/// <summary> /// Spawns the next environment object at nextEnv /// </summary> private void SpawnNextEnv() { // Randomly choose if we should spawn a consumable object if (Random.value < consumableProb) { // Randomly choose a consumable to spawn from consumableSpawnProbs int index = this.consumableSpawnProbs[(int)(Random.value * this.consumableSpawnProbs.Count)]; this.SpawnConsumable(index, new Vector3(this.nextEnv.x, Random.Range(-envMaxY, envMaxY), this.nextEnv.z)); this.nextEnv.x += ConsumableStats.XDelay; } else { // Randomly choose an obstacle to spawn from obstacleSpawnProbs int index = this.obstacleSpawnProbs[(int)(Random.value * this.obstacleSpawnProbs.Count)]; ObstacleStats stats = obstacleStats[index]; // Calculate the minimum and maximum Y of the ideal path based on other obstacles blocking at this X position float minY = -envMaxY; float maxY = envMaxY; for (int i = 0; i < this.curYBlocks.Count; ++i) { // Remove a Y block if the ending X position has been passed if (this.nextEnv.x > this.curYBlocks[i].x) { this.curYBlocks.RemoveAt(i); i--; } else if (this.curYBlocks[i].y < this.nextEnv.y) { minY = Mathf.Max(minY, this.curYBlocks[i].y); } else { maxY = Mathf.Min(maxY, this.curYBlocks[i].y); } } minY += playerSpace; maxY -= playerSpace; // Use a Markov model to choose the next Y position of the ideal path this.nextEnv.y = Utilities.Markov(this.nextEnv.y, ySdev.GetValue(this.DifficultyMultiplier), minY, maxY); // Spawn the obstacle only if there is enough space to do so if (maxY - minY > stats.YOffset * 2) { // Calculate the offset of the current obstacle to leave room on the ideal path float yOffset = (Random.value > 0.5f) ? stats.YOffset : -stats.YOffset; if (yOffset < minY) { yOffset += 2 * stats.YOffset; } else if (yOffset > maxY) { yOffset -= 2 * stats.YOffset; } this.SpawnObstaclePre(index, this.nextEnv + Vector3.up * yOffset); } this.nextEnv.x += stats.XDelay.GetValue(this.DifficultyMultiplier); } }
// Start is called before the first frame update void Start() { obstacleStats = obstacleSet.GetComponent <ObstacleStats>(); rt = GetComponent <RectTransform>(); }
public void SetObstacle(ObstacleStats obstacle) => this.obstacle = obstacle;
// Start is called before the first frame update void Start() { obstacleStats = level.GetComponent <ObstacleStats>(); destroyerIndex = StringHelper.GetObjectNum(this.name) - 1; }