Simple ANTI-MOONWALK script

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

Simple ANTI-MOONWALK script

Postby Hblade » Thu May 17, 2012 4:56 am

Ever have that moonwalk bug? Now you can fix it easily with 1 line of code
(NOTE: THIS IS FOR VERY BASIC MOVEMENT STYLE, SIMPLE LEFT AND RIGHT ONLY.. Does not include jumping animations, crouching etc)
Code: Select all
void doPlayer(int speed, char*walkLeft, char*walkRight, char*standLeft, char*standRight)
{
    char*key=GetKeyState();
    int dir=key[KEY_RIGHT]-key[KEY_LEFT];
    switch(dir)
    {
        case 0: break;
        case 1: ChangeAnimation("Event Actor", walkRight, NO_CHANGE); break;
        case -1: ChangeAnimation("Event Actor", walkLeft, NO_CHANGE); break;
    }
 
    x+=(dir*speed);
 
    if(dir==0)
    {
        if(animindex==getAnimIndex(walkRight))
        {
            ChangeAnimation("Event Actor", standRight, NO_CHANGE);
        }
        else if(animindex==getAnimIndex(walkLeft))
        {
            ChangeAnimation("Event Actor", standLeft, NO_CHANGE);
        }
    }
}



To use:
in Draw Actor of the player, write something similar to this
Code: Select all
doPlayer(5, "walkLeft", "walkRight", "standLeft", "standRight");


Whereas walkLeft is the name of the animation for walkLeft, etc.



Let me know if this works :)

Also:
use arrow keys to move
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: Simple ANTI-MOONWALK script

Postby Bee-Ant » Sun May 20, 2012 5:18 pm

My method

Player -> Draw Actor:
Code: Select all
char Direct[4][16]={"Left","none","Right"};
char State[3][16]={"Stand", "Walk"};
char *key=GetKeyState();
int dir, state=(key[KEY_RIGHT]||key[KEY_LEFT]), speed=5;
char str[64];
x+=dir*speed;
sprintf(str,"%s%s",State[state],Direct[dir+1]);
ChangeAnimation("Event Actor", str, NO_CHANGE);
dir=key[KEY_RIGHT]-key[KEY_LEFT];


That's all :)

Requirement:
- Player with "StandLeft", "StandRight", "WalkLeft", and "WalkRight" animations
- Move it with Arrow Left and Right keys
User avatar
Bee-Ant
 
Posts: 3723
Joined: Wed Apr 11, 2007 12:05 pm
Location: http://www.instagram.com/bee_ant
Score: 210 Give a positive score

Re: Simple ANTI-MOONWALK script

Postby Hblade » Mon May 21, 2012 1:08 am

Very excellent bee! I'd expect amazing code from you :)
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