Ejemplo n.º 1
0
 public static Surface GetSurface(byte[] imgBytes, Size boxSize)
 {
     Surface boxSurf = new Surface(boxSize);
     boxSurf.Fill(Color.White);  //Fill background to white color
     //Get and resize image
     if (imgBytes != null)
     {
         Surface imgSurf = new Surface(imgBytes);
         double scale = Ratio.CalculateScale(imgSurf.Size,
                                             new Size(boxSize.Width, boxSize.Height),
                                             Ratio.RatioType.FitImage); //Calculate ratio
         Surface scaledSurf = imgSurf.CreateScaledSurface(scale, true);
         imgSurf.Dispose();
         Point pt = new Point((boxSize.Width - scaledSurf.Width) / 2,      //Left point
                              (boxSize.Height - scaledSurf.Height) / 2);   //Top point
         boxSurf.Blit(scaledSurf, pt);
         scaledSurf.Dispose();  //Clear imgSurf memory
     }
     //Draw border
     for(int i = 0; i < BORDER; i++)
         boxSurf.Draw(new Box(new Point(i, i), new Point(boxSize.Width - i - 1, boxSize.Height - i - 1)), Color.Gray);
     return boxSurf;
 }
Ejemplo n.º 2
0
        public void Initialize(Rectangle mapRectangle, Rectangle showRectangle, Surface map)
        {
            double xScaleFactor = Convert.ToDouble(panel.Width) / Convert.ToDouble(mapRectangle.Width);
            double yScaleFactor = Convert.ToDouble(panel.Height) / Convert.ToDouble(mapRectangle.Height);

            if (xScaleFactor < yScaleFactor) { scaleFactor = xScaleFactor; }
            else { scaleFactor = yScaleFactor; }

            short mapX = (short)(mapRectangle.X * scaleFactor);
            short mapY = (short)(mapRectangle.Y * scaleFactor);
            short mapW = (short)(mapRectangle.Width * scaleFactor);
            short mapH = (short)(mapRectangle.Height * scaleFactor);

            short x = (short)(showRectangle.X * scaleFactor);
            short y = (short)(showRectangle.Y * scaleFactor);
            short w = (short)(showRectangle.Width * scaleFactor);
            short h = (short)(showRectangle.Height * scaleFactor);

            if (mapW > surfaceControl.Width) { mapW = (short)panel.Width; }
            if (mapH > surfaceControl.Height) { mapH = (short)panel.Height; }

            mapViewport = new Box(new Point(x, y), new Point(x + w - 1, y + h - 1));

            mapSurface = map;

            surface = new Surface(mapW, mapH);
            surface = map.CreateScaledSurface(scaleFactor, true);
            surface.Draw(mapViewport, Color.Red);
            Point pos = new Point((panel.Width / 2) - (mapW / 2), (panel.Height / 2) - (mapH / 2));
            surfaceControl.Width = mapW;
            surfaceControl.Height = mapH;
            surfaceControl.Location = pos;
            this.surfaceControl.Blit(surface);

            this.initialized = true;
        }
Ejemplo n.º 3
0
        ///// <summary>
        ///// Doubles the size of the surface
        ///// </summary>
        //public void ScaleDouble()
        //{
        //    if (this.disposed)
        //    {
        //        throw (new ObjectDisposedException(this.ToString()));
        //    }
        //    this.Scale(2, 2);
        //}

        ///// <summary>
        ///// Doubles the size of the surface
        ///// </summary>
        ///// <param name="antiAlias">If true</param>
        ///// <returns></returns>
        //public void ScaleDouble(bool antiAlias)
        //{
        //    if (this.disposed)
        //    {
        //        throw (new ObjectDisposedException(this.ToString()));
        //    }
        //    this.Scale(2, 2, antiAlias);
        //}

        ///// <summary>
        ///// Stretch Surface
        ///// </summary>
        ///// <param name="sourceRectangle">Source Rectangle</param>
        ///// <param name="destinationRectangle">Destination of stretch</param>
        ///// <returns>new Surface</returns>
        //public void Stretch(Rectangle sourceRectangle, Rectangle destinationRectangle)
        //{
        //    Surface surface = new Surface(sourceRectangle);
        //    //Surface surface = (Surface)this.Clone();
        //    Color colorTemp = this.TransparentColor;
        //    this.Transparent = false;
        //    surface.Blit(this, new Point(0, 0), sourceRectangle);
        //    this.transparentColor = colorTemp;
        //    double stretchWidth = ((double)destinationRectangle.Width / (double)sourceRectangle.Width);
        //    double stretchHeight = ((double)destinationRectangle.Height / (double)sourceRectangle.Height);
        //    surface.Scale(stretchWidth, stretchHeight);
        //    CloneFields(this, surface);
        //    this.Handle = surface.Handle;
        //}

        ///// <summary>
        ///// Stretch Surface
        ///// </summary>
        ///// <param name="destinationSize">Destination of stretch</param>
        ///// <returns>new Surface</returns>
        //public void Stretch(Size destinationSize)
        //{
        //    double stretchWidth = ((double)destinationSize.Width / (double)this.Width);
        //    double stretchHeight = ((double)destinationSize.Height / (double)this.Height);
        //    this.Scale(stretchWidth, stretchHeight);
        //}

        /// <summary>
        /// Stretch Surface
        /// </summary>
        /// <param name="sourceRectangle">Source Rectangle</param>
        /// <param name="destinationRectangle">Destination of stretch</param>
        /// <returns>new Surface</returns>
        public Surface CreateStretchedSurface(Rectangle sourceRectangle, Rectangle destinationRectangle)
        {
            using (Surface surface1 = new Surface(sourceRectangle))
            {
                //Surface surface = (Surface)this.Clone();
                Color colorTemp = this.TransparentColor;
                this.Transparent = false;
                surface1.Blit(this, new Point(0, 0), sourceRectangle);
                this.transparentColor = colorTemp;
                double stretchWidth = ((double)destinationRectangle.Width / (double)sourceRectangle.Width);
                double stretchHeight = ((double)destinationRectangle.Height / (double)sourceRectangle.Height);
                Surface surface2 = surface1.CreateScaledSurface(stretchWidth, stretchHeight);
                CloneFields(this, surface2);
                return surface2;
            }
        }
Ejemplo n.º 4
0
        public void ViewportChanged(Rectangle newViewport, Surface map)
        {
            if (initialized)
            {
                short x = (short)(newViewport.X * scaleFactor);
                short y = (short)(newViewport.Y * scaleFactor);
                short w = (short)(newViewport.Width * scaleFactor);
                short h = (short)(newViewport.Height * scaleFactor);

                if (w > surfaceControl.Width) { w = (short)surface.Width; }
                if (h > surfaceControl.Height) { h = (short)surface.Height; }

                mapViewport = new Box(new Point(x, y), new Point(x + w - 1, y + h - 1));

                mapSurface = map;

                if (map != null) { surface = map.CreateScaledSurface(scaleFactor, true); }
                surface.Draw(mapViewport, Color.Red);
                this.surfaceControl.Blit(surface);
            }
        }
Ejemplo n.º 5
0
        private void SpawnShip(int number)
        {
            Player player;
            SpriteSheet spriteSheet;
            string bulletImageFilename;
            double bulletImageScale;
            Color bulletImageTransparentColor;
            string infoBarShipImageFilename;
            Color infoBarShipImageTransparentColor;
            Point scoreCardDisplayPosition;
            if (number == 1)
            {
                player = this.player1;
                bulletImageFilename = Configuration.Ships.Model1.BulletImageFilename;
                bulletImageScale = Configuration.Ships.Model1.BulletImageScale;
                bulletImageTransparentColor = Configuration.Ships.Model1.BulletImageTransparentColor;
                infoBarShipImageFilename = Configuration.Ships.Model1.InfoBarShipImageFilename;
                infoBarShipImageTransparentColor = Configuration.Ships.Model1.InfoBarShipImageTransparentColor;
                scoreCardDisplayPosition = new Point(Configuration.InfoBarPosition.X + Configuration.InfoBar.Player1ScoreCardDisplayPosition.X, Configuration.InfoBarPosition.Y + Configuration.InfoBar.Player1ScoreCardDisplayPosition.Y);
                spriteSheet = new SpriteSheet(Configuration.Ships.Model1.SpriteSheet.Filename, Configuration.Ships.Model1.SpriteSheet.TransparentColor, Configuration.Ships.Model1.SpriteSheet.Size, Configuration.Ships.Model1.SpriteSheet.RotationDegreesPerFrame, Configuration.Ships.Model1.SpriteSheet.FirstFrameDirectionDegrees, Configuration.Ships.Model1.SpriteSheet.RotationAnimationDelay, Configuration.Ships.Model1.SpriteSheet.CannonBarrelLength, Configuration.Ships.Model1.SpriteSheet.ForwardThrusterEngineLength, Configuration.Ships.Model1.SpriteSheet.ReverseThrusterEngineLength);
            }
            else
            {
                player = this.player2;
                bulletImageFilename = Configuration.Ships.Model2.BulletImageFilename;
                bulletImageScale = Configuration.Ships.Model2.BulletImageScale;
                bulletImageTransparentColor = Configuration.Ships.Model2.BulletImageTransparentColor;
                infoBarShipImageFilename = Configuration.Ships.Model2.InfoBarShipImageFilename;
                infoBarShipImageTransparentColor = Configuration.Ships.Model2.InfoBarShipImageTransparentColor;
                scoreCardDisplayPosition = new Point(Configuration.InfoBarPosition.X + Configuration.InfoBar.Player2ScoreCardDisplayPosition.X, Configuration.InfoBarPosition.Y + Configuration.InfoBar.Player2ScoreCardDisplayPosition.Y);

                spriteSheet = new SpriteSheet(Configuration.Ships.Model2.SpriteSheet.Filename, Configuration.Ships.Model2.SpriteSheet.TransparentColor, Configuration.Ships.Model2.SpriteSheet.Size, Configuration.Ships.Model2.SpriteSheet.RotationDegreesPerFrame, Configuration.Ships.Model2.SpriteSheet.FirstFrameDirectionDegrees, Configuration.Ships.Model2.SpriteSheet.RotationAnimationDelay, Configuration.Ships.Model2.SpriteSheet.CannonBarrelLength, Configuration.Ships.Model2.SpriteSheet.ForwardThrusterEngineLength, Configuration.Ships.Model2.SpriteSheet.ReverseThrusterEngineLength);
            }

            Point spawnPosition = GetSafeSpawnPosition(player.Ship);

            // Start the creation special effects.
            this.particleSystem.Particles.Add(player.CreationEffect.Create(new Point(spawnPosition.X + spriteSheet.FrameSize.Width / 2, spawnPosition.Y + spriteSheet.FrameSize.Height / 2)));

            Bitmap bulletImage = new Bitmap(bulletImageFilename);
            Surface bulletSurface = new Surface(bulletImage).Convert(Video.Screen, true, false);
            bulletSurface = bulletSurface.CreateScaledSurface(bulletImageScale);
            bulletSurface.Transparent = true;
            bulletSurface.TransparentColor = bulletImageTransparentColor;

            Bitmap infoBarShipImage = new Bitmap(infoBarShipImageFilename);
            Surface infoBarShipSurface = new Surface(infoBarShipImage).Convert(Video.Screen, true, false);
            infoBarShipSurface.Transparent = true;
            infoBarShipSurface.TransparentColor = infoBarShipImageTransparentColor;

            if (player.Ship != null)
                player.Ship.Dispose();

            player.Ship = new Ship(player, spriteSheet, spawnPosition, bulletSurface, infoBarShipSurface);

            if (player.ScoreCard == null)
                player.ScoreCard = new ScoreCard(player, scoreCardDisplayPosition);

            this.particleSystem.Add(player.Ship);
        }
Ejemplo n.º 6
0
        private static Sprite GetPlanetSprite(string imageFilename, Color bitmap_TransparentColor, float scale)
        {
            Bitmap image = new Bitmap(imageFilename);
            Surface surface = new Surface(image);

            // Convert it for display.
            surface.Convert(Video.Screen, true, false);

            // Scale it.
            surface = surface.CreateScaledSurface(scale);

            // Set the transparent color.
            surface.Transparent = true;
            surface.TransparentColor = bitmap_TransparentColor;

            Sprite sprite = new Sprite(surface);

            return sprite;
        }
Ejemplo n.º 7
0
        public void DrawBuffer()
        {
            Surface textSurf;
            Size textSize = SdlDotNet.Widgets.TextRenderer.SizeText2(font, bubbleText, false, 0);
            CharRenderOptions[] renderOptions = new CharRenderOptions[bubbleText.Length];
            for (int i = 0; i < renderOptions.Length; i++) {
                renderOptions[i] = new CharRenderOptions(Color.WhiteSmoke);
            }
            renderOptions = Client.Logic.Graphics.StringParser.ParseText(renderOptions, ref bubbleText);
            if (textSize.Width > 300) {
                textSurf = SdlDotNet.Widgets.TextRenderer.RenderTextBasic2(font, bubbleText, renderOptions, Color.WhiteSmoke, false, 300, 0, 0, 0);
            } else {
                textSurf = SdlDotNet.Widgets.TextRenderer.RenderTextBasic2(font, bubbleText, renderOptions, Color.WhiteSmoke, false, 0, 0, 0, 0);
            }
            int tilesWidth = System.Math.Max(textSurf.Width / Constants.TILE_WIDTH, 2);
            int tilesHeight = System.Math.Max(textSurf.Height / Constants.TILE_HEIGHT, 2);

            if (textSurf.Width > tilesWidth * Constants.TILE_WIDTH) {
                tilesWidth++;
            }
            if (textSurf.Height > tilesHeight * Constants.TILE_HEIGHT * 0.7) {
                tilesHeight++;
            }
            if (buffer != null) {
                buffer.Close();
            }
            buffer = new Surface(new Size((tilesWidth * Constants.TILE_WIDTH), (tilesHeight * Constants.TILE_HEIGHT)));
            buffer.Fill(Color.Transparent);
            buffer.TransparentColor = Color.Transparent;
            buffer.Transparent = true;
            for (int i = 0; i < tilesHeight; i++) {
                if (i == 0) {
                    Maps.MapRenderer.DrawTileToSurface(buffer, 10, 1, 0, 0);
                    for (int n = 0; n < tilesWidth - 2; n++) {
                        Maps.MapRenderer.DrawTileToSurface(buffer, 10, 16, n + 1, 0);
                    }
                    Maps.MapRenderer.DrawTileToSurface(buffer, 10, 2, tilesWidth - 1, 0);
                } else if (i == tilesHeight - 1) {
                    Maps.MapRenderer.DrawTileToSurface(buffer, 10, 3, 0, tilesHeight - 1);
                    for (int n = 0; n < tilesWidth - 2; n++) {
                        Maps.MapRenderer.DrawTileToSurface(buffer, 10, 15, n + 1, tilesHeight - 1);
                    }
                    Maps.MapRenderer.DrawTileToSurface(buffer, 10, 4, tilesWidth - 1, tilesHeight - 1);
                } else {
                    Maps.MapRenderer.DrawTileToSurface(buffer, 10, 18, 0, i);
                    for (int n = 0; n < tilesWidth - 2; n++) {
                        Maps.MapRenderer.DrawTileToSurface(buffer, 10, 5, n + 1, i);
                    }
                    Maps.MapRenderer.DrawTileToSurface(buffer, 10, 17, tilesWidth - 1, i);
                }
            }
            buffer = buffer.CreateScaledSurface(1, 0.7);
            buffer.Transparent = true;
            buffer.Blit(textSurf, new Point(Logic.Graphics.DrawingSupport.GetCenterX(buffer.Width, textSurf.Width), 0));
            textSurf.Close();
            RedrawRequested = false;
        }