S
SagyDemn
Guest
GM Version: GM7
Target Platform: All
Download: https://www.dropbox.com/sh/ahcvg0ludyarh28/AAA_k-qUVXRsSToo3nMAjpu0a?dl=0
Summary: This is a Tutorial about Procedural Generation of a room with Walls and Floors.
Step1: Create a (Background) for the Floor tile. (Default size 16x16)
Step2: Create a Wall (Sprite). (Same size with the Floor Tile)
Step3: Create an (Object) called "oWall".
Step4: Create another (Object) called "oGenController".
Step5: Inside oGenController (Create Event) paste this code.
Step6: Create a room.
Step7: Default Size of the Room = 640x320
Step8: Place oGenController inside the room.
Step9: Run the Game.
Target Platform: All
Download: https://www.dropbox.com/sh/ahcvg0ludyarh28/AAA_k-qUVXRsSToo3nMAjpu0a?dl=0
Summary: This is a Tutorial about Procedural Generation of a room with Walls and Floors.
Step1: Create a (Background) for the Floor tile. (Default size 16x16)
Step2: Create a Wall (Sprite). (Same size with the Floor Tile)
Step3: Create an (Object) called "oWall".
Step4: Create another (Object) called "oGenController".
Step5: Inside oGenController (Create Event) paste this code.
Code:
///Create a random map
randomize();
c_x = room_width/2;
c_y = room_height/2;
wall = oWall;//The Wall object
t_size = 16;//Size of the floor tile
steps = 50;//This is how many times it will create a block.Bigger value = better shapes
t_depth = 1000;//Tile Depth
//Place floor
for(var s = 0;s <= steps;s ++){
var dir = choose(0,1);
if (dir = 0){ c_x += choose(-t_size,t_size); }//chooses to move at x
if (dir = 1){ c_y += choose(-t_size,t_size); }//chooses to move at y
tile_add(tile_floor,0,0,t_size,t_size,c_x,c_y,t_depth);
}
//Reset the position of the checked area.
c_x = 0;
c_y = 0;
////////
//Check The whole Room and place walls
for(i = 0;i <= room_width/t_size;i ++){
for(j = 0;j <= room_height/t_size;j ++){
if c_x <= room_width{
c_x += t_size;
}else{
c_x = 0;
c_y += t_size;
}
var cur_tile = tile_layer_find(t_depth,c_x,c_y);//Check the current tile that we are colliding.
var tmp_tile0 = tile_layer_find(t_depth,c_x+t_size,c_y);//Check right of the current tile
var tmp_tile1 = tile_layer_find(t_depth,c_x-t_size,c_y);//Check left of the current tile
var tmp_tile2 = tile_layer_find(t_depth,c_x,c_y+t_size);//Check bottom of the current tile
var tmp_tile3 = tile_layer_find(t_depth,c_x,c_y-t_size);//Check top of the current tile
if cur_tile != -1{//Check we are colliding with a tile
if(tmp_tile0 == -1){instance_create(c_x+t_size,c_y,oWall);}//Place wall on the right
if(tmp_tile1 == -1){instance_create(c_x-t_size,c_y,oWall);}//Place wall on the left
if(tmp_tile2 == -1){instance_create(c_x,c_y+t_size,oWall);}//Place wall on the bottom
if(tmp_tile3 == -1){instance_create(c_x,c_y-t_size,oWall);}//Place wall on the yop
}
}
}
Step6: Create a room.
Step7: Default Size of the Room = 640x320
Step8: Place oGenController inside the room.
Step9: Run the Game.
Last edited by a moderator: