Page 1 of 1

A new idea for a faster, simpler anti-moonwalk

PostPosted: Wed Aug 04, 2010 7:04 pm
by Hblade
The idea, (Untested so far), is to make a variable called Stopped. When 2 of the opposite keys are pressed (Example: Up and down), it activates the variable called stop, which de-activates the ability to change animation or move. Then on Draw Actor, if the stopped variable is 1, use a bunch of animindex switches to determine the stopped animation :D For example...
Code: Select all
if (stopped == 1)
{
    switch(animindex)
    {
        case 0:
         ChangeAnim(Bleh...);
    }
}

And so on from there :P

It might work :o And it could look professional in gameplay wise :o It'll also save from typing zillions of lines of code lol

Re: A new idea for a faster, simpler anti-moonwalk

PostPosted: Wed Aug 04, 2010 8:06 pm
by savvy
hmm, interesting idea, i do it by animindex, so on the move right key(repeat disabled) it changes animation to moveR and then on "draw actor" i put
Code: Select all
if(animindex==0)
{
x+=5;
}
and then the same for left but with moveL and x-=5.

Re: A new idea for a faster, simpler anti-moonwalk

PostPosted: Wed Aug 04, 2010 8:34 pm
by Hblade
nice :D

Re: A new idea for a faster, simpler anti-moonwalk

PostPosted: Wed Aug 04, 2010 9:19 pm
by Game A Gogo
I remember I wrote a perfect anti-moonwalk code that goes in the draw actor event... I should remake that.

Code: Select all
char*key=GetKeyState();
if(key[KEY_LEFT]==1&&key[KEY_RIGHT]==0)
{
    changeanim
    x-=4;
}
else if(key[KEY_LEFT]==1&&key[KEY_RIGHT]==1)
{
    changeanimdirection(STOPPED); //replace with changeanim if you have a stopped animation o:
}
else if(key[KEY_LEFT]==0&&key[KEY_RIGHT]==1)
{
    changeanim
    x+=4;
}
else if(key[KEY_LEFT]==0&&key[KEY_RIGHT]==0)
{
    changeanimdirection(STOPPED); //replace with changeanim if you have a stopped animation o:
}


changeanim = ChangeAnimation
changeanimdirection= ChangeAnimationDirection

yaddi yadda

Re: A new idea for a faster, simpler anti-moonwalk

PostPosted: Wed Aug 04, 2010 9:28 pm
by savvy
whoa, ok, u win.

Re: A new idea for a faster, simpler anti-moonwalk

PostPosted: Wed Aug 04, 2010 11:07 pm
by Game A Gogo
I wish people would read the scripting documentation that came with GE... that's how I learned this code (It might not be directly there, but all the function's function and how to's is there, it doesn't take a genius to figure out how to use what you learn there to create stuff!)

Re: A new idea for a faster, simpler anti-moonwalk

PostPosted: Thu Aug 05, 2010 3:37 am
by DilloDude
Really awesome solution: we have two variables, kr and kl, representing the right key and left key, respectively. You can get them using GetKeyState, or set them on keyDown/Up events. Whatever you prefer.
Make a temporary variable - kdir.
Code: Select all
 kdir = kr - kl;

It will be 1 for right, -1 for left, and 0 for stopped. For adjusting speed, you can even use
Code: Select all
x += kdir * 5;
or something similar.
If bothe keys are pressed, it'll automatically be stopped.

This is especially awesome for 2d movement. We can use kx (kr - kl) for the x axis, and ky (kd - ku) for the y axis. If both are 0, we are stopped. Otherwise, direction(0, 0, kx, ky) will tell us the direction we are moving in. You can press any combinatin of keys, and it adjusts correctly.

Re: A new idea for a faster, simpler anti-moonwalk

PostPosted: Thu Aug 05, 2010 8:08 am
by savvy
what scripting documentation is this?

Re: A new idea for a faster, simpler anti-moonwalk

PostPosted: Thu Aug 05, 2010 1:38 pm
by Game A Gogo
Open GE, click on Help, then Documentation (Either first or second link), I wonder if people still read that... it's REALLY useful, it helps me from asking questions here a lot
anyway

Nice trick dillo!

Re: A new idea for a faster, simpler anti-moonwalk

PostPosted: Thu Aug 05, 2010 2:57 pm
by Bee-Ant
Ahhhhhh...why is everyone using IFs ???? he's my enemy !!!! :evil:
Here, the cleaner solution :arrow:

Global code :
Code: Select all
int dir; //-1:left, 1:right
int walk; //0:stop, 1:walk
char DirTxt[4][32]=
{
    "Left","Nothing","Right",
};
char WalkTxt[3][32]=
{
    "Stop","Walk",
};


Draw Actor :
Code: Select all
char animname[32];
sprintf(animname,"Player%s%s",DirTxt[dir+1],WalkTxt[walk]);
ChangeAnimation("Event Actor", animname, NO_CHANGE);

Re: A new idea for a faster, simpler anti-moonwalk

PostPosted: Thu Aug 05, 2010 9:29 pm
by Hblade
oh ma gawd thanks bee!! :D

Re: A new idea for a faster, simpler anti-moonwalk

PostPosted: Thu Aug 05, 2010 11:11 pm
by Game A Gogo
don't forget the:
Code: Select all
char*key=GetKeyState();
x+=(key[KEY_RIGHT]-key[KEY_LEFT])*5;

Re: A new idea for a faster, simpler anti-moonwalk

PostPosted: Fri Aug 06, 2010 7:40 am
by Bee-Ant
Game A Gogo wrote:don't forget the:
Code: Select all
char*key=GetKeyState();
x+=(key[KEY_RIGHT]-key[KEY_LEFT])*5;

Well...in that case, there's no need...
Just :
Code: Select all
x+=dir*speed*walk;