Ejemplo n.º 1
0
        public void PerformAction(Vector3 position, World gameWorld, PrefabChunk prefab, int selectedSpawn, int spawnRot)
        {
            // Need to make it so voxels have a type and then we can check if tree so we don't put trees on top of trees yo

            Vector2 center = new Vector2(position.X, position.Y);

            switch (Mode)
            {
            case CursorMode.LandScape:
                for (int x = 0; x < 32; x++)
                {
                    for (int y = 0; y < 32; y++)
                    {
                        for (int z = Chunk.Z_SIZE - 1; z >= 0; z--)
                        {
                            if (Voxels[x, y, 0].Active)
                            {
                                gameWorld.SetVoxel(((int)center.X - 16) + x, ((int)center.Y - 16) + y, z, z >= Chunk.Z_SIZE - Height, 0, VoxelType.Ground, gameWorld.ThemeTopColor(Theme), gameWorld.ThemeSideColor(Theme));
                            }
                        }
                    }
                }



                break;

            case CursorMode.Trees:
                int numTrees = 1 + (Size / 2);
                for (int i = 0; i < numTrees; i++)
                {
                    Vector2 pos = Helper.RandomPointInCircle(new Vector2(position.X, position.Y), 0f, Size);

                    //int z = 0;
                    //for (int zz = 0; zz < Chunk.Z_SIZE; zz++) if (gameWorld.GetVoxel((int)Position.X, (int)Position.Y, zz).Active) { z = zz - 1; break; }

                    gameWorld.MakeTree((int)pos.X, (int)pos.Y, (int)position.Z);
                }

                //for (float a = 0f; a < MathHelper.TwoPi; a += 0.05f)
                //{
                //    for (int r = 0; r < Size; r++)
                //    {
                //        Vector3 pos = new Vector3(Helper.PointOnCircle(ref center, r, a), 0f);
                //        gameWorld.MakeTree((int)pos.X, (int)pos.Y, (int)Position.Z);
                //    }
                //}
                break;

            case CursorMode.Water:
                for (int x = 0; x < 32; x++)
                {
                    for (int y = 0; y < 32; y++)
                    {
                        for (int z = Chunk.Z_SIZE - 1; z >= 0; z--)
                        {
                            if (Voxels[x, y, 0].Active)
                            {
                                gameWorld.SetVoxel(((int)center.X - 16) + x, ((int)center.Y - 16) + y, z, z >= Chunk.Z_SIZE - (Height - 1), 0, VoxelType.Water, new Color(0.1f, 0.1f, 0.8f + ((float)Helper.Random.NextDouble() * 0.1f)) * 0.8f, new Color(0.3f, 0.3f, 0.8f + ((float)Helper.Random.NextDouble() * 0.1f)) * 0.8f);
                            }
                        }
                    }
                }

                break;

            case CursorMode.Prefab:
                int startX = (int)position.X - (prefab.X_SIZE / 2);
                int startY = (int)position.Y - (prefab.Y_SIZE / 2);
                int startZ = (Chunk.Z_SIZE - Height) - (prefab.Z_SIZE);
                for (int x = 0; x < prefab.X_SIZE; x++)
                {
                    for (int y = 0; y < prefab.Y_SIZE; y++)
                    {
                        for (int z = 0; z < prefab.Z_SIZE; z++)
                        {
                            if (prefab.Voxels[x, y, z].Active)
                            {
                                gameWorld.SetVoxel(startX + x, startY + y, startZ + z, true, destructable, VoxelType.Prefab, new Color(prefab.Voxels[x, y, z].TR, prefab.Voxels[x, y, z].TG, prefab.Voxels[x, y, z].TB), new Color(prefab.Voxels[x, y, z].SR, prefab.Voxels[x, y, z].SG, prefab.Voxels[x, y, z].SB));
                            }
                        }
                    }
                }

                break;

            case CursorMode.Spawn:
                bool found = false;
                for (int i = gameWorld.Spawns.Count - 1; i >= 0; i--)
                {
                    if (gameWorld.Spawns[i].Position == position)
                    {
                        found = true;
                        gameWorld.Spawns.RemoveAt(i);
                    }
                }
                if (!found)
                {
                    gameWorld.Spawns.Add(new Spawn()
                    {
                        Position = position,
                        Rotation = (byte)spawnRot,
                        Type     = (SpawnType)selectedSpawn,
                    });
                }
                break;
            }
        }
Ejemplo n.º 2
0
        public void PerformAction(Vector3 position, World gameWorld, PrefabChunk prefab, int selectedSpawn, int spawnRot)
        {
            // Need to make it so voxels have a type and then we can check if tree so we don't put trees on top of trees yo

            Vector2 center = new Vector2(position.X, position.Y);

            switch (Mode)
            {
                case CursorMode.LandScape:
                    for (int x = 0; x < 32; x++)
                        for (int y = 0; y < 32; y++)
                            for (int z = Chunk.Z_SIZE - 1; z >= 0; z--)
                            {
                                if(Voxels[x,y,0].Active)
                                    gameWorld.SetVoxel(((int)center.X - 16) + x, ((int)center.Y - 16) + y, z, z >= Chunk.Z_SIZE - Height, 0, VoxelType.Ground, gameWorld.ThemeTopColor(Theme), gameWorld.ThemeSideColor(Theme));
                            }

                    break;

                case CursorMode.Trees:
                    int numTrees = 1 +(Size / 2);
                    for (int i = 0; i < numTrees; i++)
                    {
                        Vector2 pos = Helper.RandomPointInCircle(new Vector2(position.X,position.Y), 0f, Size);

                        //int z = 0;
                        //for (int zz = 0; zz < Chunk.Z_SIZE; zz++) if (gameWorld.GetVoxel((int)Position.X, (int)Position.Y, zz).Active) { z = zz - 1; break; }

                        gameWorld.MakeTree((int)pos.X, (int)pos.Y, (int)position.Z);
                    }

                    //for (float a = 0f; a < MathHelper.TwoPi; a += 0.05f)
                    //{
                    //    for (int r = 0; r < Size; r++)
                    //    {
                    //        Vector3 pos = new Vector3(Helper.PointOnCircle(ref center, r, a), 0f);
                    //        gameWorld.MakeTree((int)pos.X, (int)pos.Y, (int)Position.Z);
                    //    }
                    //}
                    break;
                case CursorMode.Water:
                    for (int x = 0; x < 32; x++)
                        for (int y = 0; y < 32; y++)
                            for (int z = Chunk.Z_SIZE - 1; z >= 0; z--)
                            {
                                if(Voxels[x,y,0].Active)
                                    gameWorld.SetVoxel(((int)center.X - 16) + x, ((int)center.Y - 16) + y, z, z >= Chunk.Z_SIZE - (Height - 1), 0, VoxelType.Water, new Color(0.1f, 0.1f, 0.8f + ((float)Helper.Random.NextDouble() * 0.1f)) * 0.8f, new Color(0.3f, 0.3f, 0.8f + ((float)Helper.Random.NextDouble() * 0.1f)) * 0.8f);
                            }

                    break;
                case CursorMode.Prefab:
                    int startX = (int)position.X - (prefab.X_SIZE/2);
                    int startY = (int)position.Y - (prefab.Y_SIZE/2);
                    int startZ = (Chunk.Z_SIZE - Height) - (prefab.Z_SIZE);
                    for (int x = 0; x < prefab.X_SIZE; x++)
                    {
                        for (int y = 0; y < prefab.Y_SIZE; y++)
                        {
                            for (int z = 0; z < prefab.Z_SIZE; z++)
                            {
                                if (prefab.Voxels[x, y, z].Active)
                                {
                                    gameWorld.SetVoxel(startX + x, startY + y, startZ + z, true, destructable, VoxelType.Prefab, new Color(prefab.Voxels[x, y, z].TR, prefab.Voxels[x, y, z].TG, prefab.Voxels[x, y, z].TB), new Color(prefab.Voxels[x, y, z].SR, prefab.Voxels[x, y, z].SG, prefab.Voxels[x, y, z].SB));
                                }
                            }
                        }
                    }

                    break;
                case CursorMode.Spawn:
                    bool found = false;
                    for (int i = gameWorld.Spawns.Count - 1; i >= 0; i--)
                    {
                        if (gameWorld.Spawns[i].Position == position)
                        {
                            found = true;
                            gameWorld.Spawns.RemoveAt(i);
                        }
                    }
                    if (!found)
                    {
                        gameWorld.Spawns.Add(new Spawn()
                        {
                            Position = position,
                            Rotation = (byte)spawnRot,
                            Type = (SpawnType)selectedSpawn,
                        });
                    }
                    break;
            }
        }