SKUPINA SLUŽBY STEAM
game development help gamedevhelp
SKUPINA SLUŽBY STEAM
game development help gamedevhelp
10
VE HŘE
79
ONLINE
Založena
28. května 2015
Jazyk
Angličtina
Zobrazuje se 1–5 z 5 položek
3
Need Help? GM:S
amusudan původně napsal:
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!
5
Starting a small studio
3
Need Help? GM:S
32
Present Thyself. Are you DEV, MODder or playtester?
Zobrazuje se 1–5 z 5 položek