Beispiel #1
0
    private void Update()
    {
        if (!gotColor)
        {
            //playerColor = this.gameObject.GetComponent<PlayerManager>().GetPlayerColor();
            int colorInt = this.GetComponent <PlayerManager>().GetPlayerColorInt();
            playerColor = (ColoredEntity.EColor)colorInt;
            gotColor    = true;
        }

        if (isLocalPlayer)
        {
            if (Input.GetMouseButtonDown(0))
            {
                Shoot();
                //canShoot = false;
            }
            //// if cannot shoot, increment counter
            //if (!canShoot)
            //{
            //    ++shootCounter;
            //}
            //if (shootCounter >= shootCounterMax)
            //{
            //    canShoot = true;
            //    shootCounter = 0;
            //}
        }
    }
    public void spawnRandomAstroid()
    {
        ColoredEntity.EColor newColor = (ColoredEntity.EColor)Random.Range(1, numPlayers + 1);

        if (Random.Range(0f, 1f) <= graySpawnThresh)
        {
            newColor = ColoredEntity.EColor.Gray;
        }

        Vector3 lastSpawn = Vector3.zero;


        //debug for testing
        //newColor = ColoredEntity.EColor.Red;

        switch (newColor)
        {
        case ColoredEntity.EColor.Red:
            lastSpawn = lastRedSpawnCoord;
            break;

        case ColoredEntity.EColor.Blue:
            lastSpawn = lastBlueSpawnCoord;
            break;

        case ColoredEntity.EColor.Green:
            lastSpawn = lastGreenSpawnCoord;
            break;

        case ColoredEntity.EColor.Yellow:
            lastSpawn = lastYellowSpawnCoord;
            break;

        case ColoredEntity.EColor.Gray:
            lastSpawn = new Vector3(0, heightOfPlaySpace, 0);
            break;
        }

        //Spawn an astroid at the top of the playspace and somewhere between the horizontal boundries
        float      leftSpawnLine  = Mathf.Max(-widthOfPlaySpace / 2, lastSpawn.x - widthOfPlaySpace / 2);
        float      rightSpawnLine = Mathf.Min(widthOfPlaySpace / 2, lastSpawn.x + widthOfPlaySpace / 2);
        GameObject newAstroid     = Instantiate(astroidPrefab, new Vector3(Random.Range(leftSpawnLine, rightSpawnLine), heightOfPlaySpace, 0), Quaternion.identity);

        newAstroid.GetComponent <Astroid>().ReColor(newColor);
        newAstroid.GetComponent <Rigidbody>().velocity = GenerateRandomDirectionToGround(newAstroid.transform.position) * astroidTravelSPeed;

        lastSpawn = newAstroid.transform.position;

        sumSpawn += lastSpawn;
        ++numberOfSpawns;
        if (numberOfSpawns > dificultySpikeThresh)
        {
            minTImeBetweenSpawns *= .9f;
            maxTimeBetweenSpawns *= .9f;
            dificultySpikeThresh += 2;
            numberOfSpawns        = 0;
        }
        //Debug.Log("Avg: " + sumSpawn / numberOfSpawns);

        switch (newColor)
        {
        case ColoredEntity.EColor.Red:
            lastRedSpawnCoord = lastSpawn;
            break;

        case ColoredEntity.EColor.Blue:
            lastBlueSpawnCoord = lastSpawn;
            break;

        case ColoredEntity.EColor.Green:
            lastGreenSpawnCoord = lastSpawn;
            break;

        case ColoredEntity.EColor.Yellow:
            lastYellowSpawnCoord = lastSpawn;
            break;

        case ColoredEntity.EColor.Gray:
            newAstroid.transform.localScale = new Vector3(3, 3, 3);
            newAstroid.GetComponent <DamagableEntity>().health = 3;
            newAstroid.GetComponent <Astroid>().damage         = 15;
            lastSpawn = new Vector3(0, heightOfPlaySpace, 0);
            break;
        }


        currentTimeBetweenSpawns = Random.Range(minTImeBetweenSpawns, maxTimeBetweenSpawns);
        timeSinceLastSpawn       = 0;
    }