Пример #1
0
        /// <summary>
        /// 判定指定的两张图片之间是否产生了碰撞
        /// </summary>
        ///
        /// <param name="src"></param>
        /// <param name="x1"></param>
        /// <param name="y1"></param>
        /// <param name="dest"></param>
        /// <param name="x2"></param>
        /// <param name="y2"></param>
        /// <returns></returns>
        public bool isPixelCollide(LImage src, float x1, float y1, LImage dest,
                                   float x2, float y2)
        {
            float width1 = x1 + src.GetWidth() - 1, height1 = y1 + src.GetHeight()
                                                              - 1, width2 = x2 + dest.GetWidth() - 1, height2 = y2
                                                                                                                + dest.GetHeight() - 1;
            int xstart = (int)Loon.Utils.MathUtils.Max(x1, x2), ystart = (int)Loon.Utils.MathUtils.Max(y1, y2), xend = (int)Loon.Utils.MathUtils.Min(width1, width2), yend = (int)Loon.Utils.MathUtils.Min(height1, height2);
            int toty = Loon.Utils.MathUtils.Abs(yend - ystart);
            int totx = Loon.Utils.MathUtils.Abs(xend - xstart);

            for (int y = 1; y < toty - 1; y++)
            {
                int ny  = Loon.Utils.MathUtils.Abs(ystart - (int)y1) + y;
                int ny1 = Loon.Utils.MathUtils.Abs(ystart - (int)y2) + y;
                for (int x = 1; x < totx - 1; x++)
                {
                    int nx  = Loon.Utils.MathUtils.Abs(xstart - (int)x1) + x;
                    int nx1 = Loon.Utils.MathUtils.Abs(xstart - (int)x2) + x;
                    try
                    {
                        if (((src.GetPixel(nx, ny).PackedValue != LSystem.TRANSPARENT)) &&
                            ((dest.GetPixel(nx1, ny1).PackedValue != LSystem.TRANSPARENT)))
                        {
                            return(true);
                        }
                    }
                    catch (Exception e)
                    {
                        Loon.Utils.Debugging.Log.Exception(e);
                    }
                }
            }
            return(false);
        }
Пример #2
0
        public static LTexture FilterColor(string res, LColor height, Loon.Core.Graphics.Opengl.LTexture.Format format)
        {
            uint      color = height.GetRGB();
            LImage    tmp   = LImage.CreateImage(res);
            LImage    image = LImage.CreateImage(tmp.GetWidth(), tmp.GetHeight(), true);
            LGraphics g     = image.GetLGraphics();

            g.DrawImage(tmp, 0, 0);
            g.Dispose();
            if (tmp != null)
            {
                tmp.Dispose();
                tmp = null;
            }
            Color[] pixels = image.GetPixels();
            int     size   = pixels.Length;

            for (int i = 0; i < size; i++)
            {
                if (pixels[i].PackedValue == color)
                {
                    pixels[i].PackedValue = LSystem.TRANSPARENT;
                }
            }
            image.SetFormat(format);
            image.SetPixels(pixels, image.GetWidth(), image.GetHeight());
            LTexture texture = image.GetTexture();

            if (image != null)
            {
                image.Dispose();
                image = null;
            }
            return(texture);
        }
Пример #3
0
        public virtual LImage SetTileBackground(LImage image, bool isReturn)
        {
            if (image == null)
            {
                return(null);
            }
            int layerWidth  = GetWidth();
            int layerHeight = GetHeight();
            int tileWidth   = image.GetWidth();
            int tileHeight  = image.GetHeight();

            LImage    tempImage = LImage.CreateImage(layerWidth, layerHeight, false);
            LGraphics g         = tempImage.GetLGraphics();

            for (int x = 0; x < layerWidth; x += tileWidth)
            {
                for (int y = 0; y < layerHeight; y += tileHeight)
                {
                    g.DrawImage(image, x, y);
                }
            }
            g.Dispose();
            if (isReturn)
            {
                return(tempImage);
            }
            tempImage.SetFormat(Loon.Core.Graphics.Opengl.LTexture.Format.SPEED);
            SetBackground(tempImage.GetTexture());
            if (tempImage != null)
            {
                tempImage.Dispose();
                tempImage = null;
            }
            return(null);
        }
Пример #4
0
 public static Polygon MakePolygon(LImage image)
 {
     if (image == null)
     {
         throw new RuntimeException("Image is null !");
     }
     return(MakePolygon(image.GetIntPixels(), image.GetWidth(),
                        image.GetHeight()));
 }
Пример #5
0
 public static LTexture.Mask CreateMask(LImage image)
 {
     if (image == null)
     {
         throw new RuntimeException("Image is null !");
     }
     return(CreateMask(image.GetIntPixels(), image.GetWidth(),
                       image.GetHeight()));
 }
Пример #6
0
 internal PackEntry(LImage image)
 {
     this.image = image;
     if (image != null)
     {
         this.fileName = image.GetPath();
         this.width    = image.GetWidth();
         this.height   = image.GetHeight();
     }
 }
Пример #7
0
 public LTexture Pack(Loon.Core.Graphics.Opengl.LTexture.Format format)
 {
     if (texture != null && !packing)
     {
         return(texture);
     }
     if (fileName != null)
     {
         texture       = new LTexture(GLLoader.GetTextureData(fileName), format);
         texture.isExt = true;
     }
     else
     {
         LImage image = PackImage();
         if (image == null)
         {
             return(null);
         }
         if (texture != null)
         {
             texture.Destroy();
             texture = null;
         }
         if (colorMask != null)
         {
             Color[] pixels = image.GetPixels();
             int     size   = pixels.Length;
             uint    color  = colorMask.GetRGB();
             for (int i = 0; i < size; i++)
             {
                 if (pixels[i].PackedValue == color)
                 {
                     pixels[i].PackedValue = LSystem.TRANSPARENT;
                 }
             }
             image.SetPixels(pixels, image.GetWidth(), image.GetHeight());
         }
         texture       = new LTexture(GLLoader.GetTextureData(image), format);
         texture.isExt = true;
         if (image != null)
         {
             image.Dispose();
             image = null;
         }
     }
     return(texture);
 }
Пример #8
0
 public int PutImage(string name, LImage image)
 {
     CheckPacked();
     if (image == null)
     {
         throw new NullReferenceException();
     }
     if (image.GetWidth() <= 0 || image.GetHeight() <= 0)
     {
         throw new ArgumentException(
                   "width and height must be positive");
     }
     this.temps.Put(name, new PackEntry(image));
     this.packing = true;
     this.count++;
     return(temps.Size() - 1);
 }
Пример #9
0
        public static LImage GetResize(LImage image, int w, int h)
        {
            if (image == null)
            {
                return(null);
            }
            if (image.width == w && image.height == h)
            {
                return(image);
            }
            LImage    result = LImage.CreateImage(w, h, image.HasAlpha());
            LGraphics g      = result.GetLGraphics();

            g.DrawImage(image, 0, 0, w, h, 0, 0, image.GetWidth(),
                        image.GetHeight());
            g.Dispose();
            return(result);
        }
Пример #10
0
        public static LTexture FilterLimitColor(string res, LColor start,
                                                LColor end, Loon.Core.Graphics.Opengl.LTexture.Format format)
        {
            int       sred   = start.R;
            int       sgreen = start.G;
            int       sblue  = start.B;
            int       ered   = end.R;
            int       egreen = end.G;
            int       eblue  = end.B;
            LImage    tmp    = LImage.CreateImage(res);
            LImage    image  = LImage.CreateImage(tmp.GetWidth(), tmp.GetHeight(), true);
            LGraphics g      = image.GetLGraphics();

            g.DrawImage(tmp, 0, 0);
            g.Dispose();
            if (tmp != null)
            {
                tmp.Dispose();
                tmp = null;
            }
            Color[] pixels = image.GetPixels();
            int     size   = pixels.Length;

            for (int i = 0; i < size; i++)
            {
                Color pixel = pixels[i];
                if ((pixel.R >= sred && pixel.G >= sgreen && pixel.B >= sblue) &&
                    (pixel.R <= ered && pixel.G <= egreen && pixel.B <= eblue))
                {
                    pixels[i].PackedValue = LSystem.TRANSPARENT;
                }
            }
            image.SetFormat(format);
            image.SetPixels(pixels, image.GetWidth(), image.GetHeight());
            LTexture texture = image.GetTexture();

            if (image != null)
            {
                image.Dispose();
                image = null;
            }
            return(texture);
        }
Пример #11
0
            internal PackEntry(LImage image)
            {
				this.image = image;
				if (image != null) {
					this.fileName = image.GetPath();
					this.width = image.GetWidth();
					this.height = image.GetHeight();
				}
			}
Пример #12
0
		public int PutImage(string name, LImage image) {
			CheckPacked();
			if (image == null) {
				throw new NullReferenceException();
			}
			if (image.GetWidth() <= 0 || image.GetHeight() <= 0) {
				throw new ArgumentException(
						"width and height must be positive");
			}
			this.temps.Put(name, new PackEntry(image));
			this.packing = true;
			this.count++;
			return temps.Size() - 1;
		}
Пример #13
0
        private void InitDesktop()
        {
            if (desktop != null && sprites != null)
            {
                return;
            }
            this.desktop = new Desktop(this, GetWidth(), GetHeight());
            this.sprites = new Sprites(GetWidth(), GetHeight());
            if (dialog == null)
            {
                LImage tmp = LImage.CreateImage(GetWidth() - 20,
                                                GetHeight() / 2 - 20, true);
                LGraphics g = tmp.GetLGraphics();
                g.SetColor(0, 0, 0, 125);
                g.FillRect(0, 0, tmp.GetWidth(), tmp.GetHeight());
                g.Dispose();
                g      = null;
                dialog = new LTexture(GLLoader.GetTextureData(tmp));
                if (tmp != null)
                {
                    tmp.Dispose();
                    tmp = null;
                }
            }
            this.message = new LMessage(dialog, 0, 0);
            this.message.SetFontColor(LColor.white);
            int size = message.GetWidth() / (message.GetMessageFont().GetSize());

            if (LSystem.scaleWidth != 1 || LSystem.scaleHeight != 1)
            {
                if (size % 2 != 0)
                {
                    size = size + 2;
                }
                else
                {
                    size = size + 3;
                }
            }
            else
            {
                if (size % 2 != 0)
                {
                    size = size - 3;
                }
                else
                {
                    size = size - 4;
                }
            }
            this.message.SetMessageLength(size);
            this.message.SetLocation((GetWidth() - message.GetWidth()) / 2,
                                     GetHeight() - message.GetHeight() - 10);
            this.message.SetVisible(false);
            this.select = new LSelect(dialog, 0, 0);
            this.select.SetLocation(message.X(), message.Y());
            this.scrCG = new AVGCG();
            this.desktop.Add(message);
            this.desktop.Add(select);
            this.select.SetVisible(false);
        }
Пример #14
0
        public PShadowEffect(LImage img, LImage back, int x, int y, int w, int h)
        {
            if (deasilTrans == null || widdershinTrans == null)
            {
                deasilTrans = new Color[max_pixel];
                for (int i = 0; i < max_pixel; i++)
                {
                    deasilTrans[i] = new Color(i, i, i);
                }
                int count = 0;
                widdershinTrans = new Color[max_pixel];
                for (int i = 0; i < max_pixel; i++)
                {
                    widdershinTrans[count++] = deasilTrans[i];
                }
            }
            this.SetLocation(x, y);
            this.width   = w;
            this.height  = h;
            this.visible = true;
            LImage temp = null;

            if (back == null)
            {
                this.scaleWidth      = width / 2;
                this.scaleHeight     = height / 2;
                temp                 = GraphicsUtils.GetResize(img, scaleWidth, scaleHeight);
                this.image           = LImage.CreateImage(scaleWidth, scaleHeight, true);
                this.finalDrawPixels = temp.GetPixels();
                this.nowDrawPixels   = (Color[])CollectionUtils.CopyOf(finalDrawPixels);
                if (temp != null)
                {
                    temp.Dispose();
                    temp = null;
                }
            }
            else
            {
                this.scaleWidth  = width / 2;
                this.scaleHeight = height / 2;
                temp             = GraphicsUtils.GetResize(img, scaleWidth, scaleHeight);
                this.image       = LImage.CreateImage(scaleWidth, scaleHeight, true);
                if (back.GetWidth() == scaleWidth &&
                    back.GetHeight() == scaleHeight)
                {
                    this.finalBackgroundPixels = back.GetPixels();
                    this.backgroundPixels      = (Color[])CollectionUtils
                                                 .CopyOf(finalBackgroundPixels);
                }
                else
                {
                    LImage tmp = GraphicsUtils.GetResize(back, scaleWidth,
                                                         scaleHeight);
                    this.finalBackgroundPixels = tmp.GetPixels();
                    if (tmp != null)
                    {
                        tmp.Dispose();
                        tmp = null;
                    }
                    this.backgroundPixels = (Color[])CollectionUtils
                                            .CopyOf(finalBackgroundPixels);
                }
                this.finalDrawPixels = temp.GetPixels();
                this.nowDrawPixels   = (Color[])CollectionUtils.CopyOf(finalDrawPixels);
            }
            this.SetBlackToWhite(flag);
            if (temp != null)
            {
                temp.Dispose();
                temp = null;
            }
            if (img != null)
            {
                img.Dispose();
                img = null;
            }
            if (back != null)
            {
                back.Dispose();
                back = null;
            }
        }
Пример #15
0
 public PShadowEffect(LImage img, LImage back, int x, int y)
     : this(img, back, x, y, img.GetWidth(), img.GetHeight())
 {
 }
Пример #16
0
        public virtual LImage SetTileBackground(LImage image, bool isReturn)
        {
            if (image == null)
            {
                return null;
            }
            int layerWidth = GetWidth();
            int layerHeight = GetHeight();
            int tileWidth = image.GetWidth();
            int tileHeight = image.GetHeight();

            LImage tempImage = LImage.CreateImage(layerWidth, layerHeight, false);
            LGraphics g = tempImage.GetLGraphics();
            for (int x = 0; x < layerWidth; x += tileWidth)
            {
                for (int y = 0; y < layerHeight; y += tileHeight)
                {
                    g.DrawImage(image, x, y);
                }
            }
            g.Dispose();
            if (isReturn)
            {
                return tempImage;
            }
            tempImage.SetFormat(Loon.Core.Graphics.Opengl.LTexture.Format.SPEED);
            SetBackground(tempImage.GetTexture());
            if (tempImage != null)
            {
                tempImage.Dispose();
                tempImage = null;
            }
            return null;
        }