Пример #1
0
        void CreateMap(VoxelSprite tileSheet)
        {
            for (int x = 0; x < 15; x++)
            {
                for (int y = 0; y < 9; y++)
                {
                    wallRots[x, y] = MathHelper.PiOver2 * (float)Helper.Random.Next(4);
                    if (x == 0 || x == 14 || y == 0 || y == 8)
                    {
                        if (x != 7 && y != 4)
                        {
                            World.CopySprite(x * Chunk.X_SIZE, y * Chunk.X_SIZE, 14, tileSheet.AnimChunks[0], Helper.Random.Next(4), 0);
                        }
                        else
                        {
                            World.CopySprite(x * Chunk.X_SIZE, y * Chunk.X_SIZE, 14, tileSheet.AnimChunks[(x == 7 ? 2 : 1)], 0, 0);
                        }
                    }
                }
            }



            for (int i = 0; i < 3; i++)
            {
                int rx = 1 + Helper.Random.Next(6);
                int ry = 1 + Helper.Random.Next(3);

                int t = 6 + Helper.Random.Next(1);

                World.CopySprite(rx * Chunk.X_SIZE, ry * Chunk.X_SIZE, 14, tileSheet.AnimChunks[t], 0, 1);
                World.CopySprite((14 - rx) * Chunk.X_SIZE, ry * Chunk.X_SIZE, 14, tileSheet.AnimChunks[t], 0, 1);
                World.CopySprite(rx * Chunk.X_SIZE, (8 - ry) * Chunk.X_SIZE, 14, tileSheet.AnimChunks[t], 0, 1);
                World.CopySprite((14 - rx) * Chunk.X_SIZE, (8 - ry) * Chunk.X_SIZE, 14, tileSheet.AnimChunks[t], 0, 1);

                if (Helper.Random.Next(5) == 1)
                {
                    PickupController.Instance.Spawn(PickupType.Health, this, VoxelWorld.ToScreenSpace((rx * Chunk.X_SIZE) + (Chunk.X_SIZE / 2), (ry * Chunk.Y_SIZE) + (Chunk.Y_SIZE / 2), 21));
                }
                if (Helper.Random.Next(5) == 1)
                {
                    PickupController.Instance.Spawn(PickupType.Health, this, VoxelWorld.ToScreenSpace(((14 - rx) * Chunk.X_SIZE) + (Chunk.X_SIZE / 2), (ry * Chunk.Y_SIZE) + (Chunk.Y_SIZE / 2), 21));
                }
                if (Helper.Random.Next(5) == 1)
                {
                    PickupController.Instance.Spawn(PickupType.Health, this, VoxelWorld.ToScreenSpace((rx * Chunk.X_SIZE) + (Chunk.X_SIZE / 2), ((8 - ry) * Chunk.Y_SIZE) + (Chunk.Y_SIZE / 2), 21));
                }
                if (Helper.Random.Next(5) == 1)
                {
                    PickupController.Instance.Spawn(PickupType.Health, this, VoxelWorld.ToScreenSpace(((14 - rx) * Chunk.X_SIZE) + (Chunk.X_SIZE / 2), ((8 - ry) * Chunk.Y_SIZE) + (Chunk.Y_SIZE / 2), 21));
                }
            }

            for (int i = 0; i < 1; i++)
            {
                int rx = 2 + Helper.Random.Next(5);
                int t  = 4 + Helper.Random.Next(3);

                World.CopySprite(rx * Chunk.X_SIZE, 4 * Chunk.X_SIZE, 14, tileSheet.AnimChunks[t], 0, 1);
                World.CopySprite((14 - rx) * Chunk.X_SIZE, 4 * Chunk.X_SIZE, 14, tileSheet.AnimChunks[t], 0, 1);
            }
            for (int i = 0; i < 1; i++)
            {
                int ry = 2 + Helper.Random.Next(2);
                int t  = 4 + Helper.Random.Next(3);

                World.CopySprite(7 * Chunk.X_SIZE, ry * Chunk.X_SIZE, 14, tileSheet.AnimChunks[t], 0, 1);
                World.CopySprite(7 * Chunk.X_SIZE, (8 - ry) * Chunk.X_SIZE, 14, tileSheet.AnimChunks[t], 0, 1);
            }

            //if (!((rx == 1 || rx == 14) && ry == 4) && !((ry == 1 || ry == 8) && rx == 7))
            //{

            //    World.CopySprite(rx * Chunk.X_SIZE, ry * Chunk.X_SIZE, 14, tileSheet.AnimChunks[3], 0);

            //}

            int  enemiesSpawned = 0;
            bool headSpawned    = false;
            bool oozeSpawned    = false;
            int  numEnemies     = 0 + Helper.Random.Next(6);

            while (enemiesSpawned < numEnemies)
            {
                for (int x = 1; x < 14; x++)
                {
                    for (int y = 1; y < 8; y++)
                    {
                        if (!World.GetVoxel((x * Chunk.X_SIZE) + (Chunk.X_SIZE / 2), (y * Chunk.Y_SIZE) + (Chunk.Y_SIZE / 2), 23).Active)
                        {
                            // Create an enemy?
                            if (!(x == 7 && y == 4))
                            {
                                if (enemiesSpawned < numEnemies && Helper.Random.Next(50) == 1)
                                {
                                    EnemyType type = (EnemyType)Helper.Random.Next(Enum.GetValues(typeof(EnemyType)).Length);
                                    if (type != EnemyType.Head)
                                    {
                                        if (type == EnemyType.Ooze && oozeSpawned)
                                        {
                                            continue;
                                        }
                                        if (type == EnemyType.Ooze)
                                        {
                                            oozeSpawned = true;
                                        }

                                        EnemyController.Instance.Spawn(type, VoxelWorld.ToScreenSpace((x * Chunk.X_SIZE) + (Chunk.X_SIZE / 2), (y * Chunk.Y_SIZE) + (Chunk.Y_SIZE / 2), 21), this);
                                        enemiesSpawned++;
                                    }
                                }
                            }
                            if (x == 7 && y == 4)
                            {
                                if (enemiesSpawned < numEnemies && !headSpawned && Helper.Random.Next(5) == 1)
                                {
                                    enemiesSpawned++;
                                    EnemyController.Instance.Spawn(EnemyType.Head, VoxelWorld.ToScreenSpace((x * Chunk.X_SIZE) + (Chunk.X_SIZE / 2), (y * Chunk.Y_SIZE) + (Chunk.Y_SIZE / 2), 21), this);
                                    headSpawned = true;
                                }
                            }
                        }
                    }
                }
            }

            World.UpdateWorldMeshes();
        }
Пример #2
0
        void CreateMap(VoxelSprite tileSheet)
        {
            for (int x = 0; x < 15; x++)
            {
                for (int y = 0; y < 9; y++)
                {
                    wallRots[x, y] = MathHelper.PiOver2 * (float)Helper.Random.Next(4);
                    if (x == 0 || x == 14 || y == 0 || y == 8)
                    {
                        if (x != 7 && y != 4)
                        {
                            World.CopySprite(x * Chunk.X_SIZE, y * Chunk.X_SIZE, 14, tileSheet.AnimChunks[0], Helper.Random.Next(4), 0);
                        }
                        else
                        {
                            World.CopySprite(x * Chunk.X_SIZE, y * Chunk.X_SIZE, 14, tileSheet.AnimChunks[(x == 7 ? 2 : 1)], 0, 0);
                        }
                    }
                }
            }



            for (int i = 0; i < 3; i++)
            {
                int rx = 1 + Helper.Random.Next(6);
                int ry = 1 + Helper.Random.Next(3);

                int t = 6 + Helper.Random.Next(1);

                World.CopySprite(rx * Chunk.X_SIZE, ry * Chunk.X_SIZE, 14, tileSheet.AnimChunks[t], 0, 1);
                World.CopySprite((14 - rx) * Chunk.X_SIZE, ry * Chunk.X_SIZE, 14, tileSheet.AnimChunks[t], 0, 1);
                World.CopySprite(rx * Chunk.X_SIZE, (8 - ry) * Chunk.X_SIZE, 14, tileSheet.AnimChunks[t], 0, 1);
                World.CopySprite((14 - rx) * Chunk.X_SIZE, (8 - ry) * Chunk.X_SIZE, 14, tileSheet.AnimChunks[t], 0, 1);
            }

            for (int i = 0; i < 1; i++)
            {
                int rx = 2 + Helper.Random.Next(5);
                int t  = 4 + Helper.Random.Next(3);

                World.CopySprite(rx * Chunk.X_SIZE, 4 * Chunk.X_SIZE, 14, tileSheet.AnimChunks[t], 0, 1);
                World.CopySprite((14 - rx) * Chunk.X_SIZE, 4 * Chunk.X_SIZE, 14, tileSheet.AnimChunks[t], 0, 1);
            }
            for (int i = 0; i < 1; i++)
            {
                int ry = 2 + Helper.Random.Next(2);
                int t  = 4 + Helper.Random.Next(3);

                World.CopySprite(7 * Chunk.X_SIZE, ry * Chunk.X_SIZE, 14, tileSheet.AnimChunks[t], 0, 1);
                World.CopySprite(7 * Chunk.X_SIZE, (8 - ry) * Chunk.X_SIZE, 14, tileSheet.AnimChunks[t], 0, 1);
            }

            //if (!((rx == 1 || rx == 14) && ry == 4) && !((ry == 1 || ry == 8) && rx == 7))
            //{

            //    World.CopySprite(rx * Chunk.X_SIZE, ry * Chunk.X_SIZE, 14, tileSheet.AnimChunks[3], 0);

            //}

            int enemiesSpawned = 0;

            for (int x = 1; x < 14; x++)
            {
                for (int y = 1; y < 8; y++)
                {
                    if (!World.GetVoxel((x * Chunk.X_SIZE) + (Chunk.X_SIZE / 2), (y * Chunk.Y_SIZE) + (Chunk.Y_SIZE / 2), 21).Active)
                    {
                        // Create an enemy?
                        if (enemiesSpawned < 4 && Helper.Random.Next(50) == 1)
                        {
                            enemiesSpawned++;

                            EnemyType type = (EnemyType)Helper.Random.Next(Enum.GetValues(typeof(EnemyType)).Length);
                            EnemyController.Instance.Spawn(type, VoxelWorld.ToScreenSpace((x * Chunk.X_SIZE) + (Chunk.X_SIZE / 2), (y * Chunk.Y_SIZE) + (Chunk.Y_SIZE / 2), 21), this);
                        }
                    }
                }
            }

            World.UpdateWorldMeshes();
        }
Пример #3
0
        public static void LoadWorld(string fn, ref VoxelWorld gameWorld)
        {
            byte[] buffer;

            using (FileStream gstr = new FileStream(fn, FileMode.Open))
            {
                byte[] lb = new byte[4];
                gstr.Position = gstr.Length - 4;
                gstr.Read(lb, 0,4);
                int msgLength = BitConverter.ToInt32(lb, 0);

                buffer = new byte[msgLength];

                gstr.Position = 0;

                using (GZipStream str = new GZipStream(gstr, CompressionMode.Decompress))
                {

                    str.Read(buffer, 0, msgLength);
                }
            }

            int pos = 0;

            int xs = buffer[0];
            int ys = buffer[1];
            int zs = buffer[2];
            gameWorld = new VoxelWorld(xs, ys, zs, false);

            pos = 3;

            for (int z = 0; z < gameWorld.Z_CHUNKS; z++)
            {
                for (int y = 0; y < gameWorld.Y_CHUNKS; y++)
                {
                    for (int x = 0; x < gameWorld.X_CHUNKS; x++)
                    {
                        Chunk c = gameWorld.Chunks[x, y, z];

                        while (pos < buffer.Length)
                        {
                            if (Convert.ToChar(buffer[pos]) != 'c')
                            {
                                int vx = buffer[pos];
                                int vy = buffer[pos + 1];
                                int vz = buffer[pos + 2];
                                VoxelType type = (VoxelType)buffer[pos + 3];
                                byte destruct = buffer[pos + 4];
                                Color top = new Color(buffer[pos + 5], buffer[pos + 6], buffer[pos + 7]);
                                Color side = new Color(buffer[pos + 8], buffer[pos + 9], buffer[pos + 10]);

                                c.SetVoxel(vx, vy, vz, true, destruct, type, top, side);
                                pos += 11;
                            }
                            else
                            {
                                pos++;
                                break;
                            }

                        }
                    }
                }

            }

            gameWorld.UpdateWorldMeshes();

            GC.Collect();
        }
Пример #4
0
        public static void LoadWorld(string fn, ref VoxelWorld gameWorld)
        {
            byte[] buffer;

            using (FileStream gstr = new FileStream(fn, FileMode.Open))
            {
                byte[] lb = new byte[4];
                gstr.Position = gstr.Length - 4;
                gstr.Read(lb, 0, 4);
                int msgLength = BitConverter.ToInt32(lb, 0);

                buffer = new byte[msgLength];

                gstr.Position = 0;

                using (GZipStream str = new GZipStream(gstr, CompressionMode.Decompress))
                {
                    str.Read(buffer, 0, msgLength);
                }
            }

            int pos = 0;

            int xs = buffer[0];
            int ys = buffer[1];
            int zs = buffer[2];

            gameWorld = new VoxelWorld(xs, ys, zs, false);

            pos = 3;

            for (int z = 0; z < gameWorld.Z_CHUNKS; z++)
            {
                for (int y = 0; y < gameWorld.Y_CHUNKS; y++)
                {
                    for (int x = 0; x < gameWorld.X_CHUNKS; x++)
                    {
                        Chunk c = gameWorld.Chunks[x, y, z];

                        while (pos < buffer.Length)
                        {
                            if (Convert.ToChar(buffer[pos]) != 'c')
                            {
                                int       vx       = buffer[pos];
                                int       vy       = buffer[pos + 1];
                                int       vz       = buffer[pos + 2];
                                VoxelType type     = (VoxelType)buffer[pos + 3];
                                byte      destruct = buffer[pos + 4];
                                Color     top      = new Color(buffer[pos + 5], buffer[pos + 6], buffer[pos + 7]);
                                Color     side     = new Color(buffer[pos + 8], buffer[pos + 9], buffer[pos + 10]);

                                c.SetVoxel(vx, vy, vz, true, destruct, type, top, side);
                                pos += 11;
                            }
                            else
                            {
                                pos++;
                                break;
                            }
                        }
                    }
                }
            }

            gameWorld.UpdateWorldMeshes();

            GC.Collect();
        }