Пример #1
0
 void WaterForce(int x, int y)
 {
     if (y < height - 1)
     {
         PixelContent downContent = pixelArray[x, y + 1].content;
         if (downContent == PixelContent.Empty || downContent == PixelContent.Steam || downContent == PixelContent.Ice)
         {
             pixelArray[x, y].acceleration += new Vector2(0.0f, gravityScale * Time.fixedDeltaTime);
         }
         else
         {
             if (pixelArray[x, y].velocity.x > 0)
             {
                 pixelArray[x, y].velocity += new Vector2(Mathf.Abs(pixelArray[x, y].velocity.y) * 0.2f,
                                                          -0.2f * pixelArray[x, y].velocity.y) * Time.deltaTime;
             }
             else
             {
                 pixelArray[x, y].velocity += new Vector2(Mathf.Abs(pixelArray[x, y].velocity.y) * -0.2f,
                                                          -0.2f * pixelArray[x, y].velocity.y) * Time.deltaTime;
             }
         }
     }
     if (pixelArray[x, y].velocity.magnitude < randThreshold)
     {
         pixelArray[x, y].velocity = new Vector2((Random.Range(0, 2) * 2 - 1) * randVelocity, pixelArray[x, y].velocity.y);
     }
 }
Пример #2
0
 protected void MoveTowards(Vector2 toTarget)
 {
     currPixel = PixelContent.Empty;
     if (pixelManager.GetContentWorld(transform.position) == PixelContent.Water)
     {
         currPixel = PixelContent.Water;
     }
     foreach (Transform child in waterProbes)
     {
         if (pixelManager.GetContentWorld(child.position) == PixelContent.Water)
         {
             currPixel = PixelContent.Water;
             break;
         }
     }
     if (currPixel == PixelContent.Empty)
     {
         GetComponent <Rigidbody2D>().drag = 0.3f;
         GetComponent <Rigidbody2D>().AddForce(airPropulsion * toTarget);
         if (canFly)
         {
             GetComponent <Rigidbody2D>().AddForce(new Vector2(0.0f, 10.65f));
         }
     }
     else if (currPixel == PixelContent.Water)
     {
         GetComponent <Rigidbody2D>().drag = 3.0f;
         GetComponent <Rigidbody2D>().AddForce(buoyantForce);
         GetComponent <Rigidbody2D>().AddForce(waterPropulsion * toTarget);
     }
 }
Пример #3
0
    void FixedUpdate()
    {
        if (!dead)
        {
            RotateTowards(dir);
            MoveTowards(dir);
            // bool submerged = true;
            // foreach (Transform child in waterProbes) {
            //     if (pixelManager.GetContentWorld(child.position) == PixelContent.Empty) {
            //         submerged = false;
            //         break;
            //     }
            // }
            // if (submerged) {
            //     lowPassFilter.enabled = true;
            //     chorusFilter.enabled = true;
            // }
            // else {
            //     lowPassFilter.enabled = false;
            //     chorusFilter.enabled = false;
            // }

            if (lastPixel != currPixel && !splashSound.isPlaying)
            {
                splashSound.Play();
            }
            lastPixel = currPixel;
        }
    }
Пример #4
0
    void SwapContent(Pixel px1, Pixel px2)
    {
        PixelContent tempContent = px1.content;

        px1.content = px2.content;
        px2.content = tempContent;
        renderQueue.Enqueue(px1);
        renderQueue.Enqueue(px2);
        px1.movedThisFrame = true;
        px2.movedThisFrame = true;
    }
Пример #5
0
    void InitShader()
    {
        transform.localScale = new Vector3(GRID_WIDTH_TILES, GRID_HEIGHT_TILES, 1);

        output = new RenderTexture(GRID_WIDTH_PIXELS, GRID_HEIGHT_PIXELS, 24);
        output.enableRandomWrite = true;
        output.filterMode        = FilterMode.Point;
        output.Create();

        uvs       = GetGridUVs();
        bufferUVs = new ComputeBuffer(uvs.Length, sizeof(float) * 2);
        bufferUVs.SetData(uvs);
        shader.SetBuffer(kernelID_Init, shaderPropertyID_uvs, bufferUVs);

        pixelsContent = new PixelContent[GRID_WIDTH_PIXELS * GRID_HEIGHT_PIXELS];
        int x = 0, y = 0;

        for (int i = 0; i < pixelsContent.Length; i++)
        {
            if (i > 0)
            {
                x++;
                if (x > GRID_WIDTH_PIXELS)
                {
                    x = 0;
                    y++;
                }
            }
            float perlinMod = 4.0f;
            float perlinX   = ((float)x / (float)GRID_WIDTH_PIXELS) * perlinMod * 3.0f;
            float perlinY   = ((float)y / (float)GRID_HEIGHT_PIXELS) * perlinMod;

            PixelContent pixel = pixelsContent[i];
            pixel.Element1    = Mathf.Pow(Mathf.PerlinNoise(perlinX, perlinY), 1);
            pixel.Element1    = Random.value;
            pixel.Wind        = new Vector4(0, Random.value, 0, 0);
            pixel.Temperature = 1000.0f;
            pixelsContent[i]  = pixel;
        }
        bufferPixels = new ComputeBuffer(pixelsContent.Length, PixelContent.GetStride());

        bufferPixels.SetData(pixelsContent);
        shader.SetBuffer(kernelID_Init, shaderPropertyID_pixelsContent, bufferPixels);

        shader.SetTexture(kernelID_Init, shaderPropertyID_terrainMap, terrainMap);

        shader.Dispatch(kernelID_Init, threadGroupCountX, threadGroupCountY, 1);
        bufferPixels.GetData(pixelsContent);
    }
Пример #6
0
    void FixedUpdate()
    {
        PixelContent currPixel = pixelManager.GetContentWorld(transform.position);

        if (currPixel == PixelContent.Empty)
        {
            GetComponent <Rigidbody2D>().drag = 0.5f;
        }
        else if (currPixel == PixelContent.Water)
        {
            GetComponent <Rigidbody2D>().drag = 5.0f;
        }

        if (Mathf.Abs(GetComponent <Rigidbody2D>().velocity.magnitude) < 0.4f)
        {
            Destroy(gameObject);
        }
    }