no if anti moonwalk

Learn how to make certain types of games and use gameEditor.

no if anti moonwalk

Postby Hblade » Tue Jul 31, 2012 1:13 am

this is an anti-moonwalk system without using if statements. It also uses a pixel system, so you dont start off moving instant speed,m you gain it but seamlessly.

Code: Select all
char*key=GetKeyState();
int dir=key[KEY_d]-key[KEY_a];

switch(dir)
{
    case 0:
        switch(animindex)
        {
            case 2: ChangeAnimation("Event Actor", "charStopLeft", NO_CHANGE);
            break;
            case 3: ChangeAnimation("Event Actor", "charStopRight", NO_CHANGE);
            break;
        }
        spd=0;
    break;
    case 1:
        spd = min(spd + 1, 7);
        x+=spd;
        ChangeAnimation("Event Actor", "charRight", NO_CHANGE);
    break;
    case -1:
        spd = min(spd + 1, 7);
        x-=spd;
        ChangeAnimation("Event Actor", "charLeft", NO_CHANGE);
    break;
}
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: no if anti moonwalk

Postby AliceXIII » Sat Aug 18, 2012 10:24 pm

im a little late on posting this but:

Code: Select all
char*key=GetKeyState();
//int dir=key[KEY_d]-key[KEY_a]; the int dir doesn't need to exist

switch(key[KEY_d]-key[KEY_a]) // the switch is capable of taking the keys as straight input
{
    case 0:
        switch(animindex)
        {
            case 2: ChangeAnimation("Event Actor", "charStopLeft", NO_CHANGE);
            break;
            case 3: ChangeAnimation("Event Actor", "charStopRight", NO_CHANGE);
            break;
        }
        spd=0;
    break;
    case 1:
        spd = min(spd + 1, 7);
        x+=spd;
        ChangeAnimation("Event Actor", "charRight", NO_CHANGE);
    break;
    case -1:
        spd = min(spd + 1, 7);
        x-=spd;
        ChangeAnimation("Event Actor", "charLeft", NO_CHANGE);
    break;
}


just something i've known for awhile and decided you might want to know also, read the code insert around where you created the int dir and the switch :)
"Taking a breath of fresh air."
User avatar
AliceXIII
 
Posts: 325
Joined: Fri Sep 17, 2010 2:36 am
Location: victoria, texas
Score: 37 Give a positive score

Re: no if anti moonwalk

Postby Hblade » Sun Aug 19, 2012 4:03 am

sweet!
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


Return to Tutorials

Who is online

Users browsing this forum: No registered users and 1 guest