Map tiles calculate

Started by
5 comments, last by bjgamer 9 years, 8 months ago

Hi, i want to make a map editor for some game(not mine)

So it uses some files contains paths of textures the game loads it and draw it as a background

I did that too but now i want convert the texture to list of tiles

I mean the tiles inside the texture

Thats my full code


public void CameraMoved()
        {

            foreach (LoadedTexture t in Textures)
            {
                t.Texture.Dispose();
            }
            Textures.Clear();
            Textures.Capacity = 0;
            int XCoordsToShow = (int)Math.Min(RenderWidth / map.PPuzzle.TileSize/*At the most 256 and some maps use 128*/ + 1, map.PPuzzle.Size.Width);
            int YCoordsToShow = (int)Math.Min(RenderHeight / map.PPuzzle.TileSize + 1, map.PPuzzle.Size.Height);

            int fpx = Camera.X / map.PPuzzle.TileSize;
            int fpy = Camera.Y / map.PPuzzle.TileSize;

            if (bfr != null)
                bfr.Dispose();
            int numberoftiles = (RenderWidth / TileWidth + (RenderWidth % TileWidth)) * (RenderHeight / TileHeight + (RenderWidth % TileHeight));
            bfr = new VertexBuffer(renderMgr.Device, numberoftiles * 20, Usage.None, VertexFormat.PositionRhw | VertexFormat.Diffuse, Pool.Default);
            st = bfr.Lock(0, 0, LockFlags.None);
            primitivecount = 0;
            for (int px = 0; px < XCoordsToShow; px++)
            {
                for (int py = 0; py < YCoordsToShow; py++)
                {
                    int drawX = px;
                    int drawY = py;
                    drawX *= map.PPuzzle.TileSize;
                    drawY *= map.PPuzzle.TileSize;
                    int pzlindex = map.PPuzzle.Entries[px + fpx, py + fpy];
                    string dds = Static.GetANI(Static.ConquerPath + "\\" + map.PPuzzle.ANIPath,
                        pzlindex)[0];
                    LoadedTexture t = new LoadedTexture();
                    t.Texture = Helper.LoadTexture(renderMgr.Device, dds);/*256X256 DDS File*/
                    t.X = drawX;
                    t.Y = drawY;
                    Textures.Add(t);
                    #region TilesInside
                    for (int x = 0; x < map.PPuzzle.TileSize/TileWidth; x++)
                    {
                        for (int y = 0; y < map.PPuzzle.TileSize/TileHeight; y ++)
                        {
                            /*The problem in this 4 numbers
                             * I know its wrong way but i tried other ways and?!
                             */
                            int mapx = x + ((px + fpx)/*Current Puzzle*/+ TileWidth);
                            int mapy = y + ((py + fpy)/*Current Puzzle*/+ TileHeight);
                            int drawx = x + drawX;
                            int drawy = y + drawY;
                            byte[] b = new byte[] { 0/*Blue*/, 0/*Green*/, 255/*Red*/ , 0/*useless*/ };
                            if (map.IsValid((ushort)mapx, (ushort)mapy))
                            {
                                b = new byte[] { 0/*Blue*/, 255/*Green*/, 0/*Red*/ , 0/*useless*/ };
                            }
                            int bgr = BitConverter.ToInt32(b, 0);
                            st.WriteRange(Helper.GetDiamond(drawx, drawy, TileWidth, TileHeight, bgr));
                            primitivecount += 4;
                        }
                    }
                    #endregion
                }
            }
            bfr.Unlock();
        }

the problem is exactly here :


                            int mapx = x + ((px + fpx)/*Current Puzzle*/+ TileWidth);
                            int mapy = y + ((py + fpy)/*Current Puzzle*/+ TileHeight);
                            int drawx = x + drawX;
                            int drawy = y + drawY;

what i want to see(from other viewer) :

9tyss8P.png

what i'm seeing :

WPm9qNU.png

What i want to know is how can i calculate (MapX,MapY) , (ScreenX,ScreenY (I think that will be easier if i knew the map coordinates )) << i feel like i'm programming now xD

Advertisement

bump

From what I can tell you're incrementing all of your loops by one instead of by the size of your tiles (which makes them all draw on top of each other). You want to increment by the size of the tile, ie


for (int dx = 0; dx < size_of_puzzle; dx += size_of_tile_x)
{
   ///logic
}

                    for (int x = 0; x < map.PPuzzle.TileSize / TileWidth; x++)
                    {
                        for (int y = 0; y < map.PPuzzle.TileSize / TileHeight; y++)
                        {
                            int mapx = x + ((px + fpx)/*Current Puzzle*/ * map.PPuzzle.TileSize / TileWidth);
                            int mapy = y + ((py + fpy)/*Current Puzzle*/ * map.PPuzzle.TileSize / TileHeight);
                            int drawx = x  * TileWidth + drawX;
                            int drawy = y * TileHeight + drawY;
                            byte[] b = new byte[] { 0/*Blue*/, 0/*Green*/, 255/*Red*/ , 0/*useless*/ };
                            if (map.IsValid((ushort)(mapx), (ushort)(mapy)))
                            {
                                b = new byte[] { 0/*Blue*/, 255/*Green*/, 0/*Red*/ , 0/*useless*/ };
                            }
                            int bgr = BitConverter.ToInt32(b, 0);
                            st.WriteRange(Helper.GetDiamond(drawx, drawy, TileWidth, TileHeight, bgr));
                            primitivecount += 4;
                        }
                    }

That fixed it but : (

piKvm87.png

As you can see there is something wrong in the map coordinates the bridge tiles should be drawn with green color

In the game if i walked to down

X,Y increased

To up

both decreased

To Right

X increased , Y decreased

To Left

Y increased , X decreased

so i guess its really an isometric map so do i need to deal with this using math

or i just need to transform the buffer

Thanks

I really want to do it myself, but i tried a lot of things nothing worked

I'm talking seriously i spent many hours trying to complete it

At this rate i will waste my time and it looks like i have a lot of problems with math

So i will be really thankful for anyone will help me

bump

I think i just need to convert from puzzle(background) to map coordinate

Do you mean the lines should be drawn green instead of red? if that's the case then you should try to debug your code. Put a breakpoint here:


if (map.IsValid((ushort)(mapx), (ushort)(mapy)))
{
   b = new byte[] { 0/*Blue*/, 255/*Green*/, 0/*Red*/ , 0/*useless*/ }; //breakpoint here
}

First make sure your this line of code actually runs, if not then you have a problem in your map.IsValid(...) function. If this line gets run, make sure you're not redrawing over your green lines.

This topic is closed to new replies.

Advertisement