Ejemplo n.º 1
0
        public static int Distance(Cord c1, Cord c2)
        {
            int width = Math.Max(c1.x,c2.x) - Math.Min(c1.x,c2.x);
            int height = Math.Max(c1.y,c2.y) - Math.Min(c1.y,c2.y);

            return (int)Math.Sqrt(Math.Pow(width,2) + Math.Pow(height,2));
        }
Ejemplo n.º 2
0
        public static int Distance(Cord c1, Cord c2)
        {
            int width  = Math.Max(c1.x, c2.x) - Math.Min(c1.x, c2.x);
            int height = Math.Max(c1.y, c2.y) - Math.Min(c1.y, c2.y);

            return((int)Math.Sqrt(Math.Pow(width, 2) + Math.Pow(height, 2)));
        }
Ejemplo n.º 3
0
        public int IsTouching(Cord pos, char type)
        {
            int touches = 0;

            if (worldmap [pos.x - 1, pos.y, pos.z] == type)
            {
                touches++;
            }             // Left

            if (worldmap [pos.x + 1, pos.y, pos.z] == type)
            {
                touches++;
            }             // Right

            if (worldmap [pos.x, pos.y + 1, pos.z] == type)
            {
                touches++;
            }             // Down

            if (worldmap [pos.x, pos.y - 1, pos.z] == type)
            {
                touches++;
            }             // Up

            return(touches);
        }
Ejemplo n.º 4
0
        public int FindTileByDir(Cord pos, int direction, char type, int maxreach = 200)
        {
            for (int i = 0; i < maxreach; i++)
            {
                switch (direction)
                {
                case 0:
                    try {
                        if (worldmap[pos.x, pos.y - i, pos.z] == type)
                        {
                            return(i);
                        }
                    } catch (Exception ex) {
                        return(-1);
                    }
                    break;

                case 1:
                    try {
                        if (worldmap[pos.x + i, pos.y, pos.z] == type)
                        {
                            return(i);
                        }
                    } catch (Exception ex) {
                        return(-1);
                    }
                    break;

                case 2:
                    try {
                        if (worldmap[pos.x, pos.y + i, pos.z] == type)
                        {
                            return(i);
                        }
                    } catch (Exception ex) {
                        return(-1);
                    }
                    break;

                case 3:
                    try {
                        if (worldmap[pos.x - i, pos.y, pos.z] == type)
                        {
                            return(i);
                        }
                    } catch (Exception ex) {
                        return(-1);
                    }
                    break;

                default:
                    return(-1);

                    break;
                }
            }

            return(-1);
        }
Ejemplo n.º 5
0
 public bool TileIsOnEdge(Cord pos)
 {
     if (pos.x == 0 || pos.x == worldmap.GetLength(0) - 1 || pos.y == 0 || pos.y == worldmap.GetLength(1) - 1)
     {
         return(true);
     }
     return(false);
 }
Ejemplo n.º 6
0
 public SamGobson(Cord pos) : base(pos)
 {
     letter    = 'S';
     health    = 10;
     level     = 1;
     name      = "Sam Gobson";
     quotes[0] = "How did i end up here?";
     quotes[1] = "Fight me irl.";
     quotes[1] = "Subway!";
 }
Ejemplo n.º 7
0
        public Room[] FindNearestRooms(Room room, int distance)
        {
            List <Room> selected = new List <Room> ();

            foreach (Room otherRoom in rooms)
            {
                if (Cord.Distance(room.pos, otherRoom.pos) <= distance)
                {
                    selected.Add(otherRoom);
                }
            }

            return(selected.ToArray());
        }
Ejemplo n.º 8
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);
        }
Ejemplo n.º 9
0
        public int FindTileByDir(Cord pos, int direction, char type, int maxreach = 200)
        {
            for (int i = 0; i < maxreach; i++) {
                switch (direction) {
                case 0:
                    try {
                        if(worldmap[pos.x,pos.y - i,pos.z] == type)
                            return i;
                    } catch (Exception ex) {
                        return -1;
                    }
                    break;
                case 1:
                    try {
                        if(worldmap[pos.x + i,pos.y,pos.z] == type)
                            return i;
                    } catch (Exception ex) {
                        return -1;
                    }
                    break;
                case 2:
                    try {
                        if(worldmap[pos.x,pos.y + i,pos.z] == type)
                            return i;
                    } catch (Exception ex) {
                        return -1;
                    }
                    break;
                case 3:
                    try {
                        if(worldmap[pos.x - i,pos.y,pos.z] == type)
                            return i;
                    } catch (Exception ex) {
                        return -1;
                    }
                    break;
                default:
                    return -1;
                    break;
                }
            }

            return -1;
        }
Ejemplo n.º 10
0
 public Player(int id, string name, int health, int attackxp, int defencexp, int magicxp, Cord pos) : base(pos)
 {
     this.id        = id;
     this.name      = name;
     this.health    = health;
     this.attackxp  = attackxp;
     this.defencexp = defencexp;
     this.magicxp   = magicxp;
 }
Ejemplo n.º 11
0
 public void SetTile(Cord pos, char type)
 {
     worldmap[pos.x,pos.y,pos.z] = type;
 }
Ejemplo n.º 12
0
 public Player(int id, string name, int health, int attackxp, int defencexp, int magicxp,Cord pos)
     : base(pos)
 {
     this.id = id;
     this.name = name;
     this.health = health;
     this.attackxp = attackxp;
     this.defencexp = defencexp;
     this.magicxp = magicxp;
 }
Ejemplo n.º 13
0
 public Room(Cord cord, int width, int height)
 {
     pos         = cord;
     this.width  = width;
     this.height = height;
 }
Ejemplo n.º 14
0
 public Entity()
 {
     position = new Cord(0, 0, 0);
 }
Ejemplo n.º 15
0
 public Entity(Cord pos)
 {
     position = pos;
 }
Ejemplo n.º 16
0
 public void SetTile(Cord pos, char type)
 {
     worldmap[pos.x, pos.y, pos.z] = type;
 }
Ejemplo n.º 17
0
 public Room(Cord cord, int width, int height)
 {
     pos = cord;
     this.width = width;
     this.height = height;
 }
Ejemplo n.º 18
0
 public override void Spawn(int health, Cord pos)
 {
     base.Spawn (health, pos);
     session.Send("[UPP]" + ToString());
 }
Ejemplo n.º 19
0
 public override void Spawn(int health, Cord pos)
 {
     base.Spawn(health, pos);
     session.Send("[UPP]" + ToString());
 }
Ejemplo n.º 20
0
 public SamGobson(Cord pos)
     : base(pos)
 {
     letter = 'S';
     health = 10;
     level = 1;
     name = "Sam Gobson";
     quotes[0] = "How did i end up here?";
     quotes[1] = "Fight me irl.";
     quotes[1] = "Subway!";
 }
Ejemplo n.º 21
0
        public int IsTouching(Cord pos, char type)
        {
            int touches = 0;
            if (worldmap [pos.x - 1, pos.y, pos.z] == type) {
                touches++;
            } // Left

            if (worldmap [pos.x + 1, pos.y, pos.z] == type) {
                touches++;
            } // Right

            if (worldmap [pos.x, pos.y + 1, pos.z] == type) {
                touches++;
            } // Down

            if (worldmap [pos.x, pos.y - 1, pos.z] == type) {
                touches++;
            } // Up

            return touches;
        }
Ejemplo n.º 22
0
 public Entity()
 {
     position = new Cord(0,0,0);
 }
Ejemplo n.º 23
0
 public bool TileIsOnEdge(Cord pos)
 {
     if (pos.x == 0 || pos.x == worldmap.GetLength(0) - 1 || pos.y == 0 || pos.y == worldmap.GetLength(1) - 1)
         return true;
     return false;
 }
Ejemplo n.º 24
0
 public Entity(Cord pos)
 {
     position = pos;
 }
Ejemplo n.º 25
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);
        }
Ejemplo n.º 26
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);
                }
            }
        }