示例#1
0
        public ModCity(string name, Texture2D texture, Texture2D highlightTexture, Texture2D clickedTexture, Vector2 gridposition,Vector2 gridOffset,float size, IsoGrid grid, Tuple<float, float, float> politicalStanding, List<Ship> shipList, List<Material> materialList, List<Tuple<Building, int>> buildingList, GraphicsDevice graphicsDevice,Random random, bool playerCity = false)
        {
            this.lowTex = texture;
            this.highTex = highlightTexture;
            this.clickTex = clickedTexture;
            this.gridposition = gridposition;
            this.rect = new Rectangle(0, 0, lowTex.Width, lowTex.Height);
            this.position = grid.gridCoords(gridposition) - new Vector2(0, lowTex.Height);

            this.name = name;
            this.player = playerCity;

            this.politics = politicalStanding;
            this.ships = shipList;
            this.materials = materialList;
            this.buildingTypes = buildingList;

            this.tex = lowTex;

            this.isogrid = new CityIsoGrid(graphicsDevice, Math.PI / 6.0, 8, size ,position + gridOffset);

            // fill grid with buildings in random positions

            List<Vector2> positions = new List<Vector2>{}; // list of possible positions...

             for (int i=0;i<isogrid.size;i++)
            {
                for (int j=0;j<isogrid.size;j++)
                {
                    if (isogrid.usage[i,j] == 0)
                    {
                        positions.Add(new Vector2(i,j));
                    }
                }
             }

            List<Vector2> rpositions = new List<Vector2>{}; // randomised list of possible positions...

            foreach (Vector2 p in positions)
            {
                int i = random.Next(rpositions.Count);
                rpositions.Insert(i,p);
            }

            foreach (Tuple<Building, int> buildingType in buildingList) // fit them all in somewhere...
            {
                for (int n = 0; n < buildingType.Item2; n++) // for the number in the city...
                {
                    Vector2 pos = Vector2.Zero;

                    for (int j = 0; j < rpositions.Count; j++) // find a suitable position...
                    {
                        pos = rpositions[j];
                        bool fit = true;

                        for (int l = 0; l < buildingType.Item1.footprint.X; l ++)
                        {
                            for (int k = 0; k < buildingType.Item1.footprint.Y; k++)
                            {
                                if ((int)pos.X + l >= isogrid.usage.GetLength(0) | (int)pos.Y + k >= isogrid.usage.GetLength(1))
                                {
                                    fit = false;
                                }

                                else if (isogrid.usage[(int)pos.X + l, (int)pos.Y + k] == 1)
                                {
                                    fit = false;
                                }
                            }
                        }

                        if (fit == true)
                        {
                            break;
                        }
                    }

                    int type = random.Next(1, buildingType.Item1.variations);

                    buildings.Add(new Tuple<Building, int, Vector2>(buildingType.Item1, type, pos));

                    for (int x = (int)pos.X; x < buildingType.Item1.footprint.X + (int)pos.X; x++)
                    {
                        for (int y = (int)pos.Y; y < buildingType.Item1.footprint.Y + (int)pos.Y; y++)
                        {
                            isogrid.usage[x, y] = 1;
                            rpositions.Remove(pos + new Vector2(x, y));
                        }
                    }
                }
            }
        }
示例#2
0
 public void Draw(SpriteBatch sbatch, Vector2 gridposition, int variation, CityIsoGrid grid)
 {
     position = grid.gridEdgeCoords(gridposition) - new Vector2(0, tex.Height) + offset;
     rect.X = rect.Width * (variation - 1);
     sbatch.Draw(tex, position, rect, Color.White, 0.0f, Vector2.Zero, 1.0f, SpriteEffects.None, 0.4f + gridposition.Y * 0.001f - gridposition.X * 0.0001f);
 }