예제 #1
0
    void PopulateMap()
    {
        GenerateHills();

        for (int x = 0; x < mapWidth; x++)
        {
            for (int y = maxStartingHeight; y < mapHeight; y++)
            {
                streamingMap.SetBlockPrefabAt(blockPrefab, 0, x, y, 0);
                streamingMap.SetBackgroundAt(blockBackground, x, y, 0);
            }
        }
    }
예제 #2
0
    public void GenerateMapFromTexture()
    {
        if (map == null)
        {
            Debug.LogWarning("Cannot generate a map without first... having a map! Be sure you've sampled a texture.");
            return;
        }

        if (pixelScale <= 0.0f)
        {
            Debug.LogWarning("Cannot generate a map without a greater-than-zero pixel scale. Be sure you've sampled a texture.");
            return;
        }

        if (texture == null)
        {
            Debug.LogWarning("Cannot generate a map without a texture. Sample a texture, my friend.");
            return;
        }

        //Yeah, we sample the texture twice.
        //I'm not happy about it either,
        //But otherwise it'd be like...
        //Make an index map up there ^
        //And then shuffle the indices around when they change
        //
        //And dude.. It's like 5.32pm here. That's clocking-off time.
        //
        //My elephant teapot is almost ready
        //I'll drink tea
        //But i'll leave this.
        //Deal? Deal.

        int interval       = (int)pixelScale;
        int start_interval = (int)(pixelScale * 0.5f);

        int xc = 0, yc = 0;

        for (int x = start_interval; x < texture.width; x += interval)
        {
            yc = 0;

            for (int y = start_interval; y < texture.height; y += interval)
            {
                Color c = texture.GetPixel(x, y);

                int i = GetColorIndex(c);

                if (i == -1)
                {
                    continue;
                }

                map.SetBlockPrefabAt(blocks[i], xc, map.height - yc, 1);

                yc++;
            }

            xc++;
        }

        map.generateMapOnAwake = true;
    }
예제 #3
0
    public void Dig()
    {
        //Set the facing direction

        Direction facing = Direction.None;

        //You'll need to change this if you're using some sort of smoothing
        //this is just to show the dealio
        Vector3 forward = transform.forward;

        if (forward == frontDirection)
        {
            facing = Direction.Down;
        }
        else if (forward == backDirection)
        {
            facing = Direction.Up;
        }
        else if (forward == leftDirection)
        {
            facing = Direction.Left;
        }
        else if (forward == rightDirection)
        {
            facing = Direction.Right;
        }

        int d_x = y, d_y = x;

        switch (facing)
        {
        case Direction.Down: {
            d_x = this.x;
            d_y = this.y + 1;
            break;
        }

        case Direction.Up: {
            d_x = this.x;
            d_y = this.y - 1;
            break;
        }

        case Direction.Right: {
            d_x = this.x + 1;
            d_y = this.y;
            break;
        }

        case Direction.Left: {
            d_x = this.x - 1;
            d_y = this.y;
            break;
        }

        case Direction.None: {
            return;
        }
        }

        //We need to do a few things here
        if (streamingMap != null)
        {
            if (d_x < 0 || d_x >= streamingMap.width ||
                d_y < 0 || d_y >= streamingMap.height)
            {
                return;
            }
        }
        else
        {
            if (d_x < 0 || d_x >= BlockUtilities.GetMapWidth(parentMap) ||
                d_y < 0 || d_y >= BlockUtilities.GetMapHeight(parentMap))
            {
                return;
            }
        }

        //Looks like we can do it!
        //You will probably want to implement a "Diggable" / "Not Diggable" logic here
        //But for now - we dig!

        BlockUtilities.RemoveBlockFromMap(parentMap, d_x, d_y, 0, false, false);

        if (streamingMap != null)
        {
            streamingMap.SetBlockPrefabAt(null, d_x, d_y, 0);
        }
    }