This is unfinished, it places the border sprites I need to do the mid section but have to go out for a while so I thought I would post what I got so far maybe you can draw some ideas from it or simplify it a little, I will continue with the complicated part when I get home, this basically shows how I would go about structuring the code
// Project: Road System
// Created: 2017-07-11
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "Road System" )
SetWindowSize( 1024, 768, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window
// set display properties
SetVirtualResolution( 1024, 768 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts
#Constant ROAD_TILE_SIZE 256
#Constant ROAD_GRID_X 3
#Constant ROAD_GRID_Y 2
#Constant ROAD_CROSS 1
#Constant ROAD_TEE_DOWN 2
#Constant ROAD_TEE_UP 3
#Constant ROAD_TEE_LEFT 4
#Constant ROAD_TEE_RIGHT 5
#Constant ROAD_CORNER_LEFT_DOWN 6
#Constant ROAD_CORNER_RIGHT_DOWN 7
#Constant ROAD_CORNER_LEFT_UP 8
#Constant ROAD_CORNER_RIGHT_UP 9
#Constant ROAD_HORZ 10
#Constant ROAD_VERT 11
global map as integer[ROAD_GRID_X, ROAD_GRID_Y]
//SetViewZoomMode(1)
//SetViewZoom(0.5)
global img_road_main
img_road_main=LoadImage("roads.png")
Function CreateRoadSprite(Road_Type, x, y)
road = CreateSprite(img_road_main)
SetSpriteAnimation(road, 256, 256, 5)
SetSpritePosition(road, x*ROAD_TILE_SIZE, y*ROAD_TILE_SIZE)
map[x,y]=Road_Type
Select Road_Type
Case ROAD_CROSS
EndCase
Case ROAD_TEE_DOWN
SetSpriteFrame(road, 2)
EndCase
Case ROAD_TEE_UP
SetSpriteFrame(road, 2)
SetSpriteAngle(road, 180)
EndCase
Case ROAD_TEE_LEFT
EndCase
Case ROAD_TEE_RIGHT
EndCase
Case ROAD_CORNER_LEFT_DOWN
SetSpriteFrame(road, 4)
SetSpriteAngle(road, 270)
EndCase
Case ROAD_CORNER_RIGHT_DOWN
SetSpriteFrame(road, 4)
//SetSpriteAngle(road, 0)
EndCase
Case ROAD_CORNER_LEFT_UP
SetSpriteFrame(road, 4)
SetSpriteAngle(road, 180)
EndCase
Case ROAD_CORNER_RIGHT_UP
SetSpriteFrame(road, 4)
SetSpriteAngle(road, 90)
EndCase
Case ROAD_HORZ
SetSpriteFrame(road, 3)
EndCase
Case ROAD_VERT
SetSpriteFrame(road, 3)
SetSpriteAngle(road, 90)
EndCase
EndSelect
EndFunction
for x=0 to ROAD_GRID_X
for y=0 to ROAD_GRID_Y
if y=0 // first row
if x=0 // top left corner
CreateRoadSprite(ROAD_CORNER_LEFT_DOWN, x, y)
elseif x>0 and x < ROAD_GRID_X // top row
// TODO, need to check here if last tile was a tee
// dont want to many close togeather
choice = Random2(0, 1)
if choice = 1 // road
CreateRoadSprite(ROAD_HORZ, x, y)
else // tee section
CreateRoadSprite(ROAD_TEE_DOWN, x, y)
endif
elseif x = ROAD_GRID_X // top right corner
CreateRoadSprite(ROAD_CORNER_RIGHT_DOWN, x, y)
endif
elseif y>0 and y<ROAD_GRID_Y // mid section
if x=0 // left side
CreateRoadSprite(ROAD_VERT, x, y)
elseif x>0 and x < ROAD_GRID_X // mid section
// here would be the real tricky part of
// filling the main section
// TODO, check surrounding tiles and find a sutible section for this tile
//if map[x-1, y-1] =
//elseif map[x-1, y-1] =
//endif
elseif x = ROAD_GRID_X // right side
CreateRoadSprite(ROAD_VERT, x, y)
endif
elseif y=ROAD_GRID_Y // last row
if x=0 // bottom left corner
CreateRoadSprite(ROAD_CORNER_LEFT_UP, x, y)
elseif x>0 and x < ROAD_GRID_X // bottom row
// TODO, need to check here if last tile was a tee
// dont want to many close togeather
choice = Random2(0, 1)
if choice = 1 // road
CreateRoadSprite(ROAD_HORZ, x, y)
else // tee section
CreateRoadSprite(ROAD_TEE_UP, x, y)
endif
elseif x = ROAD_GRID_X // bottom right corner
CreateRoadSprite(ROAD_CORNER_RIGHT_UP, x, y)
endif
endif
next
next
do
Print( ScreenFPS() )
Sync()
loop