A
aGreenCrystal
Guest
Hey, i've coded a small world generator.
I've put the script into the rooms creation code,
but if i start the game it just does nothing.
Does anybody know why?
Code:
randomize();
scl = 128;
worldsize = 100;
grass_lowest = 2;
grass_highest = 7;
mountain_lowest = 8;
mountain_highest = 9;
water_lowest = 0;
water_highest = 1;
a = 0;
currentx = 0;
currenty = 0;
mapgrid = ds_grid_create(worldsize, worldsize);
repeat 5
{
currenty = -1;
repeat worldsize
{
currentx = -1;
currenty += 1;
repeat worldsize
{
currentx += 1;
if ds_grid_get(mapgrid, currentx, currenty) != ds_grid_get_max(mapgrid, currentx-1, currenty-1, currentx+1, currenty+1)
{
if ((ds_grid_get_max(mapgrid, currentx-1, currenty-1, currentx+1, currenty+1))-1)>0
{
ds_grid_set(mapgrid, currentx, currenty, (ds_grid_get_max(mapgrid, currentx-1, currenty-1, currentx+1, currenty+1))-1);
}
else
{
ds_grid_set(mapgrid, currentx, currenty, 0);
};
};
};
};
};
currenty = -1;
repeat worldsize
{
currenty += 1;
currentx = -1;
repeat worldsize
{
currentx += 1;
a = ds_grid_get(mapgrid, currentx, currenty);
if a > water_lowest-1 and a < water_highest+1
{
draw_sprite_tiled(sWater, 0, currentx*scl, currenty*scl);
};
if a > grass_lowest-1 and a < grass_highest+1
{
draw_sprite_tiled(sGrass, random_range(0, 3), currentx*scl, currenty*scl);
};
if a > mountain_lowest-1 and a < mountain_highest+1
{
draw_sprite_tiled(sMountain, 0, currentx*scl, currenty*scl);
};
};
};
I've put the script into the rooms creation code,
but if i start the game it just does nothing.
Does anybody know why?
Code:
randomize();
scl = 128;
worldsize = 100;
grass_lowest = 2;
grass_highest = 7;
mountain_lowest = 8;
mountain_highest = 9;
water_lowest = 0;
water_highest = 1;
a = 0;
currentx = 0;
currenty = 0;
mapgrid = ds_grid_create(worldsize, worldsize);
repeat 5
{
currenty = -1;
repeat worldsize
{
currentx = -1;
currenty += 1;
repeat worldsize
{
currentx += 1;
if ds_grid_get(mapgrid, currentx, currenty) != ds_grid_get_max(mapgrid, currentx-1, currenty-1, currentx+1, currenty+1)
{
if ((ds_grid_get_max(mapgrid, currentx-1, currenty-1, currentx+1, currenty+1))-1)>0
{
ds_grid_set(mapgrid, currentx, currenty, (ds_grid_get_max(mapgrid, currentx-1, currenty-1, currentx+1, currenty+1))-1);
}
else
{
ds_grid_set(mapgrid, currentx, currenty, 0);
};
};
};
};
};
currenty = -1;
repeat worldsize
{
currenty += 1;
currentx = -1;
repeat worldsize
{
currentx += 1;
a = ds_grid_get(mapgrid, currentx, currenty);
if a > water_lowest-1 and a < water_highest+1
{
draw_sprite_tiled(sWater, 0, currentx*scl, currenty*scl);
};
if a > grass_lowest-1 and a < grass_highest+1
{
draw_sprite_tiled(sGrass, random_range(0, 3), currentx*scl, currenty*scl);
};
if a > mountain_lowest-1 and a < mountain_highest+1
{
draw_sprite_tiled(sMountain, 0, currentx*scl, currenty*scl);
};
};
};