Esempio n. 1
0
    /// <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);
        }
    }
Esempio n. 3
0
    // Start is called before the first frame update
    void Start()
    {
        obstacleStats = obstacle.GetComponent <ObstacleStats>();

        if (prevObstacle != null)
        {
            prevLevelObstStats = prevObstacle.GetComponent <ObstacleStats>();
        }
    }
Esempio n. 4
0
    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;
    }
Esempio n. 5
0
    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);
    }
Esempio n. 6
0
    /// <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);
        }
    }
Esempio n. 7
0
    // Start is called before the first frame update
    void Start()
    {
        obstacleStats = obstacleSet.GetComponent <ObstacleStats>();

        ChangeObstacleValueText();
    }
Esempio n. 8
0
 // Start is called before the first frame update
 void Start()
 {
     obstacleStats = obstacleSet.GetComponent <ObstacleStats>();
 }
Esempio n. 9
0
    /// <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);
        }
    }
Esempio n. 10
0
 // Start is called before the first frame update
 void Start()
 {
     obstacleStats = obstacleSet.GetComponent <ObstacleStats>();
     rt            = GetComponent <RectTransform>();
 }
Esempio n. 11
0
 public void SetObstacle(ObstacleStats obstacle) => this.obstacle = obstacle;
Esempio n. 12
0
 // Start is called before the first frame update
 void Start()
 {
     obstacleStats  = level.GetComponent <ObstacleStats>();
     destroyerIndex = StringHelper.GetObjectNum(this.name) - 1;
 }