示例#1
0
 public int GetTileID(int x, int y)
 {
     if (x >= 0 && x < field.GetWidth() && y >= 0 && y < field.GetHeight())
     {
         return(field.GetType(y, x));
     }
     else
     {
         return(-1);
     }
 }
示例#2
0
 public void Convert(Field2D field, int ins0, int xout)
 {
     for (int xp = 0; xp < this.width; xp++)
     {
         for (int yp = 0; yp < this.height; yp++)
         {
             if (field.GetType(this.x + xp, this.y + yp) == ins0)
             {
                 field.SetType(this.x + xp, this.y + yp, xout);
             }
         }
     }
 }
示例#3
0
 public void Convert(Field2D field, int ins0, int xout)
 {
     for (int xp = 0; xp < this.width; xp++)
     {
         for (int yp = 0; yp < this.height; yp++)
         {
             if (field.GetType(this.x + xp, this.y + yp) == ins0)
             {
                 field.SetType(this.x + xp, this.y + yp, xout);
             }
         }
     }
 }
示例#4
0
文件: LLayer.cs 项目: keppelcao/LGame
        public virtual void SetField2DBackground(Field2D field, Dictionary<object, object> pathMap,
                string fileName)
        {
            SetField2D(field);
            LImage background = null;

            if (fileName != null)
            {
                LImage tmp = LImage.CreateImage(fileName);
                background = SetTileBackground(tmp, true);
                if (tmp != null)
                {
                    tmp.Dispose();
                    tmp = null;
                }
            }
            else
            {
                background = LImage.CreateImage(GetWidth(), GetHeight(), false);
            }
            int srcWidth = GetWidth();
            int srcHeight = GetHeight();
            //在C#环境下LGraphics采取像素渲染,得不到硬件加速,此处直接将像素操作方法粘过来了(虽然也快不了几毫秒……)
            int[] dstColors = background.GetIntPixels();
            int[] srcColors = null;
            for (int i = 0; i < field.GetWidth(); i++)
            {
                for (int j = 0; j < field.GetHeight(); j++)
                {
                    int index = field.GetType(j, i);
                    object o = CollectionUtils.Get(pathMap, index);
                    if (o != null)
                    {
                        if (o is LImage)
                        {
                            LImage img = (LImage)o;
                            srcColors = img.GetIntPixels();
                            int w = img.Width;
                            int h = img.Height;
                            int y = field.TilesToHeightPixels(j);
                            int x = field.TilesToWidthPixels(i);
                            if (x < 0)
                            {
                                w += x;
                                x = 0;
                            }
                            if (y < 0)
                            {
                                h += y;
                                y = 0;
                            }
                            if (x + w > srcWidth)
                            {
                                w = srcWidth - x;
                            }
                            if (y + h > srcHeight)
                            {
                                h = srcHeight - y;
                            }
                            if (img.hasAlpha)
                            {
                                int findIndex = y * srcWidth + x;
                                int drawIndex = 0;
                                int moveFind = srcWidth - w;
                                for (int col = 0; col < h; col++)
                                {
                                    for (int row = 0; row < w; )
                                    {
                                        if (srcColors[drawIndex] != 0)
                                        {
                                            dstColors[findIndex] = srcColors[drawIndex];
                                        }
                                        row++;
                                        findIndex++;
                                        drawIndex++;
                                    }
                                    findIndex += moveFind;
                                }
                            }
                            else
                            {
                                for (int size = 0; size < h; size++)
                                {
                                    System.Array.Copy(srcColors, size * w, dstColors,
                                                     (y + size) * srcWidth + x, w);
                                }
                            }
                        }
                        else if (o is Actor)
                        {
                            AddObject(((Actor)o), field.TilesToWidthPixels(i),
                                    field.TilesToHeightPixels(j));
                        }
                    }
                }
            }
            background.SetIntPixels(dstColors);
            background.SetFormat(Loon.Core.Graphics.Opengl.LTexture.Format.SPEED);
            SetBackground(background.GetTexture());
            srcColors = null;
            dstColors = null;
            if (background != null)
            {
                background.Dispose();
                background = null;
            }
        }
示例#5
0
        public void SetField2DBackground(Field2D field, Dictionary<object, object> pathMap,
                String fileName)
        {
            SetField2D(field);
            LPixmap background = null;

            if (fileName != null)
            {
                LPixmap tmp = new LPixmap(fileName);
                background = SetTileBackground(tmp, true);
                if (tmp != null)
                {
                    tmp.Dispose();
                    tmp = null;
                }
            }
            else
            {
                background = new LPixmap(GetWidth(), GetHeight(), false);
            }

            for (int i = 0; i < field.GetWidth(); i++)
            {
                for (int j = 0; j < field.GetHeight(); j++)
                {
                    int index = field.GetType(j, i);
                    Object o = CollectionUtils.Get(pathMap, index);
                    if (o != null)
                    {
                        if (o is LPixmap)
                        {
                            background.DrawPixmap(((LPixmap)o), field.TilesToWidthPixels(i),
                                    field.TilesToHeightPixels(j));
                        }
                        else if (o is Actor)
                        {
                            AddObject(((Actor)o), field.TilesToWidthPixels(i),
                                    field.TilesToHeightPixels(j));
                        }
                    }
                }
            }
            SetBackground(background.Texture);
            if (background != null)
            {
                background.Dispose();
                background = null;
            }
        }