Hello Guest, please login or register.
Did you miss your activation email?
Login with username, password and session length.

Pages: [1]   Go Down

Author Topic: A Random Level Generator Script (  (Read 1711 times)

0 Members and 1 Guest are viewing this topic.

DarkerColt

Programmer / Game Developer
A Random Level Generator Script (
« on: March 21, 2013, 10:34:38 pm »
  • "Youtuber, Fan-Game Creator, Student"
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 26
Yesterday i posted a topic concerning a splitscreen formula, today i release another script, let me know what you think.

//This is a random object generating script for GML.

//Script by Ethan Behan, credit would be appreciated.

//create event (setting the variables to avoid error):

generate=true
type=0
active=0
room_speed=1000 //so the process is sped up.

//step event:

if generate = true //overall decision for the object to start generating!
{
   if place_free(x,y) and type=0 and active=0 //this checks active and type is not equal to 1 so it does not generate multiple objects in a single place.
   {
   active=1
   }
}
//object generator, the higher the real numerical random number the less chance there will be an object of choice, type 0 must always be free.
if active=1 and type=0
{
   active=0
   type=irandom(3)
   if type=1{type=0;instance_create(x,y,objWall)}
   if type=2{type=0;instance_create(x,y,objwater)}
   if type=3{type=0;}
}
//movement,moving by a 16,16 grid.
if place_free(x+16,y+0) and generate=true
{
x+=16
}
//destroys once the object is out of the room.
if y > room_height
{
   instance_destroy()
}}

//Outside Event: //this is used to scroll down the room

y+=16
x=0
type=0
active=0

//Destroy Event:

room_speed=30 //this is the normal room speed.

//Sript produced by Ethan Behan.
Logged
Hey There! im new to the forums, but will be quite active! started work on a new Majora's Mask Remake project in the forums if anyone is interested!
  • Youtube:
Re: A Random Level Generator Script (
« Reply #1 on: March 21, 2013, 11:45:33 pm »
  • Yeah, I don't even...
  • *
  • Reputation: +11/-4
  • Offline Offline
  • Gender: Female
  • Posts: 1008
That's a pretty simple script, though kinda inneficient if you think about it, the way that's set up it doesn't make it have global accessablity so there is a semi-high possibity for the level to be a complete dead end.
Logged

Antidote

>.>
Re: A Random Level Generator Script (
« Reply #2 on: March 21, 2013, 11:48:28 pm »
  • In all seriousness who's serious?
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 1485
umm, next time you post code please use the code tags
Other than that, pretty much what kami said
Logged
  • Axiomatic Data Laboratories
Re: A Random Level Generator Script (
« Reply #3 on: April 08, 2013, 06:21:06 am »
  • Let's do this.
  • *
  • Reputation: +4/-0
  • Offline Offline
  • Gender: Male
  • Posts: 211
I got some nice levels with this piece of code:

Code: [Select]
/* Generator >> Chunk */

rows = ds_grid_width(argument0);
columns = ds_grid_height(argument0);
matrix = ds_grid_create(rows,columns);
range = 100;
sum = 0;

// Create random matrix
for (yy = 0; yy < columns; yy += 1)
{
    for (xx = 0; xx < rows; xx += 1)
    {
        ds_grid_set(matrix,xx,yy,(2*range)*(random(1)-0.5));
    }
}

 
// Clumping matrix
for (clumping = 0; clumping < argument1; clumping += 1)
{
    for (yy = 0; yy < columns; yy += 1)
    {
        for (xx = 0; xx < rows; xx += 1)
        {
            sum = chunk_get(matrix,xx,yy) +
                  chunk_get(matrix,xx-1,yy) + chunk_get(matrix,xx+1,yy) +
                  chunk_get(matrix,xx,yy-1) + chunk_get(matrix,xx,yy+1);
           
            ds_grid_set(matrix,xx,yy,sum/SumCounter);
            SumCounter = 0;
        }
    }
}

// Copy clumped matrix to chunk
for (yy = 0; yy < columns; yy += 1)
{
    for (xx = 0; xx < rows; xx += 1)
    {
        ds_grid_set(argument0,xx,yy,round(ds_grid_get(matrix,xx,yy)));
    }
}

Code: [Select]
/* Chunk Get
arguments: Chunk, x, y */

if (argument1 < 0 or argument2 < 0 or argument1 == ds_grid_width(argument0) or argument2 == ds_grid_height(argument0))
{
    return 0;
}
else
{
    SumCounter += 1;
    return ds_grid_get(argument0, argument1, argument2);
}

I could build some nice worlds a lá Minecraft with this code, but it is still somewhat slow:



You also can try the code, in my signature is a link to the Java Applet.
« Last Edit: April 08, 2013, 06:23:38 am by Rayo »
Logged
This is one of many tales Hylian lore speaks of...

Click here to check out my Deviantart!
  • Zelda Time Walker

Starforsaken101

Wake the Beast
Re: A Random Level Generator Script (
« Reply #4 on: April 08, 2013, 10:42:58 am »
  • www.mouffers.com
  • *
  • Reputation: +69/-0
  • Offline Offline
  • Gender: Female
  • Posts: 2575
Ha, this is pretty sweet!
Logged
  • Starforsaken101's DeviantART

Antidote

>.>
Re: A Random Level Generator Script (
« Reply #5 on: April 16, 2013, 08:28:29 am »
  • In all seriousness who's serious?
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 1485
Your script is pretty good, but it could use some optimizations, I'll only give you a few hints though:
1) Your idea of using data structures is spot on
2) Your for loop could be unrolled a bit
3) Try and use as small a loop as possible in game maker

otherwise excellent work.
Logged
  • Axiomatic Data Laboratories
Re: A Random Level Generator Script (
« Reply #6 on: April 16, 2013, 04:11:04 pm »
  • *
  • Reputation: +2/-0
  • Offline Offline
  • Gender: Male
  • Posts: 269
That minecraft looking game looks awesome by the way. and ill have to try this code out for myself to see what i can come up with..
Logged
Pages: [1]   Go Up

 


Contact Us | Legal | Advertise Here
2013 © ZFGC, All Rights Reserved



Page created in 0.121 seconds with 34 queries.