Example #1
0
    public void ApplyRadial(Vector3 point, float radius)
    {
        point = Camera.main.ScreenToWorldPoint(point);
        Rect dmgBox = new Rect(point.x - radius, point.y - radius, radius * 2, radius * 2f);

        Rect chunkRange          = MathTests.GetOverlappingBox(planetFrame, dmgBox);
        Rect chunkRangeUnits     = MathTests.BoxChunkUnits(chunkRange);
        Rect chunkRangeUnitsDisc = MathTests.BoxToGrid(chunkRangeUnits);

        for (float y = chunkRangeUnitsDisc.y; y < chunkRangeUnitsDisc.y + chunkRangeUnitsDisc.height; y++)
        {
            for (float x = chunkRangeUnitsDisc.x; x < chunkRangeUnitsDisc.x + chunkRangeUnitsDisc.width; x++)
            {
                ChunkTexture chunk = chunks[((int)y + radiusChunks) * radiusChunks * 2 + ((int)x + radiusChunks)];

                Rect chunkBox   = new Rect(x, y, 1f, 1f);
                Rect overlapBox = MathTests.GetOverlappingBox(chunkRangeUnits, chunkBox);

                Rect pixelsBox = GetPixelsBox(chunkBox, overlapBox);

                chunk.ApplyRadial(point, radius, pixelsBox);
                chunk.UpdateColliders(pixelsBox);
            }
        }
    }
Example #2
0
    private void Load(float factor)
    {
        Rect innerFrame = new Rect(gameManager.ship.transform.position.x - gameManager.viewWidth * factor * 0.5f, gameManager.ship.transform.position.y - gameManager.viewHeight * factor * 0.5f, gameManager.viewWidth * factor, gameManager.viewHeight * factor);

        Rect loadBox       = MathTests.GetOverlappingBox(planetFrame, innerFrame);
        Rect loadBoxGrid   = MathTests.BoxChunkUnits(loadBox);
        Rect chunkGenFrame = MathTests.BoxToGrid(loadBoxGrid);

        GenerateChunksWithin(chunkGenFrame, loadBoxGrid);

        gameManager.lastGenCent = new Vector2(gameManager.ship.transform.position.x, gameManager.ship.transform.position.y);
    }