STEAM GROUP
game development help gamedevhelp
STEAM GROUP
game development help gamedevhelp
5
IN-GAME
66
ONLINE
Founded
28 May, 2015
Language
English
Firel 4 Jul, 2015 @ 8:39pm
Need Help? GM:S
Post your questions here!
Need more help than posted?
Friend me then chat!
(please do not expect to stay on said list)
I mostly deal with:
Top Down Shooters
Platformers
Terrarians (plaformer/sandboxes)

Please don't ask about random gen, i am clueless on that.
< >
Showing 1-3 of 3 comments
Random gen is pretty simple when it comes down to it, you just need to know how it works (not code-wise but the general logic behind it). Top down level generation is the most simple generation (terraria style world generation is much more complicated), all you need is an object going in random directions and placing floor tiles, then make the floor tiles check if the space next to them is free and if so place a wall block there. Here's an example:

do
{
if !place_meeting(x,y,obj_ground) // we aren't currently on a floor block
{
tiles++; // number of tiles + 1
instance_create(x,y,obj_ground); // create a floor tile
if tiles = maxtiles // the last tile we created is the final tile to be placed
{
guard = instance_create(x,y+6,obj_enemy); // create an enemy to guard the loot
instance_deactivate_object(guard);
instance_create(x,y,obj_chest); // create a loot chest
}
}

do //pick a random direction until the direction we picked keeps us inside the room
{
dir = irandom(3); //choose a random direction
xdist = lengthdir_x(32, dir * 90);
ydist = lengthdir_y(32, dir * 90);
}
until x + xdist < room_width - 32 and x + xdist > 32 and y + ydist < room_height - 32 and y + ydist > 32
x += xdist; // move x
y += ydist; // move x
}
until tiles = maxtiles

This creates a random level in a single step, ofcourse there is some variable initialising before this (maxtiles,tiles and roomsize and x/y coordinates) and wall creation after it (also loot/prop/enemy/vegetation spawning) but as you see it is very simple!

To create more advanced level generation you could add a smaller chance to turn and rooms (basically place more floor tiles around yourself to create an open space).
Last edited by Shimmy, Shimmy, Shimmy; 5 Mar, 2016 @ 3:55am
Firel 5 Mar, 2016 @ 10:08am 
Originally posted by amusudan:
Random gen is pretty simple when it comes down to it, you just need to know how it works (not code-wise but the general logic behind it). Top down level generation is the most simple generation (terraria style world generation is much more complicated), all you need is an object going in random directions and placing floor tiles, then make the floor tiles check if the space next to them is free and if so place a wall block there. Here's an example:

do
{
if !place_meeting(x,y,obj_ground) // we aren't currently on a floor block
{
tiles++; // number of tiles + 1
instance_create(x,y,obj_ground); // create a floor tile
if tiles = maxtiles // the last tile we created is the final tile to be placed
{
guard = instance_create(x,y+6,obj_enemy); // create an enemy to guard the loot
instance_deactivate_object(guard);
instance_create(x,y,obj_chest); // create a loot chest
}
}

do //pick a random direction until the direction we picked keeps us inside the room
{
dir = irandom(3); //choose a random direction
xdist = lengthdir_x(32, dir * 90);
ydist = lengthdir_y(32, dir * 90);
}
until x + xdist < room_width - 32 and x + xdist > 32 and y + ydist < room_height - 32 and y + ydist > 32
x += xdist; // move x
y += ydist; // move x
}
until tiles = maxtiles

This creates a random level in a single step, ofcourse there is some variable initialising before this (maxtiles,tiles and roomsize and x/y coordinates) and wall creation after it (also loot/prop/enemy/vegetation spawning) but as you see it is very simple!

To create more advanced level generation you could add a smaller chance to turn and rooms (basically place more floor tiles around yourself to create an open space).


Hey thanks man! I needed help with that! Now i can start moving on by using that :smile:

I'll keep this as first comment to keep it in file!
No problem, if you need help with anything else just ask.
By the way the code I showed you is from my new project, no name yet but you can check the blog if you'd like that ( https://lousydev.wordpress.com/ ).
Last edited by Shimmy, Shimmy, Shimmy; 5 Mar, 2016 @ 10:50am
< >
Showing 1-3 of 3 comments
Per page: 1530 50