• 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!

Level not rendering

G

Gustav van Rooyen

Guest
Good day all,

I am currently following a HeartBeast series where you random generate a level.
Here is the link to that video:

But I followed along perfectly and when I run the game I just get the game maker splash and thats it no error or nothing.

If someone can help me on this it would be great.
Here is my code:

///Create the Level

//Resize the room
room_width = (CELL_WIDTH/16) * 720;
room_height = (CELL_HEIGHT/16) * 720;

//Set the grid width and height
var width = room_width div CELL_WIDTH;
var height = room_height div CELL_HEIGHT;

//Create the grid
grid = ds_grid_create(width, height);

//Fill the grid with void
ds_grid_set_region(grid, 0, 0, width-1, height-1, VOID);

//Randomize the world
randomize();

//Create the controller in the center of the grid
var cx = width div 2;
var cy = height div 2;

//Create the player
instance_create(cx*CELL_WIDTH+CELL_WIDTH/2, cy*CELL_HEIGHT+CELL_HEIGHT/2, obj_Player);

//Give the controller a random direction
var cdir = irandom(3);

//The odds variable for changing direction
var odds = 1;

//Create the level using 1000 steps
repeat (1000)
{
//PLace a floor tile at the controller position
grid[# cx, cy] = FLOOR;

//Randomize the direction of the controller
if (irandom(odds) == odds)
{
cdir = irandom(3);
}

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

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

//Add the walls
for (var yy = 1; yy < height-1; yy++)
{
for (var xx = 1; xx < width-1; xx++)
{
if (grid[# xx, yy] == FLOOR)
{
//Check for walls
if (grid[# xx+1, yy] != FLOOR) grid[# xx+1, yy] = WALL;
if (grid[# xx-1, yy] != FLOOR) grid[# xx-1, yy] = WALL;
if (grid[# xx, yy+1] != FLOOR) grid[# xx, yy+1] = WALL;
if (grid[# xx, yy-1] != FLOOR) grid[# xx, yy-1] = WALL;
}
}
}

//Draw the level using the grid
for (var yy = 0; yy < height; y++)
{
for (var xx = 0; xx < width; xx++)
{
if (grid[# xx, yy] == FLOOR)
{
//Draw the floor
tile_add(back_Floor, 0, 0, CELL_WIDTH, CELL_HEIGHT, xx*CELL_WIDTH, yy*CELL_HEIGHT, 0)
} else if (grid[# xx, yy] == WALL)
{
//Draw the wall
tile_add(back_Wall, 0, 0, CELL_WIDTH, CELL_HEIGHT, xx*CELL_WIDTH, yy*CELL_HEIGHT, 0);
}
}
}
 
R

rui.rosario

Guest
Not sure if this is the only reason, but you created an infinite loop. Look ath the drawing loop, you have
Code:
for (var yy = 0; yy < height; y++)
You made a mistake typing yy which made an infinite loop because you're incrementing y but yy remains being zero (never reaching height)
 
G

Gustav van Rooyen

Guest
Oi thank you, that solved the problem. I just changed y++ to yy++ and it is working
 
Top