• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Making A One-Way Road with Bends?

R

rangers1001c

Guest
Hey guys, I'm having 2 problems with the code below, which is mostly from
The objective is to create a road that is only a single lane.

Output of the program: http://imgur.com/eJO0Tvf

Problems:
1. The lane sometimes splits into multiple directions. I'd like it to be like a one-way road, I know this problem lies within the restart() function because that's where the cells in the grid are selected to be tiled, but I don't know how to change it to make it follow a single path.

2. I'd like adjacent tiles to be connected. I have no idea about this one. I watched a video about auto-tiling, but I don't think that works in a grid.

If you're wondering, yes I'm a noob here, started yesterday :p

All help appreciated!

room_width=(CELL_WIDTH/16)*360;
room_height=(CELL_HEIGHT/16)*360;

var width=room_width div CELL_WIDTH;
var height= room_height div CELL_HEIGHT;

grid=ds_grid_create(width,height);

ds_grid_set_region(grid, 0,0, width, height, VOID);

randomize();

var cx = width div 2;
var cy = height;

//give the controller a random direction (left, up, or down)
var cdir = irandom(2);

//The odds of changing direction
var odds = 1;

//Create the level using 100 steps (for testing purposes)
repeat (100) {
//Place a floor tile at the controller position
grid[# cx,cy]=FLOOR;

//Choose a random direction for the controller
if (irandom(odds)==odds){
cdir=irandom(2)
}

//Move the controller
var xdir=lengthdir_x(1,cdir*90);
var ydir=lengthdir_y(1,cdir*90);
cx+=xdir;
cy+=ydir;

//Don't move outside the grid
cx=clamp(cx,1,width-2);
cy=clamp(cy,1,height-2);
}

//Move through grid and add tiles
for (var yy=0;yy<height;yy++) {
for ( var xx=0; xx<width; xx++) {
if (grid[# xx, yy] == FLOOR){
tile_add(bg_1,0,0, CELL_WIDTH, CELL_HEIGHT, xx*CELL_WIDTH, yy*CELL_HEIGHT,0)
}
}
}
 
Top