if all your frames are in the same sprite then you dont need an array to CREATE the tiles you just can use the array to store what tiles are where.
The best way to go about randomly making this like you want is to generate the streets on a grid first then generate anything else in the places streets arent.
The first thing you need is a layout evenly sized for your tiles. If the map can be 20 tiles wide then the layout needs to be the width of the tile*20 wide. Same for height.
Now instead of thinkin in terms of x and y location you can think in terms of location on a grid (layout.width/tile.width = number of columns in the grid. layout.height/tile.height = number of rows)
To generate your roads you need to start at a location on your grid (probably a corner or edge) and then place a road tile. Now you know that if your road is going left/right then you need to put another road tile up or down to make the full road. Thats upto you how you want to do it but you need to do it that way every time a road tile is made goin left or right.
Now you need to randomly decide a direction for the next part of the road. You can do that with choose() or random() or however you want to set it up. But randomly pick a direction (going any direction but the one you went last aka if the last road was placed right you dont wanna go left this time just up down or right again)
When you get to another edge or corner you know your roads done. That will generate one random road. Do it again from a different starting location to make another road etc.
Its not the best or fastest way to do it but its a good way to get you started with randomly generated content. Once its working you can tweak it to make it do things like generate intersections and instead of makin 1 road at a time you can make it generate a new road everytime it makes an intersection.
The main things are
- use a grid dont worry so much about the actual x,y values. You DO need em to place the tiles in the right part of the grid but dont try to use those to generate the locations
- You can use an array to store the tile in the same location in the array as it is in the grid (the grid is really a 2d array) then use this array to tell exactly whats where or whats empty (for makin buildings and stuff between roads)
- dont generate over what youve already generated (dont go left if you just went right)
- if you need somethin made with each tile generated do it then. Dont try to go back and do it after its generated. Like the other part of the roads in your case. Itll save you headaches down the road.