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

Legacy GM [ World Seed ] simple random_set_seed for infinite procedural generation

D

Dengar

Guest
GM Version: gamemaker studio 1.4
Target Platform: should work on all platforms
Download: http://www.mediafire.com/file/s5iaicgcke2xpcg/world_seed.gmz/file


Summary:
This tutorial is my method for using random_set_seed to setup room-based infinite proceduraly generated worlds using 1 object, 1 script, and 1 room.
Room transition occurs when player reaches edge of room and can be used with any size room with or without views.
Tutorial is designed for top down style games but could easily be used for other style games.
This tutorial is only setting up the seed numbers and doesn't include any actual terrain generation.

Download version also includes basic mouse-click based player movement. movement code is labeled -just for demo- and can easily be replaced with your own movement code.


Tutorial:
I use 2 variables called gx and gy, these variables adjust by +1/-1 when you move between rooms. these numbers are used for random_set_seed so all random functions in the generate script will pick the same random numbers each time you generate a room. this alloys you to leave and re-enter a room and it'll be generated the same way it was before.

another variable called "base_seed" is attached to the beginning of this seed number so you can change the generation in the entire game (like allowing the player to enter a number to generate the world, allowing them to re-generate worlds theve played before or choose to generate new worlds.)

the generate() script simply destroys all generated instances/tiles, then sets the new random_set_seed, and then finaly randomly generates new instances/tiles.

Code:
//object create_event

base_seed=1; //unique number added to all random seeds
gx=1000; //x position for room, not player
gy=1000; //y position for room, not player
transition_buffer=48; //distance player to edge of room that will transition to next room
generate(); //script creates room
Code:
 //object step_event

//======= room transition code ====================================================== 
if x<transition_buffer { gx-=1; generate(); x=room_width-(transition_buffer*1.5); } //move to left room
else if x>(room_width-transition_buffer) { gx+=1; generate(); x=transition_buffer*1.5; } //move to right room
else if y<transition_buffer { gy-=1; generate(); y=room_height-(transition_buffer*1.5); } //move to top room
else if y>(room_height-transition_buffer) { gy+=1; generate(); y=transition_buffer*1.5; } //move to bottom room
//========================

//breakdown of how transition code above works=====================
//========================
//if within transition zone (between room edge and transition buffer)
//adjust gx/gy depending on which direction in world your moving
//run generate() script based on new gx/gy location
//move players x/y position to other edge of room so it appears they moved into new room
Code:
//generate() script

//destroy all instances other than object

//sets random_seed to "base_seed + gx + gy"
random_set_seed(real( string(base_seed)+string(gx)+string(gy) ));

//create new objects
 
Last edited by a moderator:
  • Like
Reactions: Rob

Rob

Member
So is this for a top down map or a platformer or something else? What kind of games would work well with it?
 
Top