I Wanna Community

Fangames => Game Design => Topic started by: Sudnep on September 30, 2015, 10:07:58 AM

Title: Post your Code Snippets
Post by: Sudnep on September 30, 2015, 10:07:58 AM
Since this forum is now mostly dead because of the separation of Gamemaker Questions and Game Design I figured this would probably be a useful thread for posting interesting/easy to implement code.

Alternative way to post: https://klazen.com/gm/ (https://klazen.com/gm/)

I'll start:

parShooterBoss (https://klazen.com/gm/MP) - A simple parent that can be assigned to an object to give it the attributes of a generic shooter boss.
Title: Re: Post your Code Snippets
Post by: klazen108 on September 30, 2015, 10:36:17 AM
irandom_excluding (https://klazen.com/gm/x2) script to pick a random number from 0 to some upper limit, skipping one number in the range

blast_shape (https://klazen.com/gm/nl) script to blast a shape in cherries, including triangles, squares and stars

Triple Jump (https://klazen.com/gm/8g) how to add triple jump to your game (shows exact edits for YoYoYo Engine, but the concept applies to all engines)

array_shuffle (https://klazen.com/gm/AN) script to take an array and shuffle its elements

draw_rotated (https://klazen.com/gm/EAq) draw any sprite as if it were rotated into/out of the screen.
Title: Re: Post your Code Snippets
Post by: Zurai on October 08, 2015, 11:20:08 AM
Move and Stop (https://klazen.com/gm/lE) - Maybe more a beginner thingy but always useful.
Title: Re: Post your Code Snippets
Post by: Derf on October 08, 2015, 02:57:48 PM
Move and Stop (https://klazen.com/gm/lE) - Maybe more a beginner thingy but always useful.
Boy I'm gonna need to see some indenting and semi-colon line termination or else it's gonna be a ticket.

(srs though it's a nice simple code that pretty much anyone can benefit from)
Title: Re: Post your Code Snippets
Post by: lawatson on October 08, 2015, 03:03:12 PM
Rainbowness!
(click to show/hide)

Make sure to use it on black and white sprites for the most effect.
Title: Re: Post your Code Snippets
Post by: WetWookie on October 09, 2015, 12:45:07 PM
Wookie's Bugs.

Give them a small sprite (I used 7x7) with the origin in the center and uncheck "visible" in the object. Place the bug anywhere on the screen and on startup it will find a random block, place itself there, turn itself visible and start wandering around.

(click to show/hide)
(click to show/hide)
(click to show/hide)

Known issues: Crawls onto invisible objects (triggers)
Title: Re: Post your Code Snippets
Post by: Derf on October 09, 2015, 03:44:33 PM
Super cheap day/night cycle I'm using in one of my latest games. Works best over a background of clouds.

Create:
Code: [Select]
c1 = make_color_rgb(29,68,73);
c2 = make_color_rgb(89,146,199);
c3 = make_color_rgb(237,189,104);
c4 = make_color_rgb(150,222,219);
c5 = make_color_rgb(70,42,100);
c6 = make_color_rgb(242,95,52);
c7 = make_color_rgb(83,12,0);
c8 = make_color_rgb(14,19,38);
c9 = make_color_rgb(1,2,6);
c0 = make_color_rgb(45,37,78);
col1 = c1;
col2 = c3;
con = 0;
pha = 0;
inc = 0.125/2;

Step:
Code: [Select]
switch(pha){
     case 0:
          col1 = merge_color(c1,c2,con/100);
          col2 = merge_color(c3,c4,con/100);
     break;

     case 1:
          col1 = merge_color(c2,c5,con/100);
          col2 = merge_color(c4,c6,con/100);
     break;

     case 2:
          col1 = merge_color(c5,c7,con/100);
          col2 = merge_color(c6,c8,con/100);
     break;

     case 3:
          col1 = merge_color(c7,c9,con/100);
          col2 = merge_color(c8,c0,con/100);
     break;

     case 4:
          col1 = merge_color(c9,c1,con/100);
          col2 = merge_color(c0,c3,con/100);
     break;
}

con += inc;

if(con == 100){
     con = 0;
     pha += 1;
}

if(pha >= 5){
    pha = 0;
}

Draw:
Code: [Select]
draw_set_blend_mode_ext(bm_src_color,bm_src_color);
draw_set_alpha(0.5);
draw_rectangle_color(0,0room_width,room_height,col1,col1,col2,col2,0);
draw_set_blend_mode(bm_normal);
draw_set_alpha(1);

Free to use; don't care about credit. I would appreciate changing the colours + increment so the effects aren't completely identical but either way I'm not really too bothered. :~)
Title: Re: Post your Code Snippets
Post by: Sudnep on October 21, 2015, 09:47:23 AM
This was made more for myself than other people but I'm sure people can find a use for it / edit it for their own personal use.

Orbiting Objects (https://klazen.com/gm/Wy): Used for making an 'objProjectile' orbit about a point or another object. I'll update the link if I find any bugs with it.

updated dec 11, 2015
Title: Re: Post your Code Snippets
Post by: patrickgh3 on November 01, 2015, 03:29:11 PM
fontSetup (https://klazen.com/gm/kR) - Shortcut for typing out several draw_set_somethings

oscillate (https://klazen.com/gm/bR) - Modular script for making objects bob up and down, and similar effects
Title: Re: Post your Code Snippets
Post by: RandomFangamer on December 19, 2015, 08:51:36 AM
Found this nice site called GMLScripts
It has several scripts that allow you do to many things with instances, sprites, etc.
Link: https://www.gmlscripts.com (https://www.gmlscripts.com)
Title: Re: Post your Code Snippets
Post by: zaphod77 on January 19, 2016, 06:21:06 PM
This is for I wanna Be The Studio Engine YoYoYo Edition.

I've created a cherry that will after a number of ticks that you can assign after creation, aim itself at the player, and that will repeat the action a defined number of times. It can optionally change speed when it does this, and then change speed again each time after.

(click to show/hide)

I modifed scrCreateShapes for testing this.  you can, of course, make colored versions of this object easily enough.

There are many things you can do with this object.

1) make a shape that expands, then aims all it's cherries at you.
2) make a shot that curves towards you for a bit and accelerates
3) place a mine that speeds off in your direction a while later.

making versions of other/random colors is left as an exercise to the reader.
Title: Re: Post your Code Snippets
Post by: WetWookie on March 09, 2016, 12:27:33 PM
Someone asked me for my water droplet code so here ya go. Object drips down blocks and slides along the edges of spikes.

(click to show/hide)

(click to show/hide)

(click to show/hide)
Title: Re: Post your Code Snippets
Post by: Smartkin on March 27, 2016, 06:29:57 AM
People probably already made this thousands of times but decided to write this myself. This is a code that let's you make the object fade in and out, or just fade in, or just fade out - scrAlphaFade (https://klazen.com/gm/6EW)

Oh, yeah if you work in Studio you should have currentFade variable defined in the creation code of every object that will use this script.

Edit: I decided to go even further and created a script that will let you mess with fading any variable you want to - scrValFade (https://klazen.com/gm/a7Q)
Title: Re: Post your Code Snippets
Post by: MrSlick on March 28, 2016, 06:36:18 PM
https://klazen.com/gm/AjN
All credit goes to YoYo for this script. I only added too it.
The description says what it does and all the arguments are documented. :)

ADMIN EDIT: snippet edit panel was showing, be more careful next time.
Title: Re: Post your Code Snippets
Post by: patrickgh3 on April 05, 2016, 06:24:27 PM
I made a pretty nice pushable block that feels smooth, drops into 32px gaps, and is configurable. PM if you find any issues.

https://klazen.com/gm/eEq

EDIT: Updated version here: https://tinyurl.com/zx9ra6h
Title: Re: Post your Code Snippets
Post by: Sudnep on June 19, 2016, 02:52:32 AM
These are just a bunch of scripts I use for generic effects in avoidance. :) Hopefully someone finds these useful. If you have any problems or errors message me on discord @ Sudnep#2735

The way to use these scripts is to run these scripts is to run scrCreateEvent in the object's create event and then in the step event write whatever scripts you want the object to do within it. An example can be found here: link (https://klazen.com/gm/Wja)

(click to show/hide)

(click to show/hide)

(click to show/hide)

(click to show/hide)

(click to show/hide)

(click to show/hide)

(click to show/hide)

(click to show/hide)

(click to show/hide)

(click to show/hide)

(click to show/hide)

(click to show/hide)

(click to show/hide)

(click to show/hide)

(click to show/hide)

(click to show/hide)

(click to show/hide)

A zip file containing all of the script.gml files and objTrail for studio can be found here: link (https://puu.sh/py0BV/8ddde9bbe6.rar)
Title: Re: Post your Code Snippets
Post by: bananaguy12mhc on June 19, 2016, 01:31:35 PM
Thank you so much Sudnep!  :atkHappy:
Title: Re: Post your Code Snippets
Post by: klazen108 on August 01, 2016, 10:27:59 PM
Easy Spotlight Shader (https://klazen.com/IWBTG/archive/spotlight_test.gmz) - This one's a gmz because it comes with a sprite, shader, script, and example object and room! Shows a super easy method of creating spotlights without needing a huge sprite with a cutout, crazy blend modes, or any other complicated hacks - Just a function called "draw_spotlight"!
Title: Re: Post your Code Snippets
Post by: Zapmunk on August 09, 2016, 12:40:55 AM
A little script I wrote to replace gamemaker's tragic lack of a move_contact_object function. Could be a good start for anyone who wants to convert the physics to non-solid blocks like me.

(click to show/hide)

It works more or less like move_contact_solid, except:
Title: Re: Post your Code Snippets
Post by: Zapmunk on January 28, 2017, 05:53:16 PM
A fragment shader for converting to and from HSV. Useful for performing color effects.
The shader supplied here replaces the default image_blend functionality with something like the sprite editor's colorize function, but it can be easily be modified to do other HSV-color-space effects. (I recommend against using it for anything that doesn't require hue though, since saturation and volume can both be manipulated directly in RGB color space)

(click to show/hide)
Title: Re: Post your Code Snippets
Post by: patrickgh3 on February 20, 2017, 03:46:45 AM
Updated my nice-feeling push blocks. Fixed some bugs, and made the code simpler. https://tinyurl.com/zx9ra6h