Ejemplo n.º 1
0
 public Furniture(Vector2 pos, FurnitureType type, Room r) : base(pos)
 {
     this.type = type;
     room      = r;
 }
Ejemplo n.º 2
0
        public void GenerateFurniture()
        {
            foreach (Room ro in rooms)
            {
                if (ro != null)
                {
                    foreach (string s in ro.type.furniture.Keys)
                    {
                        if ((float)r.NextDouble() < ro.type.furniture[s].chance) //If random chance...
                        {
                            switch (ro.type.furniture[s].anchor)
                            {
                            case FurnitureAnchor.top:
                                while (true)
                                {
                                    int posX = r.Next(1, ro.roomSize.X - 1);     // Random position for the furniture
                                    if (tileMap[ro.roomPos.X + posX, ro.roomPos.Y]?.GetType() == typeof(Door) || tileMap[ro.roomPos.X + posX + 1, ro.roomPos.Y + 1]?.GetType() == typeof(Door) || tileMap[ro.roomPos.X + posX - 1, ro.roomPos.Y + 1]?.GetType() == typeof(Door))
                                    {
                                        continue;     // Furniture is next to door, repeat random process
                                    }
                                    else
                                    {
                                        objectMap.Add(new Furniture(new Vector2(ro.roomPos.X + posX, ro.roomPos.Y + 1), FurnitureType.ParseFromXML(furnitureDocument, s), ro));
                                        break;
                                    }
                                }
                                break;

                            case FurnitureAnchor.sides:
                                while (true)
                                {
                                    int posY = r.Next(2, ro.roomSize.Y - 1); // Random position for the furniture
                                    if (r.Next(0, 2) == 0)                   // Spawn on the right or left side
                                    {
                                        // Left side
                                        if (tileMap[ro.roomPos.X, ro.roomPos.Y + posY]?.GetType() == typeof(Door))
                                        {
                                            continue;     // Furniture is next to door, repeat random process
                                        }
                                        else
                                        {
                                            objectMap.Add(new Furniture(new Vector2(ro.roomPos.X + 1, ro.roomPos.Y + posY), FurnitureType.ParseFromXML(furnitureDocument, s), ro));
                                            break;
                                        }
                                    }
                                    else
                                    {
                                        // Right side
                                        if (tileMap[ro.roomPos.X + ro.roomSize.X - 1, ro.roomPos.Y + posY]?.GetType() == typeof(Door))
                                        {
                                            continue;     // Furniture is next to door, repeat random process
                                        }
                                        else
                                        {
                                            objectMap.Add(new Furniture(new Vector2(ro.roomPos.X + ro.roomSize.X - 2, ro.roomPos.Y + posY), FurnitureType.ParseFromXML(furnitureDocument, s), ro));
                                            break;
                                        }
                                    }
                                }
                                break;

                            case FurnitureAnchor.center:
                                break;

                            case FurnitureAnchor.corners:
                                break;

                            default:
                                break;
                            }
                        }
                    }
                }
            }
        }