コード例 #1
0
        public override bool Generate(CubeWorld world)
        {
            int fromY = fromYRV.EvaluateInt(world);
            int toY   = toYRV.EvaluateInt(world);

            TileManager tileManager = world.tileManager;

            Random rnd = new Random();

            for (int x = 0; x < tileManager.sizeX; x++)
            {
                for (int z = 0; z < tileManager.sizeZ; z++)
                {
                    for (int y = fromY; y < toY; y++)
                    {
                        TilePosition pos = new TilePosition(x, y, z);
                        if (tileManager.GetTileType(pos) == TileDefinition.EMPTY_TILE_TYPE)
                        {
                            int n = rnd.Next(0, probabilityRange);
                            foreach (TileTypeProbability s in probabilities)
                            {
                                if (n < s.probability)
                                {
                                    tileManager.SetTileType(pos, s.tileType);
                                    break;
                                }
                            }
                        }
                    }
                }
            }

            return(true);
        }
コード例 #2
0
		public DayCycleManager (CubeWorld world)
		{
			this.world = world;

            this.skyColor = skyColorDay;
            this.ambientLightLuminance = Tile.MAX_LUMINANCE;
		}
コード例 #3
0
        public override bool Generate(CubeWorld world)
        {
            int fromY = fromYRV.EvaluateInt(world);
            int toY   = toYRV.EvaluateInt(world);

            TileManager tileManager = world.tileManager;

            for (int x = 0; x < tileManager.sizeX; x++)
            {
                for (int z = 0; z < tileManager.sizeZ; z++)
                {
                    int y = tileManager.GetTopPosition(x, z);

                    if (tileManager.GetTileType(new TilePosition(x, y, z)) != TileDefinition.EMPTY_TILE_TYPE)
                    {
                        y++;
                    }

                    if (y >= fromY)
                    {
                        for (int i = y; i < toY; i++)
                        {
                            tileManager.SetTileType(new TilePosition(x, i, z), waterTileType);
                        }
                    }
                }
            }

            return(true);
        }
コード例 #4
0
        public override bool Generate(CubeWorld world)
        {
            int fromY = fromYRV.EvaluateInt(world);
            int toY = toYRV.EvaluateInt(world);

			TileManager tileManager = world.tileManager;
			
            Random rnd = new Random();

            for (int x = 0; x < tileManager.sizeX; x++)
                for (int z = 0; z < tileManager.sizeZ; z++)
                    for (int y = fromY; y < toY; y++)
                    {
                        TilePosition pos = new TilePosition(x, y, z);
                        if (tileManager.GetTileType(pos) == TileDefinition.EMPTY_TILE_TYPE)
                        {
                            int n = rnd.Next(0, probabilityRange);
                            foreach (TileTypeProbability s in probabilities)
                            {
                                if (n < s.probability)
                                {
                                    tileManager.SetTileType(pos, s.tileType);
                                    break;
                                }
                            }
                        }
                    }

            return true;
        }
コード例 #5
0
        public override bool Generate(CubeWorld world)
        {
            Random random = new Random();

            int iterations = iterationsRV.EvaluateInt(world);
            int minRadius  = minRadiusRV.EvaluateInt(world);
            int maxRadius  = maxRadiusRV.EvaluateInt(world);

            TileManager tileManager = world.tileManager;

            for (int i = 0; i < iterations; i++)
            {
                int cx = random.Next(maxRadius + 1, tileManager.sizeX - maxRadius - 1);
                int cz = random.Next(maxRadius + 1, tileManager.sizeZ - maxRadius - 1);

                int radius = random.Next(minRadius, maxRadius);

                int sum = 0;

                for (int x = cx - radius; x < cx + radius; x++)
                {
                    for (int z = cz - radius; z < cz + radius; z++)
                    {
                        sum += tileManager.GetTopPosition(x, z);
                    }
                }

                int avg = sum / (radius * 2 * radius * 2);

                for (int x = cx - radius; x < cx + radius; x++)
                {
                    for (int z = cz - radius; z < cz + radius; z++)
                    {
                        int y = tileManager.GetTopPosition(x, z);

                        if (avg - y < -1 || avg - y > 1)
                        {
                            if (y > avg)
                            {
                                //Remove tiles
                                for (int dy = avg + 1; dy <= y; dy++)
                                {
                                    tileManager.SetTileType(new TilePosition(x, dy, z), 0);
                                }
                            }
                            else if (y < avg)
                            {
                                //Add tiles
                                for (int dy = y; dy <= avg; dy++)
                                {
                                    tileManager.SetTileType(new TilePosition(x, dy, z), tileType);
                                }
                            }
                        }
                    }
                }
            }

            return(true);
        }
コード例 #6
0
        private void PlantTree(int x, int z, CubeWorld world)
        {
            TileManager tileManager = world.tileManager;

            int topY = tileManager.GetTopPosition(x, z);

            if (topY < tileManager.sizeY - (maxTrunkHeight + maxLeavesHeight) * 2)
            {
                if (tileManager.GetTileType(new TilePosition(x, topY, z)) == overTileType)
                {
                    topY++;

                    int trunkHeight  = generator.Next(minTrunkHeight, maxTrunkHeight + 1);
                    int leavesHeight = generator.Next(minLeavesHeight, maxLeavesHeight + 1);
                    int leavesRadius = generator.Next(minLeavesRadius, maxLeavesRadius + 1);

                    int treeHeight = trunkHeight + leavesHeight;

                    if (FreeSpaceAvailable(x, topY, z, leavesRadius, treeHeight, world))
                    {
                        CreateTree(x, topY, z, trunkHeight, leavesHeight, leavesRadius, world);
                    }
                }
            }
        }
コード例 #7
0
        public float Evaluate(CubeWorld world)
        {
            switch (relativeTo)
            {
            case RelativeTo.Nothing:
                return(value);

            case RelativeTo.SizeX:
                return(world.sizeX * value);

            case RelativeTo.SizeY:
                return(world.sizeY * value);

            case RelativeTo.SizeZ:
                return(world.sizeZ * value);

            case RelativeTo.SizeXY:
                return((world.sizeX * world.sizeY) * value);

            case RelativeTo.SizeXZ:
                return((world.sizeX * world.sizeZ) * value);

            case RelativeTo.SizeYZ:
                return((world.sizeY * world.sizeZ) * value);

            case RelativeTo.SizeVolumen:
                return((world.sizeX * world.sizeY * world.sizeZ) * value);
            }

            return(0);
        }
コード例 #8
0
        public override bool Generate(CubeWorld world)
        {
			TileManager tileManager = world.tileManager;
			
            int fromY = fromYRV.EvaluateInt(world);
            int toY = toYRV.EvaluateInt(world);
			
			//C3DPerlinNoise.Init();
			int seed = new Random().Next();
			
			int cutY = (int) (fromY + (toY - fromY) * 0.7f);
			
            for (int x = 0; x < tileManager.sizeX; x++)
			{
                for (int z = 0; z < tileManager.sizeZ; z++)
				{
					float d = GetRandomHeight(x, z, 1.0f, freq, 1.0f, 0.5f, octaves, seed);
					
					int y = (int) (fromY + d * (toY - fromY)) - 1;
					
					if (y > cutY)
						y = cutY;
					else if (y < fromY - 1)
						y = fromY - 1;

                    while (y >= fromY)
                        tileManager.SetTileType(new TilePosition(x, y--, z), tileType);
				}
			}
			
			NoiseInitialized = false;

            return true;
        }
コード例 #9
0
        public DayCycleManager(CubeWorld world)
        {
            this.world = world;

            this.skyColor = skyColorDay;
            this.ambientLightLuminance = Tile.MAX_LUMINANCE;
        }
コード例 #10
0
        public float Evaluate(CubeWorld world)
        {
            switch (relativeTo)
            {
                case RelativeTo.Nothing:
                    return value;

                case RelativeTo.SizeX:
                    return world.sizeX * value;
                case RelativeTo.SizeY:
                    return world.sizeY * value;
                case RelativeTo.SizeZ:
                    return world.sizeZ * value;

                case RelativeTo.SizeXY:
                    return (world.sizeX * world.sizeY) * value;
                case RelativeTo.SizeXZ:
                    return (world.sizeX * world.sizeZ) * value;
                case RelativeTo.SizeYZ:
                    return (world.sizeY * world.sizeZ) * value;

                case RelativeTo.SizeVolumen:
                    return (world.sizeX * world.sizeY * world.sizeZ) * value;
            }

            return 0;
        }
コード例 #11
0
        private void CreateLevel(CubeWorld world, int level)
        {
            int floor_y   = level * LEVEL_HEIGHT;
            int ceiling_y = level * (LEVEL_HEIGHT + 1);

            //Create floor
            for (int x = 0; x < world.sizeX; x++)
            {
                for (int z = 0; z < world.sizeZ; z++)
                {
                    world.tileManager.SetTileType(new TilePosition(x, floor_y, z), tileTypeHardRock);
                }
            }

            //Create walls
            for (int y = floor_y; y < ceiling_y; y++)
            {
                for (int z = 0; z < world.sizeZ; z++)
                {
                    world.tileManager.SetTileType(new TilePosition(0, y, z), tileTypeHardRock);
                    world.tileManager.SetTileType(new TilePosition(world.sizeX - 1, y, z), tileTypeHardRock);
                }
            }
            for (int y = floor_y; y < ceiling_y; y++)
            {
                for (int x = 0; x < world.sizeX; x++)
                {
                    world.tileManager.SetTileType(new TilePosition(x, y, 0), tileTypeHardRock);
                    world.tileManager.SetTileType(new TilePosition(x, y, world.sizeZ - 1), tileTypeHardRock);
                }
            }
        }
コード例 #12
0
        public override bool Generate(CubeWorld world)
        {
            int fromY = fromYRV.EvaluateInt(world);
            int toY = toYRV.EvaluateInt(world);

			TileManager tileManager = world.tileManager;
			
            for (int x = 0; x < tileManager.sizeX; x++)
            {
                for (int z = 0; z < tileManager.sizeZ; z++)
                {
                    int y = tileManager.GetTopPosition(x, z);

                    if (tileManager.GetTileType(new TilePosition(x, y, z)) != TileDefinition.EMPTY_TILE_TYPE)
                        y++;

                    if (y >= fromY)
                    {
                        for (int i = y; i < toY; i++)
                            tileManager.SetTileType(new TilePosition(x, i, z), waterTileType);
                    }
                }
            }

            return true;
        }
コード例 #13
0
        public override CubeWorld.World.Generator.GeneratorProcess Generate(CubeWorld.Configuration.Config config)
        {
            RoguelikeWorldGenerator generator = new RoguelikeWorldGenerator(world);

            this.playerStartPosition = generator.playerStartPosition;

            return world.tileManager.Generate(generator);
        }
コード例 #14
0
        public override bool Generate(CubeWorld world)
        {
            InitTileTypes(world);

            CreateBasicLevels(world);

            return true;
        }
コード例 #15
0
 public RoguelikeWorldGenerator(CubeWorld world)
 {
     playerStartPosition =
         new TilePosition(
             LEVEL_HEIGHT / 2,
             world.sizeY - LEVEL_HEIGHT + 3,
             LEVEL_HEIGHT / 2);
 }
コード例 #16
0
        public override bool Generate(CubeWorld world)
        {
            InitTileTypes(world);

            CreateBasicLevels(world);

            return(true);
        }
コード例 #17
0
ファイル: CubeWorldTests.cs プロジェクト: Fro-Z/CubeGame
    public void Test_GetChunkPos()
    {
        Assert.IsTrue(Chunk.CHUNK_SIZE > 1);
        Assert.AreEqual(CubeWorld.GetChunkPos(new Vector3Int(0, 1, Chunk.CHUNK_SIZE - 1)), new Vector2Int(0, 0));

        Assert.AreEqual(CubeWorld.GetChunkPos(new Vector3Int(-1, 0, 0)), new Vector2Int(-1, 0));
        Assert.AreEqual(CubeWorld.GetChunkPos(new Vector3Int(-Chunk.CHUNK_SIZE, 0, 0)), new Vector2Int(-1, 0));
    }
コード例 #18
0
 public RoguelikeWorldGenerator(CubeWorld world)
 {
     playerStartPosition =
         new TilePosition(
             LEVEL_HEIGHT / 2,
             world.sizeY - LEVEL_HEIGHT + 3,
             LEVEL_HEIGHT / 2);
 }
コード例 #19
0
        public GeneratorProcess(CubeWorldGenerator generator, CubeWorld world)
        {
            this.finished  = false;
            this.generator = generator;
            this.world     = world;

            generator.Prepare();
            totalCost = generator.GetTotalCost();
        }
コード例 #20
0
        public override bool Generate(CubeWorld world)
        {
            int iterations = iterationsRV.EvaluateInt(world);
            int minRadius  = minRadiusRV.EvaluateInt(world);
            int maxRadius  = maxRadiusRV.EvaluateInt(world);
            int minDepth   = minDepthRV.EvaluateInt(world);
            int maxDepth   = maxDepthRV.EvaluateInt(world);

            TileManager tileManager = world.tileManager;

            Random random = new Random();

            for (int i = 0; i < iterations; i++)
            {
                int cx = random.Next(maxRadius + 1, tileManager.sizeX - maxRadius - 1);
                int cz = random.Next(maxRadius + 1, tileManager.sizeZ - maxRadius - 1);

                int radiusX = random.Next(minRadius, maxRadius);
                int radiusZ = random.Next(minRadius, maxRadius);

                int depth = random.Next(minDepth, maxDepth);

                int sum = 0;

                for (int x = cx - radiusX; x < cx + radiusX; x++)
                {
                    for (int z = cz - radiusZ; z < cz + radiusZ; z++)
                    {
                        sum += tileManager.GetTopPosition(x, z);
                    }
                }

                int avg = sum / (radiusX * 2 * radiusZ * 2);

                if (avg - depth > 1)
                {
                    for (int x = cx - radiusX; x < cx + radiusX; x++)
                    {
                        for (int z = cz - radiusZ; z < cz + radiusZ; z++)
                        {
                            int y = tileManager.GetTopPosition(x, z);

                            if (y > avg - depth)
                            {
                                //Remove tiles
                                for (int dy = (avg - depth) + 1; dy <= y; dy++)
                                {
                                    tileManager.SetTileType(new TilePosition(x, dy, z), 0);
                                }
                            }
                        }
                    }
                }
            }

            return(true);
        }
コード例 #21
0
        public GeneratorProcess(CubeWorldGenerator generator, CubeWorld world)
        {
            this.finished = false;
            this.generator = generator;
            this.world = world;

            generator.Prepare();
            totalCost = generator.GetTotalCost();
        }
コード例 #22
0
ファイル: CubeWorldTests.cs プロジェクト: Fro-Z/CubeGame
    public void Test_GetBlockPos()
    {
        float cubeSize = CubeWorld.CUBE_SIZE;

        Assert.AreEqual(CubeWorld.GetBlockPos(new Vector3(1, 2, 3) * cubeSize), new Vector3Int(1, 2, 3));
        Assert.AreEqual(CubeWorld.GetBlockPos(new Vector3(1.01f, 2.99f, 3.5f) * cubeSize), new Vector3Int(1, 2, 3));

        Assert.AreEqual(CubeWorld.GetBlockPos(new Vector3(-1.5f, 0f, 3.5f) * cubeSize), new Vector3Int(-2, 0, 3));
    }
コード例 #23
0
    bool CanBuild(Vector3Int blockPos)
    {
        Vector3Int playerBlockPos = CubeWorld.GetBlockPos(gameObject.transform.position);

        if (blockPos.x == playerBlockPos.x && blockPos.z == playerBlockPos.z &&
            Mathf.Abs(playerBlockPos.y - blockPos.y) <= 2)
        {
            return(false);            //prevent building inside yourself and falling through the new mesh
        }
        return(world.GetBlockType(blockPos) == BLOCK_AIR);
    }
コード例 #24
0
ファイル: CWObject.cs プロジェクト: carriercomm/CubeWorld
        public virtual void Clear()
        {
            if (components != null)
            {
                foreach (CWComponent component in components)
                    component.RemovedFromObject();

                components.Clear();
            }

            world = null;
        }
コード例 #25
0
ファイル: CubeWorldTests.cs プロジェクト: Fro-Z/CubeGame
    public void Test_GetChunkOffset()
    {
        Assert.IsTrue(Chunk.CHUNK_SIZE > 1);
        Assert.AreEqual(CubeWorld.GetChunkOffset(new Vector3Int(1, 2, 3)), new Vector3Int(1, 2, 3));
        Assert.AreEqual(CubeWorld.GetChunkOffset(new Vector3Int(Chunk.CHUNK_SIZE + 1, 2, 3)), new Vector3Int(1, 2, 3));

        Assert.AreEqual(CubeWorld.GetChunkOffset(new Vector3Int(-1, 0, 0)), new Vector3Int(15, 0, 0));
        Assert.AreEqual(CubeWorld.GetChunkOffset(new Vector3Int(-15, 0, 0)), new Vector3Int(1, 0, 0));
        Assert.AreEqual(CubeWorld.GetChunkOffset(new Vector3Int(-16, 0, 0)), new Vector3Int(0, 0, 0));
        Assert.AreEqual(CubeWorld.GetChunkOffset(new Vector3Int(-17, 0, 0)), new Vector3Int(15, 0, 0));
        Assert.AreEqual(CubeWorld.GetChunkOffset(new Vector3Int(-32, 0, 0)), new Vector3Int(0, 0, 0));
    }
コード例 #26
0
        public override bool Generate(CubeWorld world)
        {
            Random random = new Random();

            int iterations = iterationsRV.EvaluateInt(world);
            int minRadius = minRadiusRV.EvaluateInt(world);
            int maxRadius = maxRadiusRV.EvaluateInt(world);

			TileManager tileManager = world.tileManager;
			
            for (int i = 0; i < iterations; i++)
            {
                int cx = random.Next(maxRadius + 1, tileManager.sizeX - maxRadius - 1);
                int cz = random.Next(maxRadius + 1, tileManager.sizeZ - maxRadius - 1);

                int radius = random.Next(minRadius, maxRadius);

                int sum = 0;

                for (int x = cx - radius; x < cx + radius; x++)
                    for (int z = cz - radius; z < cz + radius; z++)
                        sum += tileManager.GetTopPosition(x, z);

                int avg = sum / (radius * 2 * radius * 2);

                for (int x = cx - radius; x < cx + radius; x++)
                {
                    for (int z = cz - radius; z < cz + radius; z++)
                    {
                        int y = tileManager.GetTopPosition(x, z);

                        if (avg - y < -1 || avg - y > 1)
                        {
                            if (y > avg)
                            {
                                //Remove tiles
                                for (int dy = avg + 1; dy <= y; dy++)
                                    tileManager.SetTileType(new TilePosition(x, dy, z), 0);
                            }
                            else if (y < avg)
                            {
                                //Add tiles
                                for (int dy = y; dy <= avg; dy++)
                                    tileManager.SetTileType(new TilePosition(x, dy, z), tileType);
                            }
                        }
                    }
                }
            }

            return true;
        }
コード例 #27
0
        private void CreateBasicLevels(CubeWorld world)
        {
            for (int level = 0; level < world.sizeY / LEVEL_HEIGHT; level++)
                CreateLevel(world, level);

            //Create ceiling
            for (int x = 0; x < world.sizeX; x++)
                for (int z = 0; z < world.sizeZ; z++)
                    if (x % 3 == 0 && z % 3 == 0)
                        world.tileManager.SetTileType(new TilePosition(x, world.sizeY - 1, z), tileTypeCeilingGlass);
                    else
                        world.tileManager.SetTileType(new TilePosition(x, world.sizeY - 1, z), tileTypeHardRock);
        }
コード例 #28
0
        public override bool Generate(CubeWorld world)
        {
            if (currentGeneratorIndex < generators.Count)
            {
                if (generators[currentGeneratorIndex].Generate(world) == true)
                {
                    currentCost += generators[currentGeneratorIndex].GetTotalCost();
                    currentGeneratorIndex++;
                }
            }

            return currentGeneratorIndex == generators.Count;
        }
コード例 #29
0
        public override void Init(CubeWorld.World.CubeWorld world)
        {
            base.Init(world);

            stats = MultiplayerStats.Singleton;
            stats.Reset();
            stats.serverMode = true;
            stats.connected = true;

            baseGameplay.Init(world);

            server = new MultiplayerServer(9999, this, this);
        }
コード例 #30
0
        public override bool Generate(CubeWorld world)
        {
            if (currentGeneratorIndex < generators.Count)
            {
                if (generators[currentGeneratorIndex].Generate(world) == true)
                {
                    currentCost += generators[currentGeneratorIndex].GetTotalCost();
                    currentGeneratorIndex++;
                }
            }

            return(currentGeneratorIndex == generators.Count);
        }
コード例 #31
0
        public override bool Generate(CubeWorld world)
        {
            int iterations = iterationsRV.EvaluateInt(world);
            int minRadius = minRadiusRV.EvaluateInt(world);
            int maxRadius = maxRadiusRV.EvaluateInt(world);
            int minDepth = minDepthRV.EvaluateInt(world);
            int maxDepth = maxDepthRV.EvaluateInt(world);
			
			TileManager tileManager = world.tileManager;

            Random random = new Random();

            for (int i = 0; i < iterations; i++)
            {
                int cx = random.Next(maxRadius + 1, tileManager.sizeX - maxRadius - 1);
                int cz = random.Next(maxRadius + 1, tileManager.sizeZ - maxRadius - 1);

                int radiusX = random.Next(minRadius, maxRadius);
                int radiusZ = random.Next(minRadius, maxRadius);

                int depth = random.Next(minDepth, maxDepth);

                int sum = 0;

                for (int x = cx - radiusX; x < cx + radiusX; x++)
                    for (int z = cz - radiusZ; z < cz + radiusZ; z++)
                        sum += tileManager.GetTopPosition(x, z);

                int avg = sum / (radiusX * 2 * radiusZ * 2);

                if (avg - depth > 1)
                {
                    for (int x = cx - radiusX; x < cx + radiusX; x++)
                    {
                        for (int z = cz - radiusZ; z < cz + radiusZ; z++)
                        {
                            int y = tileManager.GetTopPosition(x, z);

                            if (y > avg - depth)
                            {
                                //Remove tiles
                                for (int dy = (avg - depth) + 1; dy <= y; dy++)
                                    tileManager.SetTileType(new TilePosition(x, dy, z), 0);
                            }
                        }
                    }
                }
            }

            return true;
        }
コード例 #32
0
ファイル: CWObject.cs プロジェクト: jamurr/AdventureKit_Unity
        public virtual void Clear()
        {
            if (components != null)
            {
                foreach (CWComponent component in components)
                {
                    component.RemovedFromObject();
                }

                components.Clear();
            }

            world = null;
        }
コード例 #33
0
        public override bool Generate(CubeWorld world)
        {
            if (offInitialized == false)
            {
                Random rnd = new Random();
                offX           = rnd.Next(0, 9999999);
                offY           = rnd.Next(0, 9999999);
                offInitialized = true;
            }

            TileManager tileManager = world.tileManager;

            int fromY = fromYRV.EvaluateInt(world);
            int toY   = toYRV.EvaluateInt(world);

            int cutY = (int)(fromY + (toY - fromY) * 0.9f);
            int midY = fromY + (toY - fromY) / 2;

            for (int x = 0; x < tileManager.sizeX; x++)
            {
                for (int z = 0; z < tileManager.sizeZ; z++)
                {
                    float d = FBM(x + offX, z + offY, octaves, 0.5f, freq, 1.0f / octaves, 2.0f);
                    //float d = MultiFractal(x, z, octaves, 0.5f, freq, 1.0f, 2.0f, 1.0f);

                    int y = midY + (int)(d * (toY - fromY));

                    //This line below can be used to make calderas
                    //if (y > cutY)
                    //    y = cutY - (y - cutY);

                    if (y > cutY)
                    {
                        y = cutY;
                    }
                    else if (y < fromY - 1)
                    {
                        y = fromY - 1;
                    }

                    while (y >= fromY)
                    {
                        tileManager.SetTileType(new TilePosition(x, y--, z), tileType);
                    }
                }
            }


            return(true);
        }
コード例 #34
0
        public override bool Generate(CubeWorld world)
        {
            int iterations = iterationsRV.EvaluateInt(world);
            int minRadius  = minRadiusRV.EvaluateInt(world);
            int maxRadius  = maxRadiusRV.EvaluateInt(world);
            int fromY      = fromYRV.EvaluateInt(world);
            int toY        = toYRV.EvaluateInt(world);

            TileManager tileManager = world.tileManager;

            Random random = new Random();

            for (int i = 0; i < iterations; i++)
            {
                int cx = random.Next(maxRadius + 1, tileManager.sizeX - maxRadius - 1);
                int cy = random.Next(maxRadius + 1, tileManager.sizeY - maxRadius - 1);
                int cz = random.Next(maxRadius + 1, tileManager.sizeZ - maxRadius - 1);

                int radiusX = random.Next(minRadius, maxRadius);
                int radiusY = random.Next(minRadius, maxRadius);
                int radiusZ = random.Next(minRadius, maxRadius);

                for (int x = cx - radiusX; x < cx + radiusX; x++)
                {
                    for (int z = cz - radiusZ; z < cz + radiusZ; z++)
                    {
                        for (int y = cy - radiusY; y < cy + radiusY; y++)
                        {
                            if (y >= fromY && y < toY)
                            {
                                if (random.NextDouble() > 0.25)
                                {
                                    if (allowEmptyAbove || y == tileManager.sizeY || tileManager.GetTileType(new TilePosition(x, y + 1, z)) != TileDefinition.EMPTY_TILE_TYPE)
                                    {
                                        if (tileManager.GetTileType(new TilePosition(x, y, z)) == overTile)
                                        {
                                            tileManager.SetTileType(new TilePosition(x, y, z), tileType);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return(true);
        }
コード例 #35
0
        public override bool Generate(CubeWorld world)
        {
            int trees = generator.Next(minRV.EvaluateInt(world), maxRV.EvaluateInt(world));

            TileManager tileManager = world.tileManager;

            for (int i = 0; i < trees; i++)
            {
                int x = generator.Next(maxLeavesRadius * 2, tileManager.sizeX - maxLeavesRadius * 2);
                int z = generator.Next(maxLeavesRadius * 2, tileManager.sizeZ - maxLeavesRadius * 2);

                PlantTree(x, z, world);
            }

            return(true);
        }
コード例 #36
0
        public override bool Generate(CubeWorld world)
        {
            int trees = generator.Next(minRV.EvaluateInt(world), maxRV.EvaluateInt(world));

			TileManager tileManager = world.tileManager;
			
            for (int i = 0; i < trees; i++)
            {
                int x = generator.Next(maxLeavesRadius * 2, tileManager.sizeX - maxLeavesRadius * 2);
                int z = generator.Next(maxLeavesRadius * 2, tileManager.sizeZ - maxLeavesRadius * 2);

                PlantTree(x, z, world);
            }

            return true;
        }
コード例 #37
0
    /// <summary>
    /// Get cube after raycast hit from camera
    /// </summary>
    bool GetAimpointNextBlock(out Vector3Int blockPos)
    {
        //raycast to find block empty block position
        Ray        ray = new Ray(Camera.main.transform.position, Camera.main.transform.forward);
        RaycastHit hit;

        if (Physics.Raycast(ray, out hit, distanceLimit))
        {
            //move hit position to roughly be in previous block
            hit.point -= (hit.normal * 0.1f);
            blockPos   = CubeWorld.GetBlockPos(hit.point);
            return(true);
        }

        blockPos = new Vector3Int();
        return(false);
    }
コード例 #38
0
        public override bool Generate(CubeWorld world)
        {
            int fromY = fromYRV.EvaluateInt(world);
            int toY = toYRV.EvaluateInt(world);
			
			TileManager tileManager = world.tileManager;
			
            for (int x = 0; x < tileManager.sizeX; x++)
                for (int z = 0; z < tileManager.sizeZ; z++)
                    for (int y = fromY; y < toY; y++)
                    {
                        TilePosition pos = new TilePosition(x, y, z);
                        if (tileManager.GetTileType(pos) == TileDefinition.EMPTY_TILE_TYPE)
                            tileManager.SetTileType(pos, tileType);
                    }

            return true;
        }
コード例 #39
0
        public override bool Generate(CubeWorld world)
        {
			if (offInitialized == false)
			{
				Random rnd = new Random();
				offX = rnd.Next(0, 9999999);
				offY = rnd.Next(0, 9999999);
				offInitialized = true;
			}

			TileManager tileManager = world.tileManager;
			
            int fromY = fromYRV.EvaluateInt(world);
            int toY = toYRV.EvaluateInt(world);
			
			int cutY = (int) (fromY + (toY - fromY) * 0.9f);
            int midY = fromY + (toY - fromY) / 2;
			
            for (int x = 0; x < tileManager.sizeX; x++)
			{
                for (int z = 0; z < tileManager.sizeZ; z++)
				{
                    float d = FBM(x + offX, z + offY, octaves, 0.5f, freq, 1.0f / octaves, 2.0f);
                    //float d = MultiFractal(x, z, octaves, 0.5f, freq, 1.0f, 2.0f, 1.0f);
					
					int y = midY + (int) (d * (toY - fromY));

                    //This line below can be used to make calderas
                    //if (y > cutY)
                    //    y = cutY - (y - cutY);  
					
					if (y > cutY)
						y = cutY;
					else if (y < fromY - 1)
						y = fromY - 1;

                    while (y >= fromY)
                        tileManager.SetTileType(new TilePosition(x, y--, z), tileType);
				}
			}
			

            return true;
        }
コード例 #40
0
    void Start()
    {
        selectedBlock = BlockRegistry.GetTypeByName("Dirt");

        var worldObject = GameObject.Find("World");

        if (worldObject)
        {
            world = worldObject.GetComponent <CubeWorld>();
        }

        placementCube = GameObject.CreatePrimitive(PrimitiveType.Cube);
        placementCube.GetComponent <MeshRenderer>().material = placementCubeMaterial;
        placementCube.GetComponent <MeshRenderer>().enabled  = false;
        placementCube.GetComponent <BoxCollider>().enabled   = false;

        //cube is slightly bigger, to prevent depth fighting
        placementCube.transform.localScale = new Vector3(CubeWorld.CUBE_SIZE, CubeWorld.CUBE_SIZE, CubeWorld.CUBE_SIZE) * 1.05f;
    }
コード例 #41
0
        public override bool Generate(CubeWorld world)
        {
            TileManager tileManager = world.tileManager;

            int fromY = fromYRV.EvaluateInt(world);
            int toY   = toYRV.EvaluateInt(world);

            width  = tileManager.sizeX;
            height = tileManager.sizeZ;

            map = new float[width + 1, height + 1];

            //StartMidpointDisplacment();
            //Assign the four corners of the intial grid random color values
            //These will end up being the colors of the four corners of the applet.

            float c1, c2, c3, c4;

            c1 = (float)rnd.NextDouble();
            c2 = (float)rnd.NextDouble();
            c3 = (float)rnd.NextDouble();
            c4 = (float)rnd.NextDouble();

            DivideGrid(0, 0, width, height, c1, c2, c3, c4);

            for (int x = 0; x < tileManager.sizeX; x++)
            {
                for (int z = 0; z < tileManager.sizeZ; z++)
                {
                    float d = map[x, z];

                    int y = fromY + (int)(d * (toY - fromY));

                    while (y >= fromY)
                    {
                        tileManager.SetTileType(new TilePosition(x, y--, z), tileType);
                    }
                }
            }

            return(true);
        }
コード例 #42
0
        private bool FreeSpaceAvailable(int x, int y, int z, int radius, int height, CubeWorld world)
        {
            TileManager tileManager = world.tileManager;

            for (int dx = x - radius; dx <= x + radius; dx++)
            {
                for (int dz = z - radius; dz <= z + radius; dz++)
                {
                    for (int dy = y; dy < y + height; dy++)
                    {
                        if (tileManager.GetTileType(new TilePosition(dx, dy, dz)) != TileDefinition.EMPTY_TILE_TYPE)
                        {
                            return(false);
                        }
                    }
                }
            }

            return(true);
        }
コード例 #43
0
        public override bool Generate(CubeWorld world)
        {
            int drops = generator.Next(minDropsRV.EvaluateInt(world), maxDropsRV.EvaluateInt(world));
			
			TileManager tileManager = world.tileManager;

            for (int i = 0; i < drops; i++)
            {
                int x = generator.Next(2, tileManager.sizeX - 2);
                int z = generator.Next(2, tileManager.sizeZ - 2);
                sidesToCheck = generator.Next(3, 10);

                int particles = generator.Next(minParticlesRV.EvaluateInt(world), maxParticlesRV.EvaluateInt(world));

                for (int j = 0; j < particles; j++)
                    DropParticle(x, z, world);
            }

            return true;
        }
コード例 #44
0
        public override bool Generate(CubeWorld world)
        {
            Random rnd = new Random();

			TileManager tileManager = world.tileManager;
			
            for (int x = 0; x < tileManager.sizeX; x++)
            {
                for (int z = 0; z < tileManager.sizeZ; z++)
                {
                    int y = tileManager.GetTopPosition(x, z);
                    TilePosition pos = new TilePosition(x, y, z);

                    if (tileManager.GetTileType(pos) == fromType && rnd.NextDouble() <= probability)
                        tileManager.SetTileType(pos, toType);
                }
            }

            return true;
        }
コード例 #45
0
        public override bool Generate(CubeWorld world)
        {
            int iterations = iterationsRV.EvaluateInt(world);
            int minRadius = minRadiusRV.EvaluateInt(world);
            int maxRadius = maxRadiusRV.EvaluateInt(world);
            int fromY = fromYRV.EvaluateInt(world);
            int toY = toYRV.EvaluateInt(world);
			
			TileManager tileManager = world.tileManager;

            Random random = new Random();

            for (int i = 0; i < iterations; i++)
            {
                int cx = random.Next(maxRadius + 1, tileManager.sizeX - maxRadius - 1);
                int cy = random.Next(maxRadius + 1, tileManager.sizeY - maxRadius - 1);
                int cz = random.Next(maxRadius + 1, tileManager.sizeZ - maxRadius - 1);

                int radiusX = random.Next(minRadius, maxRadius);
                int radiusY = random.Next(minRadius, maxRadius);
                int radiusZ = random.Next(minRadius, maxRadius);

                for (int x = cx - radiusX; x < cx + radiusX; x++)
                    for (int z = cz - radiusZ; z < cz + radiusZ; z++)
                        for (int y = cy - radiusY; y < cy + radiusY; y++)
                        {
                            if (y >= fromY && y < toY)
                            {
                                if (random.NextDouble() > 0.25)
                                {
                                    if (allowEmptyAbove || y == tileManager.sizeY || tileManager.GetTileType(new TilePosition(x, y + 1, z)) != TileDefinition.EMPTY_TILE_TYPE)
                                        if (tileManager.GetTileType(new TilePosition(x, y, z)) == overTile)
                                            tileManager.SetTileType(new TilePosition(x, y, z), tileType);
                                }
                            }
                        }
            }

            return true;
        }
コード例 #46
0
        public override bool Generate(CubeWorld world)
        {
            TileManager tileManager = world.tileManager;

            int fromY = fromYRV.EvaluateInt(world);
            int toY   = toYRV.EvaluateInt(world);

            //C3DPerlinNoise.Init();
            int seed = new Random().Next();

            int cutY = (int)(fromY + (toY - fromY) * 0.7f);

            for (int x = 0; x < tileManager.sizeX; x++)
            {
                for (int z = 0; z < tileManager.sizeZ; z++)
                {
                    float d = GetRandomHeight(x, z, 1.0f, freq, 1.0f, 0.5f, octaves, seed);

                    int y = (int)(fromY + d * (toY - fromY)) - 1;

                    if (y > cutY)
                    {
                        y = cutY;
                    }
                    else if (y < fromY - 1)
                    {
                        y = fromY - 1;
                    }

                    while (y >= fromY)
                    {
                        tileManager.SetTileType(new TilePosition(x, y--, z), tileType);
                    }
                }
            }

            NoiseInitialized = false;

            return(true);
        }
コード例 #47
0
        public override bool Generate(CubeWorld world)
        {
            int drops = generator.Next(minDropsRV.EvaluateInt(world), maxDropsRV.EvaluateInt(world));

            TileManager tileManager = world.tileManager;

            for (int i = 0; i < drops; i++)
            {
                int x = generator.Next(2, tileManager.sizeX - 2);
                int z = generator.Next(2, tileManager.sizeZ - 2);
                sidesToCheck = generator.Next(3, 10);

                int particles = generator.Next(minParticlesRV.EvaluateInt(world), maxParticlesRV.EvaluateInt(world));

                for (int j = 0; j < particles; j++)
                {
                    DropParticle(x, z, world);
                }
            }

            return(true);
        }
コード例 #48
0
        public override bool Generate(CubeWorld world)
        {
			TileManager tileManager = world.tileManager;

            int fromY = fromYRV.EvaluateInt(world);
            int toY = toYRV.EvaluateInt(world);

            width = tileManager.sizeX;
            height = tileManager.sizeZ;

            map = new float[width + 1, height + 1];

            //StartMidpointDisplacment();
            //Assign the four corners of the intial grid random color values
            //These will end up being the colors of the four corners of the applet.		

            float c1, c2, c3, c4;
            c1 = (float)rnd.NextDouble();
            c2 = (float)rnd.NextDouble();
            c3 = (float)rnd.NextDouble();
            c4 = (float)rnd.NextDouble();

            DivideGrid(0, 0, width, height, c1, c2, c3, c4);

            for (int x = 0; x < tileManager.sizeX; x++)
            {
                for (int z = 0; z < tileManager.sizeZ; z++)
                {
                    float d = map[x, z];

                    int y = fromY + (int)(d * (toY - fromY));

                    while (y >= fromY)
                        tileManager.SetTileType(new TilePosition(x, y--, z), tileType);
                }
            }

            return true;
        }
コード例 #49
0
        public override bool Generate(CubeWorld world)
        {
            Random rnd = new Random();

            TileManager tileManager = world.tileManager;

            for (int x = 0; x < tileManager.sizeX; x++)
            {
                for (int z = 0; z < tileManager.sizeZ; z++)
                {
                    int          y   = tileManager.GetTopPosition(x, z);
                    TilePosition pos = new TilePosition(x, y, z);

                    if (tileManager.GetTileType(pos) == fromType && rnd.NextDouble() <= probability)
                    {
                        tileManager.SetTileType(pos, toType);
                    }
                }
            }

            return(true);
        }
コード例 #50
0
        private void PlantTree(int x, int z, CubeWorld world)
        {
			TileManager tileManager = world.tileManager;
			
			int topY = tileManager.GetTopPosition(x, z);

            if (topY < tileManager.sizeY - (maxTrunkHeight + maxLeavesHeight) * 2)
            {
                if (tileManager.GetTileType(new TilePosition(x, topY, z)) == overTileType)
                {
                    topY++;

                    int trunkHeight = generator.Next(minTrunkHeight, maxTrunkHeight + 1);
                    int leavesHeight = generator.Next(minLeavesHeight, maxLeavesHeight + 1);
                    int leavesRadius = generator.Next(minLeavesRadius, maxLeavesRadius + 1);

                    int treeHeight = trunkHeight + leavesHeight;

                    if (FreeSpaceAvailable(x, topY, z, leavesRadius, treeHeight, world))
                        CreateTree(x, topY, z, trunkHeight, leavesHeight, leavesRadius, world);
                }
            }
        }
コード例 #51
0
        private void CreateBasicLevels(CubeWorld world)
        {
            for (int level = 0; level < world.sizeY / LEVEL_HEIGHT; level++)
            {
                CreateLevel(world, level);
            }

            //Create ceiling
            for (int x = 0; x < world.sizeX; x++)
            {
                for (int z = 0; z < world.sizeZ; z++)
                {
                    if (x % 3 == 0 && z % 3 == 0)
                    {
                        world.tileManager.SetTileType(new TilePosition(x, world.sizeY - 1, z), tileTypeCeilingGlass);
                    }
                    else
                    {
                        world.tileManager.SetTileType(new TilePosition(x, world.sizeY - 1, z), tileTypeHardRock);
                    }
                }
            }
        }
コード例 #52
0
        private void CreateLevel(CubeWorld world, int level)
        {
            int floor_y = level * LEVEL_HEIGHT;
            int ceiling_y = level * (LEVEL_HEIGHT + 1);

            //Create floor
            for (int x = 0; x < world.sizeX; x++)
                for (int z = 0; z < world.sizeZ; z++)
                    world.tileManager.SetTileType(new TilePosition(x, floor_y, z), tileTypeHardRock);

            //Create walls
            for (int y = floor_y; y < ceiling_y; y++)
                for (int z = 0; z < world.sizeZ; z++)
                {
                    world.tileManager.SetTileType(new TilePosition(0, y, z), tileTypeHardRock);
                    world.tileManager.SetTileType(new TilePosition(world.sizeX - 1, y, z), tileTypeHardRock);
                }
            for (int y = floor_y; y < ceiling_y; y++)
                for (int x = 0; x < world.sizeX; x++)
                {
                    world.tileManager.SetTileType(new TilePosition(x, y, 0), tileTypeHardRock);
                    world.tileManager.SetTileType(new TilePosition(x, y, world.sizeZ - 1), tileTypeHardRock);
                }
        }
コード例 #53
0
        public override bool Generate(CubeWorld world)
        {
            int fromY = fromYRV.EvaluateInt(world);
            int toY   = toYRV.EvaluateInt(world);

            TileManager tileManager = world.tileManager;

            for (int x = 0; x < tileManager.sizeX; x++)
            {
                for (int z = 0; z < tileManager.sizeZ; z++)
                {
                    for (int y = fromY; y < toY; y++)
                    {
                        TilePosition pos = new TilePosition(x, y, z);
                        if (tileManager.GetTileType(pos) == TileDefinition.EMPTY_TILE_TYPE)
                        {
                            tileManager.SetTileType(pos, tileType);
                        }
                    }
                }
            }

            return(true);
        }
コード例 #54
0
 public SectorManager(CubeWorld.World.CubeWorld world)
 {
     this.world = world;
 }
コード例 #55
0
 public virtual bool Generate(CubeWorld world)
 {
     return true;
 }
コード例 #56
0
ファイル: Sector.cs プロジェクト: carriercomm/CubeWorld
 public Sector(CubeWorld.World.CubeWorld world, TilePosition sectorPosition, TilePosition tileOffset)
 {
     this.world = world;
     this.tileOffset = tileOffset;
     this.sectorPosition = sectorPosition;
 }
コード例 #57
0
 public override void FillPlayerInventory(CubeWorld.Items.Inventory inventory)
 {
     baseGameplay.FillPlayerInventory(inventory);
 }
コード例 #58
0
ファイル: BaseGameplay.cs プロジェクト: carriercomm/CubeWorld
 public virtual void Init(CubeWorld.World.CubeWorld world)
 {
     this.world = world;
 }
コード例 #59
0
        public override bool Generate(CubeWorld world)
        {
            int iterations = iterationsRV.EvaluateInt(world);
            int minRadius = minRadiusRV.EvaluateInt(world);
            int maxRadius = maxRadiusRV.EvaluateInt(world);
            int fromY = fromYRV.EvaluateInt(world); 
            int toY = toYRV.EvaluateInt(world);
			
			TileManager tileManager = world.tileManager;

            Random random = new Random();

            for (int i = 0; i < iterations; i++)
            {
                TilePosition center = new TilePosition(
                    random.Next(maxRadius + 1, world.sizeX - maxRadius - 1),
                    random.Next(fromY, toY),
                    random.Next(maxRadius + 1, world.sizeZ - maxRadius - 1));

                TilePosition radius = new TilePosition(
                    random.Next(minRadius, maxRadius),
                    random.Next(minRadius, maxRadius),
                    random.Next(minRadius, maxRadius));

                TilePosition position = new TilePosition();

                int axis = random.Next(3);

                for (int a1 = center[axis] - radius[axis]; a1 <= center[axis] + radius[axis]; a1++)
                {
                    position[axis] = a1;

                    int axis2 = (axis + random.Next(2) + 1) % 3;
                    int axis3;
                    if (axis == 0 && axis2 == 2 || axis == 2 && axis2 == 0)
                        axis3 = 1;
                    else if (axis == 0 && axis2 == 1 || axis == 1 && axis2 == 0)
                        axis3 = 2;
                    else
                        axis3 = 0;

                    radius[axis2] += random.Next(5) - 2;

                    if (radius[axis2] < minRadius)
                        radius[axis2] = minRadius;
                    else if (radius[axis2] > maxRadius)
                        radius[axis2] = maxRadius;

                    for (int a2 = center[axis2] - radius[axis2]; a2 <= center[axis2] + radius[axis2]; a2++)
                    {
                        position[axis2] = a2;

                        radius[axis3] += random.Next(5) - 2;

                        if (radius[axis3] < minRadius)
                            radius[axis3] = minRadius;
                        else if (radius[axis3] > maxRadius)
                            radius[axis3] = maxRadius;

                        for (int a3 = center[axis3] - radius[axis3]; a3 <= center[axis3] + radius[axis3]; a3++)
                        {
                            position[axis3] = a3;

                            if (position[1] < fromY)
                                position[1] = fromY;
                            else if (position[1] > toY)
                                position[1] = toY;

                            tileManager.SetTileType(position, 0);
                        }
                    }
                }
            }

            return true;
        }
コード例 #60
0
        private void CreateTree(int treeX, int treeY, int treeZ, int trunkHeight, int leavesHeight, int leavesRadius, CubeWorld world)
        {
            TileManager tileManager = world.tileManager;

            int minX = treeX - leavesRadius;
            int maxX = treeX + leavesRadius;

            int minZ = treeZ - leavesRadius;
            int maxZ = treeZ + leavesRadius;

            int minY = treeY + trunkHeight;
            int maxY = treeY + trunkHeight + leavesHeight;

            //Leaves
            for (int y = minY; y < maxY; y++)
            {
                for (int x = minX; x <= maxX; x++)
                {
                    for (int z = minZ; z <= maxZ; z++)
                    {
                        tileManager.SetTileType(new TilePosition(x, y, z), tileTypeLeaves);
                    }
                }
            }

            //Remove extreme leaves
            tileManager.SetTileType(new TilePosition(minX, minY, minZ), 0);
            tileManager.SetTileType(new TilePosition(minX, minY, maxZ), 0);
            tileManager.SetTileType(new TilePosition(maxX, minY, maxZ), 0);
            tileManager.SetTileType(new TilePosition(maxX, minY, minZ), 0);
            tileManager.SetTileType(new TilePosition(minX, maxY - 1, minZ), 0);
            tileManager.SetTileType(new TilePosition(minX, maxY - 1, maxZ), 0);
            tileManager.SetTileType(new TilePosition(maxX, maxY - 1, maxZ), 0);
            tileManager.SetTileType(new TilePosition(maxX, maxY - 1, minZ), 0);

            //Trunk
            for (int y = treeY; y < treeY + trunkHeight + leavesHeight / 2; y++)
            {
                tileManager.SetTileType(new TilePosition(treeX, y, treeZ), tileTypeTrunk);
            }
        }