Jump to content


Photo

World Generator!


  • Please log in to reply
5 replies to this topic

#1 HelpMyFellowPeople

HelpMyFellowPeople

    GMC Member

  • GMC Member
  • 239 posts

Posted 26 July 2012 - 07:53 AM

This is what id call a masterpiece! It reads a sprite from the top left corner to the bottom right corner and grabs each pixel color and places an object relative to its position on the sprite multiplied by the width and height of the object to create a world! Brilliant!

world_gen_init(sprite_index,object_size)
//world_gen_init(sprite_index,object_size) --Assign the sprite to read from with sprite_index, and set the object size. So 16*16 or 32*32 just whatever suits you.
spr = argument0;
x1 = 0;
y1 = 0;
iw = sprite_get_width(spr);
ih = sprite_get_height(spr);
tile_s = argument1;

col = c_white;

world_gen_step()
//world_gen_step()
if(x1 < iw+1){
    if(y1 < iw){y1 += 1;}
    else if(y1 >= iw){x1 += 1; y1 = 0;}
col = draw_getpixel(view_xview+x1,view_yview+y1);
}

world_gen_draw()
if(x1 < iw+1){
    draw_sprite(spr,0,view_xview,view_yview);
}

world_gen_color(color,object) --Assigns a color to an object. For example, world_gen_color(c_red,obj_dirt){This will create obj_dirt wherever a red picel is found}
//world_gen_add_color(color,object)
if(col = argument0){
    instance_create(x1*tile_s,y1*tile_s,argument0);
}

Edited by HelpMyFellowPeople, 26 July 2012 - 07:58 AM.

  • 0

#2 Jack Indie Box

Jack Indie Box

    GMC Member

  • GMC Member
  • 1460 posts
  • Version:GM:Studio

Posted 26 July 2012 - 08:47 AM

very good if it works, and works in a quick enough manner. but just so you know the get pixel colour function is one of the slowest by far in game maker, so calling it many times is easilly noticeable slow down.
  • 1

#3 HelpMyFellowPeople

HelpMyFellowPeople

    GMC Member

  • GMC Member
  • 239 posts

Posted 26 July 2012 - 09:09 AM

Well my best average for FPS is 536fps and thats adding the objects aswell. And im on a laptop that isnt that powerful so it seems to do alright.
  • 0

#4 creativebunch

creativebunch

    The Bunchiest

  • GMC Member
  • 886 posts
  • Version:GM:Studio

Posted 26 July 2012 - 09:21 AM

I have know idea how I would implement these into a game, could you upload an example?
  • 0

#5 YellowAfterlife

YellowAfterlife

    GMC Member

  • Global Moderators
  • 3493 posts
  • Version:GM:Studio

Posted 26 July 2012 - 10:01 AM

I think you are exaggerating classification of your resources slightly.
'Generate' normally assumes Procedural generation, which, in this case, would also mean creating that image you pick colours from.
What your script currently does, is best described as 'Converting image to instances' or 'Loading game level from image'.
Second would actually be a good search result.

It would also make sense if you included a step-by-step information about using this, since it is not clear if _color script should be ran in step or draw event, and if so, why it isn't merged into those scripts initially.
  • 1

#6 HelpMyFellowPeople

HelpMyFellowPeople

    GMC Member

  • GMC Member
  • 239 posts

Posted 27 July 2012 - 05:03 AM

I will make an example. And I have made a generator that generates a level, but is not easy to convert into scripts, so I will just have to include an example with that in it. Will do this soon
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users