Exemple #1
0
        public MapDirection GetDirectionTo(Navnode other)
        {
            float xDist = 0;
            float yDist = 0;

            xDist = other.Position.X - Position.X;
            yDist = other.Position.Y - Position.Y;

            // Check to see which direction is the facing direction
            if (Math.Abs(xDist) > Math.Abs(yDist))
            {
                // Horizontal direction
                if (xDist > 0)
                {
                    return(MapDirection.Right);
                }
                else
                {
                    return(MapDirection.Left);
                }
            }
            else
            {
                // Vertical direction
                if (yDist > 0)
                {
                    return(MapDirection.Down);
                }
                else
                {
                    return(MapDirection.Up);
                }
            }
        }
Exemple #2
0
        public Building(Navnode node, BuildingType type)
        {
            Type       = type;
            texture    = buildingGraphics[Type];
            parentNode = node;

#if DEBUG
            Console.WriteLine("GENERATE " + Type.ToString());
#endif
        }
        // Add options for the super mode
        public void GenerateTown(ref List <Building> buildings, ref Navnode startPoint)
        {
            // First, clear the list of buildings.  Presumably there will be some flashy effect as well
            buildings.Clear();

            Navnode             currentNode;
            List <Navnode>      remainingNodes = gameMap.GetNodeList().FindAll(x => x.IsBuildingSpawn);
            List <BuildingType> availableTypes = new List <BuildingType>();
            Building            newBuilding;

            foreach (BuildingType b in Enum.GetValues(typeof(BuildingType)))
            {
                availableTypes.Add(b);
            }

            availableTypes.Remove(BuildingType.TrainStation);

            int index = 0;

            // Next, generate the station in a random location.
            index       = TreasureTown.StaticRandom.Next(0, remainingNodes.Count);
            currentNode = remainingNodes[index];
            remainingNodes.RemoveAt(index);

            newBuilding = new Building(currentNode, BuildingType.TrainStation);
            currentNode.SetBuilding(newBuilding);
            buildings.Add(newBuilding);

            BuildingType newBuildingType;

            // Inform the game scene where the new start point will be
            startPoint = currentNode.GetAdjacentSpace();

            // Now that the start point has been settled, generate the rest of the town
            while (remainingNodes.Count > 0)
            {
                index       = TreasureTown.StaticRandom.Next(0, remainingNodes.Count);
                currentNode = remainingNodes[index];
                remainingNodes.RemoveAt(index);
                newBuildingType = GetRandomBuildingType(availableTypes);
                newBuilding     = new Building(currentNode, newBuildingType);
                currentNode.SetBuilding(newBuilding);
                buildings.Add(newBuilding);

                // If this building occurs twice in the town, remove it from the available types.
                if (buildings.FindAll(x => x.Type == newBuildingType).Count >= 2)
                {
                    availableTypes.Remove(newBuildingType);
                }

                // Now there are no more towns with 3 banks
            }

            GenerateItems(ref buildings);
        }