I Wanna Community

Post your Code Snippets

0 Members and 1 Guest are viewing this topic.

Offline Sudnep

  • 124
  • OS:
  • Windows 10 Windows 10
  • Browser:
  • Chrome 45.0.2454.101 Chrome 45.0.2454.101
  • Playstyle: Keyboard
Post your Code Snippets
« 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: http://klazen.com/gm/

I'll start:

parShooterBoss - A simple parent that can be assigned to an object to give it the attributes of a generic shooter boss.
« Last Edit: September 30, 2015, 12:38:50 PM by Sudnep »

Offline klazen108

  • 286
  • your a kid now your a squid now
  • OS:
  • Windows 10 Windows 10
  • Browser:
  • Chrome 45.0.2454.101 Chrome 45.0.2454.101
    • Delicious-Fruit
  • Playstyle: Keyboard
Re: Post your Code Snippets
« Reply #1 on: September 30, 2015, 10:36:17 AM »
irandom_excluding script to pick a random number from 0 to some upper limit, skipping one number in the range

blast_shape script to blast a shape in cherries, including triangles, squares and stars

Triple Jump how to add triple jump to your game (shows exact edits for YoYoYo Engine, but the concept applies to all engines)

array_shuffle script to take an array and shuffle its elements

draw_rotated draw any sprite as if it were rotated into/out of the screen.

Offline Zurai

  • Administrator
  • 170
  • OS:
  • Windows 7/Server 2008 R2 Windows 7/Server 2008 R2
  • Browser:
  • Chrome 45.0.2454.101 Chrome 45.0.2454.101
  • Playstyle: Keyboard
Re: Post your Code Snippets
« Reply #2 on: October 08, 2015, 11:20:08 AM »
Move and Stop - Maybe more a beginner thingy but always useful.
Stop by and say hello at www.twitch.tv/zurairofl :PogChamp:

Derf

Re: Post your Code Snippets
« Reply #3 on: October 08, 2015, 02:57:48 PM »
Move and Stop - 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)

Offline lawatson

  • 331
  • I do things and I make things.
  • OS:
  • Windows 7/Server 2008 R2 Windows 7/Server 2008 R2
  • Browser:
  • Chrome 45.0.2454.101 Chrome 45.0.2454.101
  • Playstyle: Keyboard
Re: Post your Code Snippets
« Reply #4 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.
(click to show/hide)

smoke weed everyday

Offline WetWookie

  • 90
  • OS:
  • Windows 7/Server 2008 R2 Windows 7/Server 2008 R2
  • Browser:
  • Firefox 41.0 Firefox 41.0
  • Playstyle: Keyboard
Re: Post your Code Snippets
« Reply #5 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)

Derf

Re: Post your Code Snippets
« Reply #6 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. :~)

Offline Sudnep

  • 124
  • OS:
  • Windows 10 Windows 10
  • Browser:
  • Chrome 46.0.2490.71 Chrome 46.0.2490.71
  • Playstyle: Keyboard
Re: Post your Code Snippets
« Reply #7 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: 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
« Last Edit: December 11, 2015, 11:52:44 PM by Sudnep »

Offline patrickgh3

  • 169
  • stay optimistic! :D
  • OS:
  • Windows 7/Server 2008 R2 Windows 7/Server 2008 R2
  • Browser:
  • Chrome 46.0.2490.80 Chrome 46.0.2490.80
    • Github
  • Playstyle: Keyboard
Re: Post your Code Snippets
« Reply #8 on: November 01, 2015, 03:29:11 PM »
fontSetup - Shortcut for typing out several draw_set_somethings

oscillate - Modular script for making objects bob up and down, and similar effects

Offline RandomFangamer

  • 71
  • Pico Pico Piiiiiii
  • OS:
  • Windows 10 Windows 10
  • Browser:
  • Firefox 42.0 Firefox 42.0
  • Playstyle: Keyboard
Re: Post your Code Snippets
« Reply #9 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: http://www.gmlscripts.com




:ItsBoshyTime: o o o o o :denProgress: o o o o o :paraKid:

Offline zaphod77

  • 33
  • OS:
  • Windows 10 Windows 10
  • Browser:
  • Chrome 47.0.2526.111 Chrome 47.0.2526.111
  • Playstyle: Keyboard
Re: Post your Code Snippets
« Reply #10 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.
« Last Edit: January 29, 2016, 07:11:10 PM by zaphod77 »

Offline WetWookie

  • 90
  • OS:
  • Windows 7/Server 2008 R2 Windows 7/Server 2008 R2
  • Browser:
  • Firefox 44.0 Firefox 44.0
  • Playstyle: Keyboard
Re: Post your Code Snippets
« Reply #11 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)

Offline Smartkin

  • 11
  • Your average nerd
  • OS:
  • Windows 7/Server 2008 R2 Windows 7/Server 2008 R2
  • Browser:
  • Chrome 49.0.2623.87 Chrome 49.0.2623.87
  • Playstyle: Keyboard
Re: Post your Code Snippets
« Reply #12 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

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
« Last Edit: April 05, 2016, 03:51:31 AM by Smartkin »
Yuno Gasai is my waifu :^)

(click to show/hide)

Offline MrSlick

  • 13
  • OS:
  • Windows 10 Windows 10
  • Browser:
  • Chrome 49.0.2623.87 Chrome 49.0.2623.87
    • MrSlick
  • Playstyle: Keyboard
Re: Post your Code Snippets
« Reply #13 on: March 28, 2016, 06:36:18 PM »
http://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.
« Last Edit: March 28, 2016, 06:44:52 PM by Starz0r »

Offline patrickgh3

  • 169
  • stay optimistic! :D
  • OS:
  • Windows 10 Windows 10
  • Browser:
  • Chrome 49.0.2623.110 Chrome 49.0.2623.110
    • Github
  • Playstyle: Keyboard
Re: Post your Code Snippets
« Reply #14 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.

http://klazen.com/gm/eEq

EDIT: Updated version here: http://tinyurl.com/zx9ra6h
« Last Edit: February 20, 2017, 03:47:01 AM by patrickgh3 »