Exemple #1
0
        public void Draw(Graphics g, Size screenSize, int x, int y)
        {
            int elementX    = (int)Math.Floor(Math.Abs((double)(x / gridElementWidth)));
            int elementY    = (int)Math.Floor(Math.Abs((double)(y / gridElementHeight)));
            int endElementX = elementX + (int)Math.Floor((double)(screenSize.Width / gridElementWidth));
            int endElementY = elementY + (int)Math.Floor((double)(screenSize.Height / gridElementHeight));

            int drawPositionX = x + elementX * gridElementWidth;
            int drawPositionY = y + elementY * gridElementHeight;

            if (endElementX >= MapGrid.GridElementCollection.Length - 1)
            {
                endElementX = MapGrid.GridElementCollection.Length - 1;
            }

            for (int amountX = 0; amountX + elementX <= endElementX; amountX++)
            {
                var row = MapGrid.GridElementCollection[amountX + elementX];

                if (endElementY >= row.Length - 1)
                {
                    endElementY = row.Length - 1;
                }


                for (var amountY = 0; amountY + elementY <= endElementY; amountY++)
                {
                    var gridElement = row[amountY + elementY];

                    var image = (Bitmap)MapParser.GetImageById(gridElement.ImageId);

                    //image = (Bitmap)image.GetThumbnailImage(elementWidth, elementHeight, null, IntPtr.Zero);

                    g.DrawImageUnscaled(image, drawPositionX + amountX * gridElementWidth, drawPositionY + amountY * gridElementHeight);

                    /*   for (var bx = 0; bx < elementWidth; bx++)
                     * {
                     *     for (var by = 0; by < elementHeight; by++)
                     *     {
                     *         var cl = image.GetPixel(bx, by);
                     *         returnvalue.SetPixel(bx + (elementWidth * x), by + (elementHeight * y), cl);
                     *     }
                     * }  */
                }
            }
        }
Exemple #2
0
        public Image DrawImage(Size size)
        {
            Dictionary <String, Bitmap> cache = new Dictionary <string, Bitmap>();
            Bitmap   returnvalue = new Bitmap(size.Width, size.Height, PixelFormat.Format32bppPArgb);
            Graphics g           = Graphics.FromImage(returnvalue);

            for (var x = 0; x < MapGrid.GridElementCollection.Length; x++)
            {
                var row = MapGrid.GridElementCollection[x];
                for (var y = 0; y < row.Length; y++)
                {
                    Bitmap image;
                    var    gridElement = row[y];

                    var elementWidth  = (int)(Math.Ceiling((MapGrid.Width / row.Length) * getScaleFactorWidth(size.Width)));
                    var elementHeight = (int)(Math.Ceiling((MapGrid.Height / MapGrid.GridElementCollection.Length) * getScaleFactorHeight(size.Height)));


                    if (!cache.TryGetValue(gridElement.ImageId, out image))
                    {
                        image = (Bitmap)MapParser.GetImageById(gridElement.ImageId);
                        image = (Bitmap)CT_Helper.resizeImage(image, new Size(elementWidth, elementHeight));
                        cache.Add(gridElement.ImageId, image);
                    }


                    //image = (Bitmap)image.GetThumbnailImage(elementWidth, elementHeight, null, IntPtr.Zero);

                    g.DrawImageUnscaled(image, elementWidth * x, elementHeight * y);

                    /*   for (var bx = 0; bx < elementWidth; bx++)
                     * {
                     *     for (var by = 0; by < elementHeight; by++)
                     *     {
                     *         var cl = image.GetPixel(bx, by);
                     *         returnvalue.SetPixel(bx + (elementWidth * x), by + (elementHeight * y), cl);
                     *     }
                     * }  */
                }
            }

            return(returnvalue);
        }
Exemple #3
0
        public Map GenerateRandomMap(int width, int height, MapParser.SpecialMapElement specialMapElement)
        {
            //Map deklarieren
            Map returnvalue = null;
            //Zugehöriges Grid erzeugen:
            Grid tempGrid = new Grid();

            tileCountX = width;
            tileCountY = height;

            theSpecialMapElement = specialMapElement;
            if (theSpecialMapElement == MapParser.SpecialMapElement.CentralPark)
            {
                theCentralParkCreator = new CentralParkCreator(tileCountX, tileCountY);
                ParkGridElementPossibilitiesList = GetListFromXML(@"ParkElementList.xml");
            }

            else if (theSpecialMapElement == MapParser.SpecialMapElement.RiverCrossing)
            {
                theRiverCrossingCreator = new RiverCrossingCreator(tileCountX, tileCountY);
            }

            //Die Elementliste aus der Xml "ElementList.xml" ziehen:
            GridElementPossibilitiesList = GetListFromXML(@"ElementList.xml");

            //Im Folgenden das Grid in der in den Parametern zugewiesenen Dimension als Jagged Array erzeugen.
            tempGrid.GridElementCollection = new GridElement[height][];

            for (int i = 0; i < height; i++)
            {
                tempGrid.GridElementCollection[i] = new GridElement[width];
            }

            tileWidth = width;
            tileHeight = height;
            SetMapProperties(width, height);
            tempGrid = SetMapBoundaries(width, height);
            SetTileIds(tempGrid.GridElementCollection);
            returnvalue = new Map(tempGrid);

            return returnvalue;
        }
Exemple #4
0
        /// <summary>
        /// Erstellt die Boxen mit Bildern
        /// </summary>
        /// <param name="uiSize">Die Größe, in der die Map angezeigt werden soll</param>
        public void Initialize(Size uiSize)
        {
            this.Size = uiSize;

            //x=breitengrad (x-achse)
            elementBoxes = new PictureBox[MapGrid.GridElementCollection.Length][];
            for (var x = 0; x < MapGrid.GridElementCollection.Length; x++)
            {
                elementBoxes[x] = new PictureBox[MapGrid.GridElementCollection[x].Length];
                var column = MapGrid.GridElementCollection[x];
                for (var y = 0; y < column.Length; y++)
                {
                    var gridElement = column[y];
                    var pictureBox  = new System.Windows.Forms.PictureBox();
                    //pictureBox.SizeMode = PictureBoxSizeMode.AutoSize;

                    gridElementWidth  = (int)((MapGrid.Width / MapGrid.GridElementCollection.Length) * ScaleFactorWidth);
                    gridElementHeight = (int)((MapGrid.Height / column.Length) * ScaleFactorHeight);

                    pictureBox.Width  = (int)gridElementWidth;
                    pictureBox.Height = (int)gridElementHeight;
                    var image = MapParser.GetImageById(gridElement.ImageId);
                    pictureBox.Image = image;
                    //pictureBox.BorderStyle = BorderStyle.FixedSingle;
                    pictureBox.SizeMode = PictureBoxSizeMode.StretchImage;

                    var boxX = gridElementWidth * x;
                    var boxY = gridElementHeight * y;

                    pictureBox.Left = (int)boxX;
                    pictureBox.Top  = (int)boxY;

                    elementBoxes[x][y] = pictureBox;

                    //Auskommentiert, um die Testausgaben der Kollision zu sehen
                    this.Controls.Add(elementBoxes[x][y]);
                }
            }

            Collision = new CollisionManager(MapGrid, gridElementWidth, gridElementHeight);
        }
Exemple #5
0
        /// <summary>
        /// Erstellt die Boxen mit Bildern
        /// </summary>
        /// <param name="uiSize">Die Größe, in der die Map angezeigt werden soll</param>
        public void Initialize(Size uiSize)
        {
            this.Size = uiSize;

            //x=breitengrad (x-achse)
            for (var x = 0; x < MapGrid.GridElementCollection.Length; x++)
            {
                var column = MapGrid.GridElementCollection[x];
                for (var y = 0; y < column.Length; y++)
                {
                    var gridElement = column[y];

                    gridElementWidth  = (int)Math.Ceiling((MapGrid.Width / MapGrid.GridElementCollection.Length) * ScaleFactorWidth);
                    gridElementHeight = (int)Math.Ceiling((MapGrid.Height / column.Length) * ScaleFactorHeight);

                    MapParser.Initialize(gridElementWidth, gridElementHeight);
                }
            }

            Collision = new CollisionManager(MapGrid, gridElementWidth, gridElementHeight);
        }