Jump to content


Photo

Autotile


  • Please log in to reply
9 replies to this topic

#1 Timmeh

Timmeh

    GMC Member

  • New Member
  • 358 posts

Posted 20 May 2008 - 09:37 AM

Timothy's Autotile Script

USAGE: autotile(mode)

ARGUMENTS:
mode 0=Horizontal Autotiling, 1=Vertical Autotiling, 3=4-dir Tiling

RETURNS: None

NOTES: Sprite must follow a certain format for each mode. For 0 first frame is the left frame, second is the center and the third is the right. For 1 the first frame is the top, the second the middle, and the third the bottom. For 2 the first is the top-left, the second is the top-center, the third is the top-right, the fourth the middle-right, the fifth the bottom-right, the sixth the middle-bottom, the seventh the bottom-left, the eighth the middle-left and the nineth the very center.. For 3 the first three follow tmode 0, the next two are triangles pointing up-left, down-right, up-right, down-left repectivly. For 4 you will need a sprite with 19 frames. The first three are the same as mode 0, the next three are the same as mode 1. The next set are corners for hallways, top-left, top-right, bottom-right, bottom-left. The next 9 are the same as in mode 2.

V1.10
Two new modes
  • Floors with ramps
  • Complete (thin halls, hall corners, and other modes)
Added directional check variables, to make it more readable

/*** Usage: autotile(mode)**** Arguments:** ** mode     0=Horizontal Autotiling, 1=Vertical Autotiling, 2=4-dir Tiling, 3=Slanted Floor Tiling, 4=All Tiling**** Returns:**  None**** Notes:**  Sprite must follow a certain format for each mode.  For 0 first frame is the left frame, second is the center and the third is the right.**  For 1 the first frame is the top, the second the middle, and the third the bottom.  For 2 the first is the top-left, the second is the top-center,**  the third is the top-right, the fourth the middle-right, the fifth the bottom-right, the sixth the middle-bottom, the seventh the bottom-left, **  the eighth the middle-left and the nineth the very center..  For 3 the first three follow tmode 0, the next two are triangles**  pointing up-left, down-right, up-right, down-left repectivly.  For 4 you will need a sprite with 19 frames.  The first three are the same as mode 0,**  the next three are the same as mode 1.  The next set are corners for hallways, top-left, top-right, bottom-right, bottom-left.  The next 9 are the**  same as in mode 2.** */var obj, mode;obj=object_index //The object to look for on each side.mode=argument0 //The autotiling mode to use.image_speed=0 //Stop the sprite from animating.var left, right, up, down, upleft, upright, downleft, downright;  //Store the checks of positions here to make the rest of the code more readable.left=place_meeting(x-sprite_width, y, obj)right=place_meeting(x+sprite_width, y, obj)up=place_meeting(x, y-sprite_height, obj)down=place_meeting(x, y+sprite_height, obj)upleft=place_meeting(x-sprite_width, y-sprite_height, obj)upright=place_meeting(x+sprite_width, y-sprite_height, obj)downleft=place_meeting(x-sprite_width, y+sprite_height, obj)downright=place_meeting(x+sprite_width, y+sprite_height, obj)switch(mode) {   case 0:    if !left && right { //If there is an object to the right but not to the left...      image_index=0 //Set the image_index to the left frame.   }   if left && right { //If there are objects on both sides.      image_index=1 //Set the image_index to the center frame.   }   if left && !right { //If there is an object to the left but not the right...      image_index=2 //Set the image_index to the right frame.   }   break;      case 1:   if !up && down { //If there is an object to the bottom but not the top....      image_index=0 //Set the image_index to the left frame.   }   if up && down { //If there are objects on both the top and the bottom...      image_index=1 //Set the image_index to the center frame.   }   if up && !down { //If there is an object to the top but not the bottom...      image_index=2 //Set the image_index to the right frame.   }   break;      case 2:   if !up && !left && right && down {       image_index=0   }   if !up && left && right && down {       image_index=1   }   if !up && left && !right && down {      image_index=2   }   if up && left && !right && down {      image_index=3   }   if up && left && !right && !down {      image_index=4   }   if up && left && right && !down {      image_index=5   }   if up && !left && right && !down{      image_index=6   }   if up && !left && right && down {      image_index=7   }   if up && left && right && down {      image_index=8   }   break;      case 3:   if !left && !up && !down && right {      image_index=0   }   if left && !up && !down && right {      image_index=1   }   if left && !up && !down && !right {      image_index=2   }   if left && up && !down && !right {      image_index=3   }   if !left && !up && down && right {      image_index=4   }      if !left && up && !down && right {      image_index=5   }   if left && !up && down && !right {      image_index=6   }   break;      case 4:   if right && !left && !up && !down {      image_index=0   }   if right && left && !up && !down {      image_index=1   }   if !right && left && !up && !down {      image_index=2   }   if !right && !left && !up && down {      image_index=3   }   if !right && !left && up && down {      image_index=4   }   if !right && !left && up && !down {      image_index=5   }   if right && !left && up && !down {      image_index=6   }   if right && !left && !up && down {      image_index=7   }   if !right && left && !up && down {      image_index=8   }   if !right && left && up && !down {      image_index=9   }   if right && !left && !up && down && downright && !downleft && !upright && !upleft {      image_index=10   }   if right && left && !up && down {      image_index=11   }   if !right && left && !up && down && !downright && downleft && !upright && !upleft {      image_index=12   }   if !right && left && up && down {      image_index=13   }   if !right && left && up && !down && !downright && !downleft && !upright && upleft {      image_index=14   }   if right && left && up && !down {      image_index=15   }   if right && !left && up && !down && !downright && !downleft && upright && !upleft {      image_index=16   }   if right && !left && up && down {     image_index=17   }   if right && left && up && down {     image_index=18   }   break;   }


V 1.00
/*** Usage: autotile(mode)**** Arguments:** ** mode	 0=Horizontal Autotiling, 1=Vertical Autotiling, 3=4-dir Tiling**** Returns:**  None**** Notes:**  Sprite must follow a certain format for each mode.  For 0 first frame is the left frame, second is the center and the third is the right.**  For 1 the first frame is the top, the second the middle, and the third the bottom.  For 2 the first is the top-left, the second is the top-center,**  the third is the top-right, the fourth is the middle-right, the fifth is the middle-center, the sixth is the middle-right, the seventh is the **  bottom-left, the eighth is the bottom-center, and the nineth is the bottom-right.** */var obj, mode;obj=object_index //The object to look for on each side.mode=argument0 //The autotiling mode to use.image_speed=0 //Stop the sprite from animating.switch(mode) {   case 0:    if !place_meeting(x-sprite_width, y, obj) && place_meeting(x+sprite_width, y, obj) { //If there is an object to the right but not to the left...	  image_index=0 //Set the image_index to the left frame.   }   if place_meeting(x-sprite_width, y, obj) && place_meeting(x+sprite_width, y, obj) { //If there are objects on both sides.	  image_index=1 //Set the image_index to the center frame.   }   if place_meeting(x-sprite_width, y, obj) && !place_meeting(x+sprite_width, y, obj) { //If there is an object to the left but not the right...	  image_index=2 //Set the image_index to the right frame.   }   break;      case 1:   if !place_meeting(x, y-sprite_height, obj) && place_meeting(x, y+sprite_height, obj) { //If there is an object to the bottom but not the top....	  image_index=0 //Set the image_index to the left frame.   }   if place_meeting(x, y-sprite_height, obj) && place_meeting(x, y+sprite_height, obj) { //If there are objects on both the top and the bottom...	  image_index=1 //Set the image_index to the center frame.   }   if place_meeting(x, y-sprite_height, obj) && !place_meeting(x, y+sprite_height, obj) { //If there is an object to the top but not the bottom...	  image_index=2 //Set the image_index to the right frame.   }   break;      case 2:   if !place_meeting(x-sprite_width, y, obj) && !place_meeting(x, y-sprite_height, obj) && place_meeting(x+sprite_width, y, obj) && place_meeting(x, y+sprite_height, obj) { 	  //If there is an objec to the bottom and right but not to the top or left.	  image_index=0 //Set the image_index to the top-left frame.   }   if place_meeting(x-sprite_width, y, obj) && !place_meeting(x, y-sprite_height, obj) && place_meeting(x+sprite_width, y, obj) && place_meeting(x, y+sprite_height, obj) { 	  //If there is an object to the left, right and bottom but not the top.	  image_index=1 //Set the image_index to the top-center frame.   }   if place_meeting(x-sprite_width, y, obj) && !place_meeting(x, y-sprite_height, obj) && !place_meeting(x+sprite_width, y, obj) && place_meeting(x, y+sprite_height, obj) {	  //If there is an object to the left and bottom, but not the top or right.	  image_index=2 //Set the image_index to the top-right frame.   }   if !place_meeting(x-sprite_width, y, obj) && place_meeting(x, y-sprite_height, obj) && place_meeting(x+sprite_width, y, obj) && place_meeting(x, y+sprite_height, obj) {	  //If there is an object to the top, right and bottom, but not to the left.	  image_index=3 //Set the image_index to the middle-left frame.   }   if place_meeting(x-sprite_width, y, obj) && place_meeting(x, y-sprite_height, obj) && place_meeting(x+sprite_width, y, obj) && place_meeting(x, y+sprite_height, obj) {	  //If there is an object in all directions.	  image_index=4 //Set the image_index to the middle-center frame.   }   if place_meeting(x-sprite_width, y, obj) && place_meeting(x, y-sprite_height, obj) && !place_meeting(x+sprite_width, y, obj) && place_meeting(x, y+sprite_height, obj) {	  //If there is an object to the top, left and bottom, but not to the right.	  image_index=5 //Set the image_index to the middle-right frame.   }   if !place_meeting(x-sprite_width, y, obj) && place_meeting(x, y-sprite_height, obj) && place_meeting(x+sprite_width, y, obj) && !place_meeting(x, y+sprite_height, obj) {	  //If there is an object to the right and top but not to the left or bottom.	  image_index=6 //Set the image_index to the bottom-left frame.   }   if place_meeting(x-sprite_width, y, obj) && place_meeting(x, y-sprite_height, obj) && place_meeting(x+sprite_width, y, obj) && !place_meeting(x, y+sprite_height, obj) {	  //If there is an object to the left, top and right but not the bottom.	  image_index=7 //Set the image_index to the bottom-center frame.   }   if place_meeting(x-sprite_width, y, obj) && place_meeting(x, y-sprite_height, obj) && !place_meeting(x+sprite_width, y, obj) && !place_meeting(x, y+sprite_height, obj) {	  //If there is an object to the right and top, but not the left or bottom.	  image_index=8 //Set the image_index to the bottom-right frame.   }   break;   }

I use this script to keep my number of different objects down. It lets you take a single object type and a single sprite (with either 3 or 9 frames, depending on the mode) and autotiles them. I.E. If your sprite has the following frames

<-
--
->

Then putting four of them in a row with the code "autotile(0)" in the creation event it would look like this in game:

<- -- -- ->

There is an example here using all three modes.
Apparently, my Ripway (hosting) account has been shut down, so I no longer have the example file. If any else still has it, or wants to create a new one, I can link to it here.

Edited by Timmeh, 17 December 2009 - 09:14 PM.

  • 0
I have started teaching myself C++, and do not use Game Maker regularly any more. You can follow my current project either on my DevBlog or in my topic on the Bay12 forums.

GENERATION 195G: EVERYTIME YOU SEE THIS DIVIDE YOUR MOTHERS MAIDEN BIRTHDAY BY WHAT YOU HAD FOR DINNER LAST NIGHT AND ADD Q. (ANTI-SOCIAL EXPERIMENT)

LINKS: My Script Collection - My Autotile Script - My Random Number Generator - My Process Runner Extension - My Detailed TDS Tutorial

#2 death-droid

death-droid

    GMC Member

  • GMC Member
  • 2600 posts

Posted 20 May 2008 - 10:07 AM

Very nice can i please add this to the extention i making

of course credit to you
  • 0

Posted Image


#3 Timmeh

Timmeh

    GMC Member

  • New Member
  • 358 posts

Posted 22 May 2008 - 10:52 AM

To be honest, I would prefer it if you didn't. Not much I could do to stop you, but if you want to you can link here. Sorry, but I'm working on something similer. Once I've made a few more maybe we can merge the extensions :)
  • 0
I have started teaching myself C++, and do not use Game Maker regularly any more. You can follow my current project either on my DevBlog or in my topic on the Bay12 forums.

GENERATION 195G: EVERYTIME YOU SEE THIS DIVIDE YOUR MOTHERS MAIDEN BIRTHDAY BY WHAT YOU HAD FOR DINNER LAST NIGHT AND ADD Q. (ANTI-SOCIAL EXPERIMENT)

LINKS: My Script Collection - My Autotile Script - My Random Number Generator - My Process Runner Extension - My Detailed TDS Tutorial

#4 death-droid

death-droid

    GMC Member

  • GMC Member
  • 2600 posts

Posted 22 May 2008 - 11:27 AM

XD no problemo i dont care

I was just checking

Anyway this is AWESOME and a very smart idea
  • 0

Posted Image


#5 Timmeh

Timmeh

    GMC Member

  • New Member
  • 358 posts

Posted 23 May 2008 - 01:56 AM

Thanks for understanding, glad to meet someone mature on the internet :P

Thanks again, I'll definately contact you when my extension is a little farther underway and we can discuss merging them :)

Anyone else found a use for it? 57 views, 1 person posted... Is my description not written well enough? If so I can try to get some screenshots.
  • 0
I have started teaching myself C++, and do not use Game Maker regularly any more. You can follow my current project either on my DevBlog or in my topic on the Bay12 forums.

GENERATION 195G: EVERYTIME YOU SEE THIS DIVIDE YOUR MOTHERS MAIDEN BIRTHDAY BY WHAT YOU HAD FOR DINNER LAST NIGHT AND ADD Q. (ANTI-SOCIAL EXPERIMENT)

LINKS: My Script Collection - My Autotile Script - My Random Number Generator - My Process Runner Extension - My Detailed TDS Tutorial

#6 Neoxer

Neoxer

    GMC Member

  • New Member
  • 492 posts

Posted 26 May 2008 - 05:07 PM

This is pretty nice, I'd give it a 8/10, the only thing, for me, that would make it a 10/10 is slopes. Other than that, great script.

Edited by Neoxer, 26 May 2008 - 05:09 PM.

  • 0
I made the:

Firefox Owns


ALL of my leftovers: Thread

#7 Timmeh

Timmeh

    GMC Member

  • New Member
  • 358 posts

Posted 26 May 2008 - 08:26 PM

This is pretty nice, I'd give it a 8/10, the only thing, for me, that would make it a 10/10 is slopes. Other than that, great script.

Thanks. I'm considering adding two more modes, one for top-down walls (I.E. horizontal, vertical, and corners) and one like you said, that would be the same except with angles. Maybe I'll combine then.... I'll go ahead and do that now, see if I can't figure it out :rolleyes:

Tim

NEW VERSION: 1.10
I've finished the next release of the script. It has two additional options for mode and has been made more readable. However, the order in which the frames have to come in have changed for some mode to make it make more sense. (To me at least.)

Edited by Timmeh, 27 May 2008 - 04:27 AM.

  • 0
I have started teaching myself C++, and do not use Game Maker regularly any more. You can follow my current project either on my DevBlog or in my topic on the Bay12 forums.

GENERATION 195G: EVERYTIME YOU SEE THIS DIVIDE YOUR MOTHERS MAIDEN BIRTHDAY BY WHAT YOU HAD FOR DINNER LAST NIGHT AND ADD Q. (ANTI-SOCIAL EXPERIMENT)

LINKS: My Script Collection - My Autotile Script - My Random Number Generator - My Process Runner Extension - My Detailed TDS Tutorial

#8 death-droid

death-droid

    GMC Member

  • GMC Member
  • 2600 posts

Posted 23 June 2008 - 11:59 AM

Hm i think i might of found a bug im not sure i replaced the code in the example with the newest one and the obj_filef kind of stuffed up it looked all dodgy.

Anyway nice update
  • 0

Posted Image


#9 Nelliosis

Nelliosis

    GMC Member

  • New Member
  • 100 posts

Posted 21 April 2009 - 01:36 AM

I would like to read your example or download the file (if there is one) but the text in your post is overlapping and it's really hard to read. What's up, my browser?

Nevermind that, but the link is dead and I would like to see your example.

Edited by Nelliosis, 24 April 2009 - 10:32 PM.

  • 0

#10 Timmeh

Timmeh

    GMC Member

  • New Member
  • 358 posts

Posted 09 May 2009 - 12:35 PM

Unfortunately, it would appear Ripway has shut down my account, and due to a computer wipe, I don't have any of my Game Maker files on it. Sorry.


If someone else still has it, please e-mail it to me, and I'll re-upload it somewhere else.
  • 0
I have started teaching myself C++, and do not use Game Maker regularly any more. You can follow my current project either on my DevBlog or in my topic on the Bay12 forums.

GENERATION 195G: EVERYTIME YOU SEE THIS DIVIDE YOUR MOTHERS MAIDEN BIRTHDAY BY WHAT YOU HAD FOR DINNER LAST NIGHT AND ADD Q. (ANTI-SOCIAL EXPERIMENT)

LINKS: My Script Collection - My Autotile Script - My Random Number Generator - My Process Runner Extension - My Detailed TDS Tutorial