ZFGC
Resources => Coding => Topic started by: DarkerColt on March 21, 2013, 10:34:38 pm
-
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.
-
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.
-
umm, next time you post code please use the code tags
Other than that, pretty much what kami said
-
I got some nice levels with this piece of code:
/* 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)));
}
}
/* 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:
(http://imageshack.us/a/img600/5439/blockcraft14.png)
You also can try the code, in my signature is a link to the Java Applet.
-
Ha, this is pretty sweet!
-
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.
-
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..