Example #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));
        }
Example #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)));
        }
Example #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);
        }
Example #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);
        }
Example #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);
 }
Example #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!";
 }
Example #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());
        }
Example #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);
        }
Example #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;
        }
Example #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;
 }
Example #11
0
 public void SetTile(Cord pos, char type)
 {
     worldmap[pos.x,pos.y,pos.z] = type;
 }
Example #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;
 }
Example #13
0
 public Room(Cord cord, int width, int height)
 {
     pos         = cord;
     this.width  = width;
     this.height = height;
 }
Example #14
0
 public Entity()
 {
     position = new Cord(0, 0, 0);
 }
Example #15
0
 public Entity(Cord pos)
 {
     position = pos;
 }
Example #16
0
 public void SetTile(Cord pos, char type)
 {
     worldmap[pos.x, pos.y, pos.z] = type;
 }
Example #17
0
 public Room(Cord cord, int width, int height)
 {
     pos = cord;
     this.width = width;
     this.height = height;
 }
Example #18
0
 public override void Spawn(int health, Cord pos)
 {
     base.Spawn (health, pos);
     session.Send("[UPP]" + ToString());
 }
Example #19
0
 public override void Spawn(int health, Cord pos)
 {
     base.Spawn(health, pos);
     session.Send("[UPP]" + ToString());
 }
Example #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!";
 }
Example #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;
        }
Example #22
0
 public Entity()
 {
     position = new Cord(0,0,0);
 }
Example #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;
 }
Example #24
0
 public Entity(Cord pos)
 {
     position = pos;
 }
Example #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);
        }
Example #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);
                }
            }
        }