SHMUP Snake Algorithm in GML (Game Maker 7)

A place for people with an interest in developing new shmups.
Post Reply
EddyMRA
Posts: 798
Joined: Wed Jan 26, 2005 9:36 am
Location: San Diego, CA, USA

SHMUP Snake Algorithm in GML (Game Maker 7)

Post by EddyMRA »

A very rudimentary but versatile SHMUP snake algorithm in GML. Now you can create your own snake enemies like those found in so many SHMUPS.

In the room, the "head" of the snake is placed, with creation code to set the snake's length and the gap between each body segment.

The snake follows your mouse cursor.

This algorithm can be adapted for Gradius-style Option movement.

This algorithm is parameter-based, getting its information from creation code, to allow customization.

Examples:

Image
Snakes can be of any length...

Image
...and of any follow distance between segments.

R-Type Outslay examples (bodylength = 32, stepdelay = 12):
ImageImage

Download the GMK source for the algorithm here: http://www.sendspace.com/file/sa7m2m
The age of Alluro and JudgeSpear is over.
User avatar
Pixel_Outlaw
Posts: 2636
Joined: Sun Mar 26, 2006 3:27 am

Post by Pixel_Outlaw »

I don't have Game Maker but I assume you simply move then update all of the sections to the head's previous x and y position? That is how the Gradius options work. You might also look into Bezer curve paths, those were too used extensively and are still used.
Some of the best shmups don't actually end in a vowel.
No, this game is not Space Invaders.
User avatar
worstplayer
Posts: 861
Joined: Sun Jun 17, 2007 6:48 pm
Location: Slovakia

Post by worstplayer »

It works and looks nice. Btw the way it works is perfect opposite of my snake. In yours, head moves segments following it, in mine, every segment has "owner" variable and it simply moves towards owner's position (it basically updates backwards).
You don't need queues this way and you can have some nice sequential explosions (segment is destroyed after it loses owner).
But yours is better in that it can be also used for trains (it follows the path of head exactly).
"A game isn't bad because you resent it. A game is bad because it's shitty."
320x240
Posts: 655
Joined: Fri Nov 16, 2007 12:07 pm
Location: France

Post by 320x240 »

Nice.
agustusx
Posts: 592
Joined: Tue Dec 02, 2008 6:08 pm

Post by agustusx »

thanks much for sharing
ApGames
Posts: 6
Joined: Wed Jun 08, 2011 9:02 am
Contact:

Re: SHMUP Snake Algorithm in GML (Game Maker 7)

Post by ApGames »

Does anyone have this file?
User avatar
Rozyrg
Posts: 918
Joined: Wed Feb 11, 2009 12:03 am
Location: Southeast USA

Re: SHMUP Snake Algorithm in GML (Game Maker 7)

Post by Rozyrg »

Whoa! Looks awesome! :shock: This will require some studying for sure.

I've only done the much more lazy (but still effective) kind that uses a single preset movement pattern with a time-delay between the creation of each segment. The one time I tried something fancier, it failed miserably. Considering that was back in 2009, I might be able to pull something better off now.

(I did figure out how to do those cool delayed explosions regardless of how the segments move, though.)
User avatar
BPzeBanshee
Posts: 4859
Joined: Sun Feb 08, 2009 3:59 am

Re: SHMUP Snake Algorithm in GML (Game Maker 7)

Post by BPzeBanshee »

I tried finding this among all of my old archived crap that spans across two computers and various hard drives but couldn't find it. I think my old external hard drive may have it, I'll go and check.

EDIT: Found it and uploaded it:
http://www.mediafire.com/?3pahpgxsu6szamn

It also has a script in there for turning towards an object, I wonder how well it does compared to what S20-TBL provided me for GMOSSE's homing missile objects that can lock on to another enemy if it's already gone.
ApGames
Posts: 6
Joined: Wed Jun 08, 2011 9:02 am
Contact:

Re: SHMUP Snake Algorithm in GML (Game Maker 7)

Post by ApGames »

Thanks, did my own version but this look much better!
User avatar
Drum
Banned User
Posts: 2116
Joined: Sun Feb 07, 2010 4:01 pm

Re: SHMUP Snake Algorithm in GML (Game Maker 7)

Post by Drum »

Thanks much for bumping this as this is perfect for me. Thanks also, of course, to Alluro for making it and BPzeBanshee for reuploading.
IGMO - Poorly emulated, never beaten.

Hi-score thread: http://shmups.system11.org/viewtopic.php?f=2&t=34327
vonWolfehaus
Posts: 6
Joined: Tue Nov 30, 2010 3:41 am

Re: SHMUP Snake Algorithm in GML (Game Maker 7)

Post by vonWolfehaus »

I've been looking for this alg for a while... but I don't have Game Maker, so can anyone paste the code/alg here please?
User avatar
BPzeBanshee
Posts: 4859
Joined: Sun Feb 08, 2009 3:59 am

Re: SHMUP Snake Algorithm in GML (Game Maker 7)

Post by BPzeBanshee »

vonWolfehaus wrote:I've been looking for this alg for a while... but I don't have Game Maker, so can anyone paste the code/alg here please?
If you don't have Game Maker, get it. It's worth your while. ;)

As for the code itself it's in various parts for events throughout a few objects and even some code that for some reason my copy of Game Maker won't let me access (probably outdated, 8.0 as opposed to 8.1). Not that easy to "paste the code/alg here" unless Alluro wants to do it.

There's also that other alternative that was coded in Java that lets you open Game Maker files but I forgot what it was called and couldn't find it via Google without a specific name. One of the forum members here has it in their signature.
vonWolfehaus
Posts: 6
Joined: Tue Nov 30, 2010 3:41 am

Re: SHMUP Snake Algorithm in GML (Game Maker 7)

Post by vonWolfehaus »

I need a bit more control so I use Flash :) I found the algorithm (written in C# so it's fairly clear what's happening), which I'll post here for anyone else interested:

Code: Select all

p[0] += dt * velocity;
//if you want the rotation of the "head", do this
float headRotation = (float)Math.Atan2(velocity.Y, velocity.X);
for (int i = 1; i < p.Length; i++) {
    Vector2 diff = p[i] - p[i - 1];  //vector pointing from p[i - 1] to p[i]
    diff.Normalize();
    p[i] = p[i - 1] + 5 * diff;

    //if you want the rotation of this "chain link", do this
    float rotation = (float)Math.Atan2(diff.Y, diff.X);
}
This assumes we have an array of Vector2 "chain link" positions "Vector2[] p". Also assumed is that we want each "chain link" to be a distance of 5 away from it's adjacent "chain links." The part I was missing was normalizing the difference vector. For Flash this is a fairly expensive operation (square roots are done to normalize the vector), but it's worth it for, say, a boss. Can't use it for fodder paths, so I'll have to figure that out later :(
Post Reply