예제 #1
0
        public DrawableCityBlock[] GetCityBlocksIfAvailable(Point clicked, Point area)
        {
            int size  = area.X * area.Y;
            int count = 0;

            DrawableCityBlock[] tmpBlocks = new DrawableCityBlock[size];

            //retorna null se a area for maior que 1 e se a estrutura for sair fora do mapa
            if ((area.X > 1) && ((clicked.X + area.X > Width) ||
                                 (clicked.Y + area.Y > this.Height)))
            {
                return(null);
            }
            else if (area.X == 1 && area.Y == 1)
            {
                tmpBlocks[size - 1] = Blocks[clicked.X, clicked.Y];
                return(tmpBlocks);
            }

            for (int x = clicked.X; x < clicked.X + area.X; x++)
            {
                for (int y = clicked.Y; y < clicked.Y + area.Y; y++)
                {
                    if (Blocks[x, y].IsBuildable)
                    {
                        tmpBlocks[count++] = Blocks[x, y];
                    }
                }
            }

            return(Utils.IsAllValuesNotNull(tmpBlocks) ? tmpBlocks : null);
        }
예제 #2
0
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(base.Game.GraphicsDevice);

            // Populate your tiles list with your textures here
            //Tiles = new List<Texture2D>();
            Texture2D tmp = base.Game.Content.Load <Texture2D>(@"CityMap\Cubes\cubo_terra");

            //Tiles.Add(tmp);

            selectionTexture = base.Game.Content.Load <Texture2D>(@"CityMap\selection_maior");
            //cuboSemLinha = this.content.Load<Texture2D>("cubosemlinha");

            pequenaCasa = base.Game.Content.Load <Texture2D>(@"CityMap\pequena_casa");

            //grandeCasa = base.Game.Content.Load<Texture2D>(@"Buildings\casa_grande");
            grandeCasa = base.Game.Content.Load <Texture2D>(@"Buildings\quartel_2x2");

            House3x3 = base.Game.Content.Load <Texture2D>(@"Buildings\casa3x3");

            spriteFont = base.Game.Content.Load <SpriteFont>(@"SpriteFont");

            //testeHouse = new TinyHouse(pequenaCasa);

            //  Initialise block 2D array
            Blocks = new DrawableCityBlock[Width, Height];

            // Used as a base width and height for varying sized tiles
            CityBlock.BaseWidth  = tmp.Width;
            CityBlock.BaseHeight = tmp.Height / 2;

            Rectangle position = new Rectangle(0, 0, tmp.Width, tmp.Height);

            for (int x = 0; x < Width; x++)
            {
                position.X = (CityBlock.BaseWidth / 2) * x;
                position.Y = (CityBlock.BaseHeight / 2) * x;

                for (int y = 0; y < Height; y++)
                {
                    Blocks[x, y] = new DrawableCityBlock(new CityBlock(position, new Point(x, y)));

                    Blocks[x, y].Coordinates = x + "," + y;

                    position.Y += (CityBlock.BaseHeight / 2);
                    position.X += -(CityBlock.BaseWidth / 2);
                }
            }

            CalculateCityEdges();

            base.LoadContent();
        }
예제 #3
0
        public void DrawCityBlocksAndBuildings()
        {
            for (int x = 0; x < Width; x++)
            {
                for (int y = 0; y < Height; y++)
                {
                    DrawableCityBlock block = Blocks[x, y];

                    spriteBatch.Draw(block.Texture, Camera.RelativeToCamera(block.CityBlock.Position),
                                     Color.White);

                    if (ShowBlockEdges)
                    {
                        PrimitiveDrawing.DrawPolygon(spriteBatch, Utils.BlankTexture, 1, Color.Red, Camera.RelativeToCamera(block.CityBlock.TopPolygon));
                    }

                    if (!block.IsBuildable)
                    {
                        Rectangle teste = new Rectangle(block.CityBlock.Position.X, block.CityBlock.Position.Y, selectionTexture.Width, selectionTexture.Height);
                        spriteBatch.Draw(selectionTexture, Camera.RelativeToCamera(teste), Color.Red);
                    }

                    Rectangle teste2 = Camera.RelativeToCamera(block.CityBlock.Position);
                    Vector2   v      = new Vector2(teste2.X + 20, teste2.Y + 10);

                    if (block.Building == null)
                    {
                        spriteBatch.DrawString(spriteFont, block.Coordinates, v, Color.Black);
                    }

                    if (block.IsReferenceForBuilding && block.Building != null)
                    {
                        spriteBatch.DrawString(spriteFont, "R", v, Color.Black);
                    }
                    else if (!block.IsReferenceForBuilding && block.Building != null)
                    {
                        spriteBatch.DrawString(spriteFont, "B", v, Color.Black);
                    }
                }
            }

            if (ShowBuildings)
            {
                for (int y = 0; y < Height; y++)
                {
                    int tmpY = y;
                    for (int x = 0; tmpY >= 0; x++)
                    {
                        DrawableCityBlock block = Blocks[x, tmpY];

                        if (block.Building != null && !block.IsReferenceForBuilding)
                        {
                            spriteBatch.Draw(block.Building.Texture, Camera.RelativeToCamera(block.Building.Location), Color.White);
                        }

                        tmpY--;
                    }
                }

                int startX = 1;

                do
                {
                    int tmpY = Height - 1;
                    for (int x = startX; x < Width; x++)
                    {
                        DrawableCityBlock block = Blocks[x, tmpY];

                        if (block.Building != null && !block.IsReferenceForBuilding)
                        {
                            spriteBatch.Draw(block.Building.Texture, Camera.RelativeToCamera(block.Building.Location), Color.White);
                        }

                        tmpY--;
                    }

                    startX++;
                } while (startX < Width);
            }
        }