コード例 #1
0
        void pnlMap_Paint(object sender, PaintEventArgs e)
        {
            Size gridCellSize = new Size(128, 128);
            Pen  p            = new Pen(System.Drawing.Color.Yellow);

            switch (loadedRSDKver)
            {
            case 0:
                if (_RSDK4Level == null)
                {
                    return;
                }
                e.Graphics.Clear(Color.FromArgb(255, 255, 0, 255));
                Rectangle viewport4 = new Rectangle(-pnlMap.AutoScrollPosition.X, -pnlMap.AutoScrollPosition.Y, pnlMap.Width, pnlMap.Height);
                int       startX4   = (viewport4.X / 128) - 1;
                if (startX4 < 0)
                {
                    startX4 = 0;
                }
                int startY4 = (viewport4.Y / 128) - 1;
                if (startY4 < 0)
                {
                    startY4 = 0;
                }
                int endX4 = startX4 + (pnlMap.Width / 128) + 1;
                int endY4 = startY4 + (pnlMap.Height / 128) + 1;
                for (int y = startY4; y < endY4; y++)
                {
                    for (int x = startX4; x < endX4; x++)
                    {
                        if (y < _RSDK4Level.MapLayout.Length && x < _RSDK4Level.MapLayout[y].Length && _RSDK4Level.MapLayout[y][x] < _RSDK4Chunks.BlockList.Count)
                        {
                            if (e.ClipRectangle.IntersectsWith(new Rectangle(x * 128, y * 128, 128, 128)))
                            {
                                if (ShowMap)
                                {
                                    if (_RSDK4Level.MapLayout[y][x] > 0)
                                    {
                                        e.Graphics.DrawImageUnscaled(Chunks[_RSDK4Level.MapLayout[y][x]], x * 128, y * 128);
                                    }
                                    else
                                    {
                                    }
                                }
                                if (ShowCollision)
                                {
                                }
                                if (ShowObjects)
                                {
                                }
                            }
                        }
                    }
                }
                if (ShowObjects)     //Heh, It works now :)
                {
                    for (int o = 0; o < _RSDK4Level.objects.Count; o++)
                    {
                        if (e.ClipRectangle.IntersectsWith(new Rectangle(_RSDK4Level.objects[o].xPos, _RSDK4Level.objects[o].yPos, viewport4.Width, viewport4.Height)))
                        {
                            Object_Definitions.MapObject mapobj = RSObjects.GetObjectByType(_RSDK4Level.objects[o].type, _RSDK4Level.objects[o].subtype);
                            if (mapobj != null && mapobj.ID > 0)
                            {
                                e.Graphics.DrawImageUnscaled(mapobj.RenderObject(loadedRSDKver, datapath), _RSDK4Level.objects[o].xPos, _RSDK4Level.objects[o].yPos);
                            }
                            else
                            {
                                e.Graphics.DrawImage(RetroED.Properties.Resources.OBJ, _RSDK4Level.objects[o].xPos, _RSDK4Level.objects[o].yPos);
                            }
                        }
                    }
                }
                if (ShowGrid)
                {
                    Pen pen = new Pen(Color.DarkGray);

                    if (gridCellSize.Width >= 8 && gridCellSize.Height >= 8)
                    {
                        int lft = 0 % gridCellSize.Width;
                        int top = 0 % gridCellSize.Height;

                        for (int i = 0; i <= _RSDK4Level.width * 128; ++i)
                        {
                            e.Graphics.DrawLine(pen, lft + i * gridCellSize.Width, 0, lft + i * gridCellSize.Width, _RSDK4Level.height * 128);
                        }

                        for (int j = 0; j <= _RSDK4Level.height * 128; ++j)
                        {
                            e.Graphics.DrawLine(pen, 0, top + j * gridCellSize.Height, _RSDK4Level.width * 128, top + j * gridCellSize.Height);
                        }
                    }
                }
                e.Graphics.DrawRectangle(p, new Rectangle(tilePoint.X * 128, tilePoint.Y * 128, 128, 128));
                break;

            case 1:
                if (_RSDK3Level == null)
                {
                    return;
                }
                e.Graphics.Clear(Color.FromArgb(255, 255, 0, 255));
                Rectangle viewport3 = new Rectangle(-pnlMap.AutoScrollPosition.X, -pnlMap.AutoScrollPosition.Y, pnlMap.Width, pnlMap.Height);
                int       startX3   = (viewport3.X / 128) - 1;
                if (startX3 < 0)
                {
                    startX3 = 0;
                }
                int startY3 = (viewport3.Y / 128) - 1;
                if (startY3 < 0)
                {
                    startY3 = 0;
                }
                int endX3 = startX3 + (pnlMap.Width / 128) + 1;
                int endY3 = startY3 + (pnlMap.Height / 128) + 1;
                for (int y = startY3; y < endY3; y++)
                {
                    for (int x = startX3; x < endX3; x++)
                    {
                        if (y < _RSDK3Level.MapLayout.Length && x < _RSDK3Level.MapLayout[y].Length && _RSDK3Level.MapLayout[y][x] < _RSDK3Chunks.BlockList.Count)
                        {
                            if (e.ClipRectangle.IntersectsWith(new Rectangle(x * 128, y * 128, 128, 128)))
                            {
                                if (ShowMap)
                                {
                                    if (_RSDK3Level.MapLayout[y][x] > 0)
                                    {
                                        e.Graphics.DrawImageUnscaled(Chunks[_RSDK3Level.MapLayout[y][x]], x * 128, y * 128);
                                    }
                                    else
                                    {
                                    }
                                }
                                if (ShowCollision)
                                {
                                }
                            }
                        }
                    }
                }
                if (ShowObjects)     //Heh, It works now :)
                {
                    for (int o = 0; o < _RSDK3Level.objects.Count; o++)
                    {
                        if (e.ClipRectangle.IntersectsWith(new Rectangle(_RSDK3Level.objects[o].xPos, _RSDK3Level.objects[o].yPos, viewport3.Width, viewport3.Height)))
                        {
                            Object_Definitions.MapObject mapobj = RSObjects.GetObjectByType(_RSDK3Level.objects[o].type, _RSDK3Level.objects[o].subtype);
                            if (mapobj != null && mapobj.ID > 0)
                            {
                                e.Graphics.DrawImageUnscaled(mapobj.RenderObject(loadedRSDKver, datapath), _RSDK3Level.objects[o].xPos, _RSDK3Level.objects[o].yPos);
                            }
                            else
                            {
                                e.Graphics.DrawImage(RetroED.Properties.Resources.OBJ, _RSDK3Level.objects[o].xPos, _RSDK3Level.objects[o].yPos);
                            }
                        }
                    }
                }
                if (ShowGrid)
                {
                    Pen pen = new Pen(Color.DarkGray);

                    if (gridCellSize.Width >= 8 && gridCellSize.Height >= 8)
                    {
                        int lft = 0 % gridCellSize.Width;
                        int top = 0 % gridCellSize.Height;

                        for (int i = 0; i <= _RSDK3Level.width * 128; ++i)
                        {
                            e.Graphics.DrawLine(pen, lft + i * gridCellSize.Width, 0, lft + i * gridCellSize.Width, _RSDK3Level.height * 128);
                        }

                        for (int j = 0; j <= _RSDK3Level.height * 128; ++j)
                        {
                            e.Graphics.DrawLine(pen, 0, top + j * gridCellSize.Height, _RSDK3Level.width * 128, top + j * gridCellSize.Height);
                        }
                    }
                }
                e.Graphics.DrawRectangle(p, new Rectangle(tilePoint.X * 128, tilePoint.Y * 128, 128, 128));
                break;

            case 2:
                if (_RSDK2Level == null)
                {
                    return;
                }
                e.Graphics.Clear(Color.FromArgb(255, 255, 0, 255));
                Rectangle viewport2 = new Rectangle(-pnlMap.AutoScrollPosition.X, -pnlMap.AutoScrollPosition.Y, pnlMap.Width, pnlMap.Height);
                int       startX2   = (viewport2.X / 128) - 1;
                if (startX2 < 0)
                {
                    startX2 = 0;
                }
                int startY2 = (viewport2.Y / 128) - 1;
                if (startY2 < 0)
                {
                    startY2 = 0;
                }
                int endX2 = startX2 + (pnlMap.Width / 128) + 1;
                int endY2 = startY2 + (pnlMap.Height / 128) + 1;
                for (int y = startY2; y < endY2; y++)
                {
                    for (int x = startX2; x < endX2; x++)
                    {
                        if (y < _RSDK2Level.MapLayout.Length && x < _RSDK2Level.MapLayout[y].Length && _RSDK2Level.MapLayout[y][x] < _RSDK2Chunks.BlockList.Count)
                        {
                            if (e.ClipRectangle.IntersectsWith(new Rectangle(x * 128, y * 128, 128, 128)))
                            {
                                if (ShowMap)
                                {
                                    if (_RSDK2Level.MapLayout[y][x] > 0)
                                    {
                                        e.Graphics.DrawImageUnscaled(Chunks[_RSDK2Level.MapLayout[y][x]], x * 128, y * 128);
                                    }
                                    else
                                    {
                                    }
                                }
                                if (ShowCollision)
                                {
                                }
                            }
                        }
                    }
                }
                if (ShowObjects)     //Heh, It works now :)
                {
                    for (int o = 0; o < _RSDK2Level.objects.Count; o++)
                    {
                        if (e.ClipRectangle.IntersectsWith(new Rectangle(_RSDK2Level.objects[o].xPos, _RSDK2Level.objects[o].yPos, viewport2.Width, viewport2.Height)))
                        {
                            Object_Definitions.MapObject mapobj = RSObjects.GetObjectByType(_RSDK2Level.objects[o].type, _RSDK2Level.objects[o].subtype);
                            if (mapobj != null && mapobj.ID > 0)
                            {
                                e.Graphics.DrawImageUnscaled(mapobj.RenderObject(loadedRSDKver, datapath), _RSDK2Level.objects[o].xPos, _RSDK2Level.objects[o].yPos);
                            }
                            else
                            {
                                e.Graphics.DrawImage(RetroED.Properties.Resources.OBJ, _RSDK2Level.objects[o].xPos, _RSDK2Level.objects[o].yPos);
                            }
                            //Console.WriteLine(o);
                        }
                    }
                }
                if (ShowGrid)
                {
                    Pen pen = new Pen(Color.DarkGray);

                    if (gridCellSize.Width >= 8 && gridCellSize.Height >= 8)
                    {
                        int lft = 0 % gridCellSize.Width;
                        int top = 0 % gridCellSize.Height;

                        for (int i = 0; i <= _RSDK2Level.width * 128; ++i)
                        {
                            e.Graphics.DrawLine(pen, lft + i * gridCellSize.Width, 0, lft + i * gridCellSize.Width, _RSDK2Level.height * 128);
                        }

                        for (int j = 0; j <= _RSDK2Level.height * 128; ++j)
                        {
                            e.Graphics.DrawLine(pen, 0, top + j * gridCellSize.Height, _RSDK2Level.width * 128, top + j * gridCellSize.Height);
                        }
                    }
                }
                e.Graphics.DrawRectangle(p, new Rectangle(tilePoint.X * 128, tilePoint.Y * 128, 128, 128));
                break;

            case 3:
                if (_RSDK1Level == null)
                {
                    return;                          //We're not going to draw a level if we don't have one lol!
                }
                if (PanelMap != null)
                {
                    PanelMap.Dispose();
                }                                                   //Delet this, We don't need it anymore
                e.Graphics.Clear(Color.FromArgb(255, 255, 0, 255)); //Fill the "Canvas" with the colour FF00FF
                //Setup the viewport, this defines where on the map we are (I think)
                Rectangle viewport1 = new Rectangle(-pnlMap.AutoScrollPosition.X, -pnlMap.AutoScrollPosition.Y, pnlMap.Width, pnlMap.Height);
                int       startX1   = (viewport1.X / 128) - 1; //Where to start drawing (Xpos)
                if (startX1 < 0)
                {
                    startX1 = 0;
                }
                int startY1 = (viewport1.Y / 128) - 1;     //Where to start drawing (Ypos)
                if (startY1 < 0)
                {
                    startY1 = 0;
                }
                int endX1 = startX1 + (pnlMap.Width / 128) + 1;     //Where to Stop drawing (Xpos)
                int endY1 = startY1 + (pnlMap.Height / 128) + 1;    //Where to Stop drawing (Ypos)
                for (int y = startY1; y < endY1; y++)
                {
                    for (int x = startX1; x < endX1; x++)
                    {
                        if (y < _RSDK1Level.MapLayout.Length && x < _RSDK1Level.MapLayout[y].Length && _RSDK1Level.MapLayout[y][x] < _RSDK1Chunks.BlockList.Count)
                        {
                            // Draw the map, line by line!

                            //if (e.ClipRectangle.IntersectsWith(new Rectangle(0, 0, viewport1.Width, viewport1.Height)))
                            if (e.ClipRectangle.IntersectsWith(new Rectangle(x * 128, y * 128, 128, 128)))
                            {
                                if (ShowMap)                                                                                 //Check if the user wants to show the map
                                {
                                    if (_RSDK1Level.MapLayout[y][x] > 0)                                                     //Don't draw Chunk Zero, It's always transparent!
                                    {
                                        e.Graphics.DrawImageUnscaled(Chunks[_RSDK1Level.MapLayout[y][x]], x * 128, y * 128); //Draw the chunk to the map!
                                    }
                                    else
                                    {
                                    }
                                }
                                if (ShowCollision)
                                {
                                    //in future this will show the collision masks of the tiles
                                }
                            }
                        }
                    }
                }
                if (ShowObjects)     //Heh, It works now :)
                {
                    for (int o = 0; o < _RSDK1Level.objects.Count; o++)
                    {
                        if (e.ClipRectangle.IntersectsWith(new Rectangle(_RSDK1Level.objects[o].xPos, _RSDK1Level.objects[o].yPos, viewport1.Width, viewport1.Height)))
                        {
                            Object_Definitions.MapObject mapobj = RSObjects.GetObjectByType(_RSDK1Level.objects[o].type, _RSDK1Level.objects[o].subtype);
                            if (mapobj != null && mapobj.ID > 0)
                            {
                                e.Graphics.DrawImageUnscaled(mapobj.RenderObject(loadedRSDKver, datapath), _RSDK1Level.objects[o].xPos, _RSDK1Level.objects[o].yPos);
                            }
                            else
                            {
                                e.Graphics.DrawImage(RetroED.Properties.Resources.OBJ, _RSDK1Level.objects[o].xPos, _RSDK1Level.objects[o].yPos);
                            }
                            //Console.WriteLine(o);
                        }
                    }
                }
                if (ShowGrid)     //If we want a grid, then draw it over the map
                {
                    Pen pen = new Pen(Color.DarkGray);

                    if (gridCellSize.Width >= 8 && gridCellSize.Height >= 8)
                    {
                        int lft = 0 % gridCellSize.Width;
                        int top = 0 % gridCellSize.Height;

                        for (int i = 0; i <= _RSDK1Level.width * 128; ++i)
                        {
                            e.Graphics.DrawLine(pen, lft + i * gridCellSize.Width, 0, lft + i * gridCellSize.Width, _RSDK1Level.height * 128);
                        }

                        for (int j = 0; j <= _RSDK1Level.height * 128; ++j)
                        {
                            e.Graphics.DrawLine(pen, 0, top + j * gridCellSize.Height, _RSDK1Level.width * 128, top + j * gridCellSize.Height);
                        }
                    }
                }
                Pen PSpen = new Pen(Color.White);                                                           //We want the player spawn circle to be white!
                e.Graphics.DrawRectangle(p, new Rectangle(tilePoint.X * 128, tilePoint.Y * 128, 128, 128)); //Draw the selected tile!
                e.Graphics.DrawEllipse(PSpen, _RSDK1Level.PlayerXpos, _RSDK1Level.PlayerYPos, 32, 32);      //Draw Spawn Circle
                break;

            default:
                break;
            }
        }
コード例 #2
0
        public void LoadObjList(string filePath)
        {
            Objects.Clear();
            System.IO.StreamReader reader = new System.IO.StreamReader(filePath);
            string Name          = "";
            string Type          = "";
            string SubType       = "";
            string ImagePath     = "";
            string SpriteImgXpos = "";
            string SpriteImgYpos = "";
            string SpriteWidth   = "";
            string SpriteHeight  = "";
            char   buf           = '>';
            int    T;
            int    ST;
            int    Xpos;
            int    Ypos;
            int    Width;
            int    Height;


            while (!reader.EndOfStream)
            {
                Name          = "";
                Type          = "";
                SubType       = "";
                ImagePath     = "";
                SpriteImgXpos = "";
                SpriteImgYpos = "";
                SpriteWidth   = "";
                SpriteHeight  = "";
                buf           = '>';
                T             = 0;
                ST            = 0;
                Xpos          = 0;
                Ypos          = 0;
                Width         = 0;
                Height        = 0;

                while (buf != ',') //Load The name
                {
                    buf = (char)reader.Read();
                    if (buf == ',')
                    {
                        break;
                    }
                    Name = Name + buf;
                }
                buf = '>';         //That char shouldn't show up so change the buffer to that!

                while (buf != ',') //Load The Object Type
                {
                    buf = (char)reader.Read();
                    if (buf == ',')
                    {
                        break;
                    }
                    Type = Type + buf;
                }
                buf = '>';         //That char shouldn't show up so change the buffer to that!

                while (buf != ',') //Load The Object SubType
                {
                    buf = (char)reader.Read();
                    if (buf == ',')
                    {
                        break;
                    }
                    SubType = SubType + buf;
                }
                buf = '>';         //That char shouldn't show up so change the buffer to that!

                while (buf != ',') //Load The Object's SpriteSheet
                {
                    buf = (char)reader.Read();
                    if (buf == ',')
                    {
                        break;
                    }
                    ImagePath = ImagePath + buf;
                }
                buf = '>';         //That char shouldn't show up so change the buffer to that!

                while (buf != ',') //Load The Object's Spritesheet Xpos
                {
                    buf = (char)reader.Read();
                    if (buf == ',')
                    {
                        break;
                    }
                    SpriteImgXpos = SpriteImgXpos + buf;
                }
                buf = '>';         //That char shouldn't show up so change the buffer to that!

                while (buf != ',') //Load The Object's Spritesheet Ypos
                {
                    buf = (char)reader.Read();
                    if (buf == ',')
                    {
                        break;
                    }
                    SpriteImgYpos = SpriteImgYpos + buf;
                }
                buf = '>';         //That char shouldn't show up so change the buffer to that!

                while (buf != ',') //Load The Object Sprite's Width
                {
                    buf = (char)reader.Read();
                    if (buf == ',')
                    {
                        break;
                    }
                    SpriteWidth = SpriteWidth + buf;
                }
                buf = '>';         //That char shouldn't show up so change the buffer to that!

                while (buf != ',') //Load The Object Sprite's Height
                {
                    buf = (char)reader.Read();
                    if (buf == ';')
                    {
                        break;
                    }                          //detect if the line is over
                    SpriteHeight = SpriteHeight + buf;
                }
                buf = '>'; //That char shouldn't show up so change the buffer to that!

                T      = Int32.Parse(Type);
                ST     = Int32.Parse(SubType);
                Xpos   = Int32.Parse(SpriteImgXpos);
                Ypos   = Int32.Parse(SpriteImgYpos);
                Width  = Int32.Parse(SpriteWidth);
                Height = Int32.Parse(SpriteHeight);

                MapObject MapObj = new MapObject(Name, T, ST, ImagePath, Xpos, Ypos, Width, Height);
                Objects.Add(new Point(MapObj.ID, MapObj.SubType), MapObj);

                reader.ReadLine();
            }
        }
コード例 #3
0
        public void LoadObjList(string filePath)
        {
            Objects.Clear();
            System.IO.StreamReader reader = new System.IO.StreamReader(filePath);
            string Name          = "";
            string Type          = "";
            string SubType       = "";
            string ImagePath     = "";
            string SpriteImgXpos = "";
            string SpriteImgYpos = "";
            string SpriteWidth   = "";
            string SpriteHeight  = "";
            string pivotX        = "";
            string pivotY        = "";
            string flip          = "";
            char   buf           = '>';
            int    T             = 0;
            int    ST            = 0;
            int    Xpos          = 0;
            int    Ypos          = 0;
            int    Width         = 0;
            int    Height        = 0;
            int    PivotX        = 0;
            int    PivotY        = 0;
            int    Flip          = 0;


            while (!reader.EndOfStream)
            {
                Name          = "";
                Type          = "";
                SubType       = "";
                ImagePath     = "";
                SpriteImgXpos = "";
                SpriteImgYpos = "";
                SpriteWidth   = "";
                SpriteHeight  = "";
                pivotX        = "";
                pivotY        = "";
                flip          = "";
                buf           = '>';
                T             = 0;
                ST            = 0;
                Xpos          = 0;
                Ypos          = 0;
                Width         = 0;
                Height        = 0;

                while (buf != ',') //Load The name
                {
                    buf = (char)reader.Read();
                    if (buf == ',')
                    {
                        break;
                    }
                    Name = Name + buf;
                }
                buf = '>';         //That char shouldn't show up so change the buffer to that!

                while (buf != ',') //Load The Object Type
                {
                    buf = (char)reader.Read();
                    if (buf == ',')
                    {
                        break;
                    }
                    Type = Type + buf;
                }
                buf = '>';         //That char shouldn't show up so change the buffer to that!

                while (buf != ',') //Load The Object SubType
                {
                    buf = (char)reader.Read();
                    if (buf == ',')
                    {
                        break;
                    }
                    SubType = SubType + buf;
                }
                buf = '>';         //That char shouldn't show up so change the buffer to that!

                while (buf != ',') //Load The Object's SpriteSheet
                {
                    buf = (char)reader.Read();
                    if (buf == ',')
                    {
                        break;
                    }
                    ImagePath = ImagePath + buf;
                }
                buf = '>';         //That char shouldn't show up so change the buffer to that!

                while (buf != ',') //Load The Object's Spritesheet Xpos
                {
                    buf = (char)reader.Read();
                    if (buf == ',')
                    {
                        break;
                    }
                    SpriteImgXpos = SpriteImgXpos + buf;
                }
                buf = '>';         //That char shouldn't show up so change the buffer to that!

                while (buf != ',') //Load The Object's Spritesheet Ypos
                {
                    buf = (char)reader.Read();
                    if (buf == ',')
                    {
                        break;
                    }
                    SpriteImgYpos = SpriteImgYpos + buf;
                }
                buf = '>';         //That char shouldn't show up so change the buffer to that!

                while (buf != ',') //Load The Object Sprite's Width
                {
                    buf = (char)reader.Read();
                    if (buf == ',')
                    {
                        break;
                    }
                    SpriteWidth = SpriteWidth + buf;
                }
                buf = '>';         //That char shouldn't show up so change the buffer to that!

                while (buf != ',') //Load The Object Sprite's Height
                {
                    buf = (char)reader.Read();
                    if (buf == ';' || buf == ',')
                    {
                        break;
                    }                                        //detect if the line is over
                    SpriteHeight = SpriteHeight + buf;
                }
                bool Legacy = true;
                if (buf != ';')
                {
                    buf = '>'; Legacy = false;
                }                                           //That char shouldn't show up so change the buffer to that!

                while (buf != ',' && buf != ';' && !Legacy) //Load The Object Sprite's Height
                {
                    buf = (char)reader.Read();
                    if (buf == ';' || buf == ',')
                    {
                        break;
                    }                                        //detect if the line is over
                    pivotX = pivotX + buf;
                }
                if (buf != ';')
                {
                    buf = '>';
                }                                           //That char shouldn't show up so change the buffer to that!

                while (buf != ',' && buf != ';' && !Legacy) //Load The Object Sprite's Height
                {
                    buf = (char)reader.Read();
                    if (buf == ';' || buf == ',')
                    {
                        break;
                    }                                        //detect if the line is over
                    pivotY = pivotY + buf;
                }
                if (buf != ';')
                {
                    buf = '>';
                }                                           //That char shouldn't show up so change the buffer to that!

                while (buf != ',' && buf != ';' && !Legacy) //Load The Object Sprite's Height
                {
                    buf = (char)reader.Read();
                    if (buf == ';')
                    {
                        break;
                    }                          //detect if the line is over
                    flip = flip + buf;
                }
                buf = '>'; //That char shouldn't show up so change the buffer to that!

                T      = Int32.Parse(Type);
                ST     = Int32.Parse(SubType);
                Xpos   = Int32.Parse(SpriteImgXpos);
                Ypos   = Int32.Parse(SpriteImgYpos);
                Width  = Int32.Parse(SpriteWidth);
                Height = Int32.Parse(SpriteHeight);
                if (!Legacy)
                {
                    PivotX = Int32.Parse(pivotX);
                    PivotY = Int32.Parse(pivotY);
                    Flip   = Int32.Parse(flip);
                }
                MapObject MapObj;
                if (Legacy)
                {
                    MapObj = new MapObject(Name, T, ST, ImagePath, Xpos, Ypos, Width, Height);
                    Objects.Add(new Point(MapObj.ID, MapObj.SubType), MapObj);
                }
                else if (!Legacy)
                {
                    MapObj = new MapObject(Name, T, ST, ImagePath, Xpos, Ypos, Width, Height, PivotX, PivotY, Flip);
                    Objects.Add(new Point(MapObj.ID, MapObj.SubType), MapObj);
                }

                reader.ReadLine();
            }
            reader.Close();
        }
コード例 #4
0
        void pnlMap_Paint(object sender, PaintEventArgs e)
        {
            Size gridCellSize = new Size(128, 128);
            Pen  p            = new Pen(System.Drawing.Color.Yellow);

            if (Parent.Scene == null)
            {
                return;
            }
            e.Graphics.Clear(Color.FromArgb(255, 255, 0, 255));
            Rectangle viewport4 = new Rectangle(-pnlMap.AutoScrollPosition.X, -pnlMap.AutoScrollPosition.Y, pnlMap.Width, pnlMap.Height);
            int       startX4   = (viewport4.X / 128) - 1;

            if (startX4 < 0)
            {
                startX4 = 0;
            }
            int startY4 = (viewport4.Y / 128) - 1;

            if (startY4 < 0)
            {
                startY4 = 0;
            }
            int endX4 = startX4 + (pnlMap.Width / 128) + 1;
            int endY4 = startY4 + (pnlMap.Height / 128) + 1;

            for (int y = startY4; y < endY4; y++)
            {
                for (int x = startX4; x < endX4; x++)
                {
                    if (y < Parent.Scene.MapLayout.Length && x < Parent.Scene.MapLayout[y].Length && Parent.Scene.MapLayout[y][x] < Parent.Chunks.ChunkList.Length)
                    {
                        if (e.ClipRectangle.IntersectsWith(new Rectangle(x * 128, y * 128, 128, 128)))
                        {
                            if (ShowMap)
                            {
                                if (Parent.Scene.MapLayout[y][x] > 0)
                                {
                                    e.Graphics.DrawImageUnscaled(Chunks[Parent.Scene.MapLayout[y][x]], x * 128, y * 128);
                                }
                                else
                                {
                                }
                            }
                            if (ShowCollisionA)
                            {
                                ushort Chunk = Parent.Scene.MapLayout[y][x];
                                for (int h = 0; h < 8; h++)
                                {
                                    for (int w = 0; w < 8; w++)
                                    {
                                        if (Parent.Scene.MapLayout[y][x] > 0)
                                        {
                                            int tx, ty;
                                            tx = (x * 8) + w;
                                            ty = (y * 8) + h;

                                            Bitmap cm = CollisionPathA[Parent.Chunks.ChunkList[Chunk].Mappings[h][w].Tile16x16].Clone(new Rectangle(0, 0, 16, 16), System.Drawing.Imaging.PixelFormat.DontCare);

                                            switch (Parent.Chunks.ChunkList[Chunk].Mappings[h][w].Direction)
                                            {
                                            case 0:
                                                cm.RotateFlip(RotateFlipType.RotateNoneFlipNone);
                                                break;

                                            case 1:
                                                cm.RotateFlip(RotateFlipType.RotateNoneFlipX);
                                                break;

                                            case 2:
                                                cm.RotateFlip(RotateFlipType.RotateNoneFlipY);
                                                break;

                                            case 3:
                                                cm.RotateFlip(RotateFlipType.RotateNoneFlipXY);
                                                break;
                                            }

                                            if (Parent.Chunks.ChunkList[Chunk].Mappings[h][w].CollisionFlag0 == 0) //All
                                            {
                                                for (int ix = 0; ix < cm.Width; ix++)
                                                {
                                                    for (int iy = 0; iy < cm.Height; iy++)
                                                    {
                                                        Color gotColor = cm.GetPixel(ix, iy);
                                                        if (gotColor == Color.FromArgb(255, 0, 255, 0))
                                                        {
                                                            cm.SetPixel(ix, iy, Color.FromArgb(255, 255, 255));
                                                        }
                                                    }
                                                }
                                                e.Graphics.DrawImage(cm, (x * 128) + (w * 16), (y * 128) + (h * 16));
                                            }

                                            if (Parent.Chunks.ChunkList[Chunk].Mappings[h][w].CollisionFlag0 == 1 || Parent.Chunks.ChunkList[Chunk].Mappings[h][w].CollisionFlag0 == 4) //Top Only
                                            {
                                                for (int ix = 0; ix < cm.Width; ix++)
                                                {
                                                    for (int iy = 0; iy < cm.Height; iy++)
                                                    {
                                                        Color gotColor = cm.GetPixel(ix, iy);
                                                        if (gotColor == Color.FromArgb(255, 0, 255, 0))
                                                        {
                                                            cm.SetPixel(ix, iy, Color.FromArgb(255, 255, 0));
                                                        }
                                                    }
                                                }
                                                e.Graphics.DrawImage(cm, (x * 128) + (w * 16), (y * 128) + (h * 16));
                                            }

                                            if (Parent.Chunks.ChunkList[Chunk].Mappings[h][w].CollisionFlag0 == 2) //All But Top
                                            {
                                                for (int ix = 0; ix < cm.Width; ix++)
                                                {
                                                    for (int iy = 0; iy < cm.Height; iy++)
                                                    {
                                                        Color gotColor = cm.GetPixel(ix, iy);
                                                        if (gotColor == Color.FromArgb(255, 0, 255, 0))
                                                        {
                                                            cm.SetPixel(ix, iy, Color.FromArgb(255, 0, 0));
                                                        }
                                                    }
                                                }
                                                e.Graphics.DrawImage(cm, (x * 128) + (w * 16), (y * 128) + (h * 16));
                                            }
                                            //cm.Dispose();
                                        }
                                    }
                                }
                            }
                            if (ShowCollisionB)
                            {
                                ushort Chunk = Parent.Scene.MapLayout[y][x];
                                for (int h = 0; h < 8; h++)
                                {
                                    for (int w = 0; w < 8; w++)
                                    {
                                        if (Parent.Scene.MapLayout[y][x] > 0)
                                        {
                                            int tx, ty;
                                            tx = (x * 8) + w;
                                            ty = (y * 8) + h;

                                            Bitmap cm = CollisionPathA[Parent.Chunks.ChunkList[Chunk].Mappings[h][w].Tile16x16].Clone(new Rectangle(0, 0, 16, 16), System.Drawing.Imaging.PixelFormat.DontCare);

                                            switch (Parent.Chunks.ChunkList[Chunk].Mappings[h][w].Direction)
                                            {
                                            case 0:
                                                cm.RotateFlip(RotateFlipType.RotateNoneFlipNone);
                                                break;

                                            case 1:
                                                cm.RotateFlip(RotateFlipType.RotateNoneFlipX);
                                                break;

                                            case 2:
                                                cm.RotateFlip(RotateFlipType.RotateNoneFlipY);
                                                break;

                                            case 3:
                                                cm.RotateFlip(RotateFlipType.RotateNoneFlipXY);
                                                break;
                                            }

                                            if (Parent.Chunks.ChunkList[Chunk].Mappings[h][w].CollisionFlag1 == 0 || Parent.Chunks.ChunkList[Chunk].Mappings[h][w].CollisionFlag1 == 4) //All
                                            {
                                                for (int ix = 0; ix < cm.Width; ix++)
                                                {
                                                    for (int iy = 0; iy < cm.Height; iy++)
                                                    {
                                                        Color gotColor = cm.GetPixel(ix, iy);
                                                        if (gotColor == Color.FromArgb(255, 0, 255, 0))
                                                        {
                                                            cm.SetPixel(ix, iy, Color.FromArgb(255, 255, 255));
                                                        }
                                                    }
                                                }
                                                e.Graphics.DrawImage(cm, (x * 128) + (w * 16), (y * 128) + (h * 16));
                                            }

                                            if (Parent.Chunks.ChunkList[Chunk].Mappings[h][w].CollisionFlag1 == 1) //Top Only
                                            {
                                                for (int ix = 0; ix < cm.Width; ix++)
                                                {
                                                    for (int iy = 0; iy < cm.Height; iy++)
                                                    {
                                                        Color gotColor = cm.GetPixel(ix, iy);
                                                        if (gotColor == Color.FromArgb(255, 0, 255, 0))
                                                        {
                                                            cm.SetPixel(ix, iy, Color.FromArgb(255, 255, 0));
                                                        }
                                                    }
                                                }
                                                e.Graphics.DrawImage(cm, (x * 128) + (w * 16), (y * 128) + (h * 16));
                                            }

                                            if (Parent.Chunks.ChunkList[Chunk].Mappings[h][w].CollisionFlag1 == 2) //All But Top
                                            {
                                                for (int ix = 0; ix < cm.Width; ix++)
                                                {
                                                    for (int iy = 0; iy < cm.Height; iy++)
                                                    {
                                                        Color gotColor = cm.GetPixel(ix, iy);
                                                        if (gotColor == Color.FromArgb(255, 0, 255, 0))
                                                        {
                                                            cm.SetPixel(ix, iy, Color.FromArgb(255, 0, 0));
                                                        }
                                                    }
                                                }
                                                e.Graphics.DrawImage(cm, (x * 128) + (w * 16), (y * 128) + (h * 16));
                                            }
                                            //cm.Dispose();
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            if (ShowObjects) //Heh, It works now :)
            {
                for (int o = 0; o < Parent.Scene.objects.Count; o++)
                {
                    if (e.ClipRectangle.IntersectsWith(new Rectangle(Parent.Scene.objects[o].xPos, Parent.Scene.objects[o].yPos, viewport4.Width, viewport4.Height)))
                    {
                        Object_Definitions.MapObject mapobj = ObjectDefinitions.GetObjectByType(Parent.Scene.objects[o].type, Parent.Scene.objects[o].subtype);
                        if (mapobj != null && mapobj.ID > 0)
                        {
                            Bitmap b = mapobj.RenderObject(Parent.engineType, datapath);
                            e.Graphics.DrawImageUnscaled(b, Parent.Scene.objects[o].xPos + mapobj.PivotX, Parent.Scene.objects[o].yPos + mapobj.PivotX);
                            b.Dispose();
                        }
                        else
                        {
                            Bitmap b = RetroED.Properties.Resources.OBJ;
                            e.Graphics.DrawImage(RetroED.Properties.Resources.OBJ, Parent.Scene.objects[o].xPos - b.Width / 2, Parent.Scene.objects[o].yPos - b.Height / 2);
                            b.Dispose();
                        }
                    }
                }
            }
            if (ShowGrid)
            {
                Pen pen = new Pen(Color.DarkGray);

                if (gridCellSize.Width >= 8 && gridCellSize.Height >= 8)
                {
                    int lft = 0 % gridCellSize.Width;
                    int top = 0 % gridCellSize.Height;

                    for (int i = 0; i <= Parent.Scene.width * 128; ++i)
                    {
                        e.Graphics.DrawLine(pen, lft + i * gridCellSize.Width, 0, lft + i * gridCellSize.Width, Parent.Scene.height * 128);
                    }

                    for (int j = 0; j <= Parent.Scene.height * 128; ++j)
                    {
                        e.Graphics.DrawLine(pen, 0, top + j * gridCellSize.Height, Parent.Scene.width * 128, top + j * gridCellSize.Height);
                    }
                }
            }

            if (Parent.engineType == Retro_Formats.EngineType.RSDKvRS)
            {
                Pen PSpen = new Pen(Color.White);                                                        //We want the player spawn circle to be white!
                e.Graphics.DrawEllipse(PSpen, Parent.Scene.PlayerXpos, Parent.Scene.PlayerYPos, 32, 32); //Draw Spawn Circle
            }

            e.Graphics.DrawRectangle(p, new Rectangle(tilePoint.X * 128, tilePoint.Y * 128, 128, 128)); //Draw the selected tile!

            GC.Collect();
        }