Esempio n. 1
0
        public virtual void Spawn(int health, Cord pos = null)
        {
            this.health = health;
            Spawned     = true;
            if (pos == null || pos == new Cord(0, 0, 0))
            {
                Room room = Program.server.MainGame.map.rooms [rand.Next(0, Program.server.MainGame.map.rooms.Count - 1)];                  //Get a random spawn room.
                position = new Cord(room.getCenter().x, room.getCenter().y, room.getCenter().z);
            }
            else
            {
                position = pos;
            }

            Logger.LogMsg("Spawned a " + name + " at " + position, 2);
        }
Esempio n. 2
0
        public void Generate()
        {
            Random rand = new Random ();
            //Set all tiles to soild
            for (int z = 0; z < worldmap.GetLength(2); z++) {
                for (int x = 0; x < worldmap.GetLength(0); x++) {
                    for (int y = 0; y < worldmap.GetLength(1); y++) {
                        worldmap [x, y, z] = '#';
                    }
                }

                //Create rooms
                for (int r = 0; r < rand.Next(150,300); r++) {
                    int width = rand.Next (3, 15), height = rand.Next (3, 10);
                    int cx = 0, cy = 0;
                    bool failed = true;
                    while (failed) {
                        while ((cx - width) < 25 || (cx + width) > 486 || (cy - height) < 25 || (cy + height) > 486) {
                            cx = rand.Next (0, 511);
                            cy = rand.Next (0, 511);
                        }

                        Room potential = new Room(new Cord (cx, cy, z), width, height);
                        if(r == 0){failed = false; };
                        foreach (Room room in rooms) {
                            if (!potential.Intersects (room))
                                failed = false;
                        }

                    }
                    Room newRoom = new Room(new Cord (cx, cy, z), width, height);

                    if (rooms.Count () > 1) {
                        //Create a tunnel.
                        Room[] selectedr = FindNearestRooms(newRoom,Consts.MAX_TUNNEL_DIST);
                        Room oldRoom;
                        if(selectedr.Count() > 0)
                        {
                            int roomid = rand.Next(1,selectedr.Count()) - 1;
                            oldRoom = rooms[rooms.IndexOf(selectedr[roomid])];

                            Cord oldCord = oldRoom.getCenter();
                            Cord newCord = newRoom.getCenter();

                            int minx = Math.Min(newCord.x,oldCord.x);
                            int maxx = Math.Max(newCord.x,oldCord.x);

                            int miny = Math.Min(newCord.y,oldCord.y);
                            int maxy = Math.Max(newCord.y,oldCord.y);

                            int oldy = oldCord.y;
                            int oldx = oldCord.x;

                            //Horizontal tunnel.
                            for(int x = minx; x < maxx; x++) {
                                worldmap[x,oldy,z] = '.';
                            }
                            //Vertical tunnel.
                            for(int y = miny; y < maxy; y++) {
                                worldmap[oldx,y,z] = '.';
                            }
                        }
                    }
                    ApplyRoom(newRoom);
                    rooms.Add(newRoom);
                }
            }
        }
Esempio n. 3
0
        public void Generate()
        {
            Random rand = new Random();

            //Set all tiles to soild
            for (int z = 0; z < worldmap.GetLength(2); z++)
            {
                for (int x = 0; x < worldmap.GetLength(0); x++)
                {
                    for (int y = 0; y < worldmap.GetLength(1); y++)
                    {
                        worldmap [x, y, z] = '#';
                    }
                }

                //Create rooms
                for (int r = 0; r < rand.Next(150, 300); r++)
                {
                    int  width = rand.Next(3, 15), height = rand.Next(3, 10);
                    int  cx = 0, cy = 0;
                    bool failed = true;
                    while (failed)
                    {
                        while ((cx - width) < 25 || (cx + width) > 486 || (cy - height) < 25 || (cy + height) > 486)
                        {
                            cx = rand.Next(0, 511);
                            cy = rand.Next(0, 511);
                        }

                        Room potential = new Room(new Cord(cx, cy, z), width, height);
                        if (r == 0)
                        {
                            failed = false;
                        }
                        ;
                        foreach (Room room in rooms)
                        {
                            if (!potential.Intersects(room))
                            {
                                failed = false;
                            }
                        }
                    }
                    Room newRoom = new Room(new Cord(cx, cy, z), width, height);


                    if (rooms.Count() > 1)
                    {
                        //Create a tunnel.
                        Room[] selectedr = FindNearestRooms(newRoom, Consts.MAX_TUNNEL_DIST);
                        Room   oldRoom;
                        if (selectedr.Count() > 0)
                        {
                            int roomid = rand.Next(1, selectedr.Count()) - 1;
                            oldRoom = rooms[rooms.IndexOf(selectedr[roomid])];

                            Cord oldCord = oldRoom.getCenter();
                            Cord newCord = newRoom.getCenter();

                            int minx = Math.Min(newCord.x, oldCord.x);
                            int maxx = Math.Max(newCord.x, oldCord.x);

                            int miny = Math.Min(newCord.y, oldCord.y);
                            int maxy = Math.Max(newCord.y, oldCord.y);

                            int oldy = oldCord.y;
                            int oldx = oldCord.x;

                            //Horizontal tunnel.
                            for (int x = minx; x < maxx; x++)
                            {
                                worldmap[x, oldy, z] = '.';
                            }
                            //Vertical tunnel.
                            for (int y = miny; y < maxy; y++)
                            {
                                worldmap[oldx, y, z] = '.';
                            }
                        }
                    }
                    ApplyRoom(newRoom);
                    rooms.Add(newRoom);
                }
            }
        }