Page 1 of 1

no if anti moonwalk

PostPosted: Tue Jul 31, 2012 1:13 am
by Hblade
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;
}

Re: no if anti moonwalk

PostPosted: Sat Aug 18, 2012 10:24 pm
by AliceXIII
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 :)

Re: no if anti moonwalk

PostPosted: Sun Aug 19, 2012 4:03 am
by Hblade
sweet!