Inheritance: MonoBehaviour
Esempio n. 1
0
    public void baddieSpawn(GameRenderer gr)
    {
        int   to_spawn = day;
        float ang      = 0;
        int   range    = 10;
        int   x        = 0;
        int   y        = 0;

        while (range < 200)
        {
            x = (int)(player.location.x + (range * Mathf.Sin(ang * Mathf.Deg2Rad)));
            y = (int)(player.location.y + (range * Mathf.Cos(ang * Mathf.Deg2Rad)));

            if (!isOOB(new IntVec2(x, y)) && tiles_[x, y] == null)
            {
                Baddie b = new Swarmer(BALANCE_CONSTANTS.BADDIE_HP + (day * BALANCE_CONSTANTS.BADDIE_HP_GROWTH_DAY));
                b.anim = TileUnit.Animation.IDLE;
                b.gr   = gr;
                var v = b.find(new IntVec2(x, y), this, flighthouse);
                if (v == null)
                {
                    tiles_[x, y] = b;
                    //OK!
                    to_spawn--;
                }
                else if (Vector2.Distance(new Vector2(x, y), new Vector2(v.x, v.y)) > 10)
                {
                    tiles_[x, y] = b;
                    //OK!
                    to_spawn--;
                }
            }

            if (to_spawn == 0)
            {
                return;
            }

            ang += 31;
            if (ang > 360)
            {
                ang   -= 360;
                range += 5;
            }
        }
    }
Esempio n. 2
0
    void Start()
    {
        transform.position       = HivePosition;
        hiveTransform.localScale = new Vector3(hiveRadius, hiveRadius, hiveRadius);

        swarmKernel = swarmComputeShader.FindKernel("TargetSwarmMain");
        worldKernel = swarmComputeShader.FindKernel("TargetWorldUpdateMain");

        // Create rotation matrices
        CreateRotationMatrices();

        // Create the worldtexture
        worldTexture = CreateRenderTexture();

        // Create and init swarmer compute buffers
        swarmBuffer = new ComputeBuffer(numSwarmers, 56);
        Swarmer[] swarmers = new Swarmer[numSwarmers];
        for (int i = 0; i < swarmers.Length; i++)
        {
            swarmers[i].color    = new Vector3(0.20f, 1f, 0f);
            swarmers[i].position = HivePosition;/* + new Vector3(  Random.Range(-spawnRange, spawnRange),
                                                 *              Random.Range(-spawnRange, spawnRange),
                                                 *              Random.Range(-spawnRange, spawnRange));*/

            swarmers[i].previousPosition = swarmers[i].position;

            swarmers[i].direction = new Vector3(Random.Range(-1.0f, 1.0f),
                                                Random.Range(-1.0f, 1.0f),
                                                Random.Range(-1.0f, 1.0f)).normalized;

            swarmers[i].scent          = 0;
            swarmers[i].pheromoneScent = 0;
        }
        swarmBuffer.SetData(swarmers);

        // Create and init swarm targets compute buffer
        swarmTargetBuffer = new ComputeBuffer(targets.Length, 16);
        SwarmTarget[] swarmTargets = new SwarmTarget[targets.Length];
        for (int i = 0; i < swarmTargets.Length; i++)
        {
            swarmTargets[i].position = HivePosition + targets[i].localPosition;
            swarmTargets[i].hp       = 1;
        }
        swarmTargetBuffer.SetData(swarmTargets);

        // Set swarm comput shader data
        swarmComputeShader.SetInt("width", worldSize.x);
        swarmComputeShader.SetInt("height", worldSize.y);
        swarmComputeShader.SetInt("depth", worldSize.z);
        swarmComputeShader.SetTexture(swarmKernel, "worldTex", worldTexture);
        swarmComputeShader.SetBuffer(swarmKernel, "swarmers", swarmBuffer);
        swarmComputeShader.SetBuffer(swarmKernel, "targets", swarmTargetBuffer);
        swarmComputeShader.SetInt("numTargets", swarmTargets.Length);

        swarmComputeShader.SetFloats("hiveX", HivePosition.x);
        swarmComputeShader.SetFloats("hiveY", HivePosition.y);
        swarmComputeShader.SetFloats("hiveZ", HivePosition.z);
        swarmComputeShader.SetFloats("traceAdd", traceAdd);
        swarmComputeShader.SetFloats("traceDecay", traceDecay);
        swarmComputeShader.SetFloat("traceAttraction", traceAttraction);
        swarmComputeShader.SetFloat("swarmerSpeed", swarmerSpeed);
        swarmComputeShader.SetMatrix("rot1", rotMat1);
        swarmComputeShader.SetMatrix("rot2", rotMat2);
        swarmComputeShader.SetMatrix("rot3", rotMat3);
        swarmComputeShader.SetMatrix("rot4", rotMat4);
        swarmComputeShader.SetMatrix("rot5", rotMat5);
        swarmComputeShader.SetMatrix("rot6", rotMat6);
        swarmComputeShader.SetFloat("randomness", randomness);
        swarmComputeShader.SetFloat("hiveRadius", hiveRadius);

        swarmComputeShader.SetTexture(worldKernel, "worldTex", worldTexture);

        Debug.Log($"Hiveposition: {HivePosition}");


        // Set rendering materials data
        swarmerMaterial.SetBuffer("swarmers", swarmBuffer);


        // Debug
        debugWorldNodes = new WorldNode[NumWorldNodes];
    }
Esempio n. 3
0
    void Start()
    {
        transform.position = HivePosition;

        swarmKernel = swarmComputeShader.FindKernel("SwarmMain");
        worldKernel = swarmComputeShader.FindKernel("WorldUpdateMain");

        // Create rotation matrices
        CreateRotationMatrices();

        // Create and init compute buffers
        worldTexture = CreateRenderTexture();
        swarmBuffer  = new ComputeBuffer(numSwarmers, 56);
        Swarmer[] swarmers = new Swarmer[numSwarmers];
        for (int i = 0; i < swarmers.Length; i++)
        {
            swarmers[i].position = HivePosition + new Vector3(Random.Range(-spawnRange, spawnRange),
                                                              Random.Range(-spawnRange, spawnRange),
                                                              Random.Range(-spawnRange, spawnRange));

            swarmers[i].previousPosition = swarmers[i].position;

            swarmers[i].direction = new Vector3(Random.Range(-1.0f, 1.0f),
                                                Random.Range(-1.0f, 1.0f),
                                                Random.Range(-1.0f, 1.0f)).normalized;
            swarmers[i].life = Random.Range(0f, 3.0f);

            swarmers[i].startDelay = 0;

            swarmers[i].color = new Vector3(0, 0, 0);
        }
        swarmBuffer.SetData(swarmers);

        // Set swarm comput shader data
        swarmComputeShader.SetInt("width", worldSize.x);
        swarmComputeShader.SetInt("height", worldSize.y);
        swarmComputeShader.SetInt("depth", worldSize.z);
        swarmComputeShader.SetTexture(swarmKernel, "worldTex", worldTexture);
        swarmComputeShader.SetBuffer(swarmKernel, "swarmers", swarmBuffer);
        swarmComputeShader.SetFloats("hiveX", HivePosition.x);
        swarmComputeShader.SetFloats("hiveY", HivePosition.y);
        swarmComputeShader.SetFloats("hiveZ", HivePosition.z);
        swarmComputeShader.SetFloats("traceAdd", traceAdd);
        swarmComputeShader.SetFloats("traceDecay", traceDecay);
        swarmComputeShader.SetFloat("traceAttraction", traceAttraction);
        swarmComputeShader.SetFloat("swarmerSpeed", swarmerSpeed);
        swarmComputeShader.SetMatrix("rot1", rotMat1);
        swarmComputeShader.SetMatrix("rot2", rotMat2);
        swarmComputeShader.SetMatrix("rot3", rotMat3);
        swarmComputeShader.SetMatrix("rot4", rotMat4);
        swarmComputeShader.SetMatrix("rot5", rotMat5);
        swarmComputeShader.SetMatrix("rot6", rotMat6);
        swarmComputeShader.SetFloat("randomness", randomness);

        swarmComputeShader.SetTexture(worldKernel, "worldTex", worldTexture);

        Debug.Log($"Hiveposition: {HivePosition}");


        // Set rendering materials data
        swarmerMaterial.SetBuffer("swarmers", swarmBuffer);


        // Debug
        debugWorldNodes = new WorldNode[NumWorldNodes];
    }