예제 #1
0
    public void GenerateChunksWithin(Rect frameDisc, Rect frameCont)
    {
        for (float y = frameDisc.y; y < frameDisc.y + frameDisc.height; y++)
        {
            for (float x = frameDisc.x; x < frameDisc.x + frameDisc.width; x++)
            {
                ChunkTexture chunk = null;
                if (chunks[((int)y + radiusChunks) * radiusChunks * 2 + ((int)x + radiusChunks)] != null)
                {
                    chunk = chunks[((int)y + radiusChunks) * radiusChunks * 2 + ((int)x + radiusChunks)];
                }
                else
                {
                    Vector3 chunkPos = new Vector3(x * GameManager.CHUNK_SIZE, y * GameManager.CHUNK_SIZE, 0f);

                    chunk = (ChunkTexture)Instantiate(chunkTexture, chunkPos, Quaternion.identity);
                    chunk.Init();

                    chunk.transform.parent = gameObject.transform;

                    // chunk.FillTextureTrans();

                    chunks[((int)y + radiusChunks) * radiusChunks * 2 + ((int)x + radiusChunks)] = chunk;
                }

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

                Rect chunkDivBox = GetChunkDivisionBox(chunkBox, overlapBox, div);

                GenParts(chunk, chunkDivBox);
            }
        }
    }
예제 #2
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);
            }
        }
    }
예제 #3
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);
    }
예제 #4
0
 public void Setup()
 {
     _math = new MathTests();
 }