Cool magnet script!

Talk about making games.

Cool magnet script!

Postby Hblade » Wed Nov 26, 2014 8:01 pm

This script lets you apply a magnetic pull effect =)
Code: Select all
void mag(char*a1, double power, double distance_to_mag, double max_vel)
{
    Actor*a=getclone(a1);
    if(distance(x, y, a->x, a->y)<=250)
    {
        a->angle=direction(a->x, a->y, x, y);
        if(distance(x, y, a->x, a->y)>=max_vel*2)
        {
            a->directional_velocity+=power;
        } else {
            a->directional_velocity-=power;
        }
        a->directional_velocity=min(max(a->directional_velocity, 0), max_vel);
    }
    else {
        a->directional_velocity=0;
         }
    if(distance(x, y, a->x, a->y)<=5)
    {
        a->directional_velocity=.05;
    }
}


Usage: (In a draw actor script of the magnet-actor)
Code: Select all
mag("object_to_mag", .5, 50, 25);
mag("balls.0", 1.5, 50, 25);
mag("balls.1", 1.15, 50, 25);
mag("balls.2", 1.25, 50, 25);
mag("balls.3", 1.35, 50, 25);
mag("balls.4", 1.45, 50, 25);


How to use:
Code: Select all
mag("ACTOR_TO_PULL", speed, magnet_range, max_pull_speed);


Demo:
mag.zip
(11.42 KiB) Downloaded 119 times


Screenshot:
scrn.png
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Re: Cool magnet script!

Postby digiot » Wed Nov 26, 2014 8:32 pm

Nice one, thanks !

Cheers !
User avatar
digiot
 
Posts: 211
Joined: Sat Mar 17, 2012 2:29 pm
Score: 7 Give a positive score

Re: Cool magnet script!

Postby Hblade » Wed Nov 26, 2014 8:36 pm

hehe :D

I updated it to have a push effect now O:..

Code: Select all
#define PUSH 1
#define PULL 0

void mag(char*a1, int type, double power, double distance_to_mag, double max_vel)
{
    Actor*a=getclone(a1);
    if(distance(x, y, a->x, a->y)<=250)
    {
        switch(type)
        {
            case 0:
            a->angle=direction(a->x, a->y, x, y);
            break;
            case 1:
            a->angle=direction(-a->x, -a->y, -x, -y);
            break;
        }
        if(distance(x, y, a->x, a->y)>=max_vel*2)
        {
            a->directional_velocity+=power;
        } else {
            a->directional_velocity-=power;
        }
        a->directional_velocity=min(max(a->directional_velocity, 0), max_vel);
    }
    else {
        a->directional_velocity=0;
         }
    if(distance(x, y, a->x, a->y)<=5)
    {
        a->directional_velocity=.05;
    }
}


New usage:
mag("object_to_mag", PUSH, .5, 50, 25);

You can either have PUSH or PULL :D
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Re: Cool magnet script!

Postby MrJolteon » Wed Nov 26, 2014 9:56 pm

Cool.
Join us on Discord!
Game Editor 2
These are the best ways to reach me these days


Your local Community Janitor, always lurking in the shadows...
User avatar
MrJolteon
 
Posts: 2326
Joined: Sat Aug 09, 2008 3:25 pm
Location: Stranded under endless sky
Score: 105 Give a positive score

Re: Cool magnet script!

Postby digiot » Wed Nov 26, 2014 10:06 pm

I hope, Sky also has thrown out that terror of editor...

Maybe, adding a switch for push or pull would be funny !

Cheers !
User avatar
digiot
 
Posts: 211
Joined: Sat Mar 17, 2012 2:29 pm
Score: 7 Give a positive score

Re: Cool magnet script!

Postby lcl » Wed Nov 26, 2014 10:38 pm

digiot wrote:I hope, Sky also has thrown out that terror of editor...

What do you mean?
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Re: Cool magnet script!

Postby digiot » Wed Nov 26, 2014 11:08 pm

@ Lcl : I just had a horrible contact with GEs editor after a while, shocking !
And I hope, Sky has at least pimped it a little !

Here is my bloody hack to switch between pushing and pulling, just press
p, and it will change.

Cheers !
Attachments
mag_switch.tar.gz
(9.74 KiB) Downloaded 93 times
User avatar
digiot
 
Posts: 211
Joined: Sat Mar 17, 2012 2:29 pm
Score: 7 Give a positive score

Re: Cool magnet script!

Postby DjVan » Fri Nov 28, 2014 9:12 am

Hblade (somewhere) wrote:At the moment, one thing I can think of would be to create a boss made of multiple parts.


this magnet demo might do it as well..
i can't think of the numbers of things i can do with this 8)
Attachments
magnet snake.rar
(10.32 KiB) Downloaded 99 times
2.B.A
User avatar
DjVan
 
Posts: 24
Joined: Fri May 23, 2014 4:09 pm
Location: Pallet town
Score: 3 Give a positive score

Re: Cool magnet script!

Postby Hblade » Fri Nov 28, 2014 7:30 pm

nice :D
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Re: Cool magnet script!

Postby Zivouhr » Fri Nov 28, 2014 10:39 pm

Thanks HBlade. Sounds cool.
City of Rott Game created on Game Editor http://cityofrott.wordpress.com/
User avatar
Zivouhr
 
Posts: 549
Joined: Sat May 17, 2014 2:12 pm
Score: 59 Give a positive score


Return to Game Development

Who is online

Users browsing this forum: No registered users and 1 guest