A new idea for a faster, simpler anti-moonwalk

Talk about making games.

A new idea for a faster, simpler anti-moonwalk

Postby Hblade » Wed Aug 04, 2010 7:04 pm

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
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: A new idea for a faster, simpler anti-moonwalk

Postby savvy » Wed Aug 04, 2010 8:06 pm

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.
--> For my help, i ask for a simple +1 if it helps! ^-^
--> I dont code, I type art which you dont understand.
--> I keep winning the 3D model challenge at college, teacher says: "you keep winning im not giving you prizes".
User avatar
savvy
 
Posts: 494
Joined: Wed Jun 03, 2009 11:55 am
Location: England
Score: 44 Give a positive score

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

Postby Hblade » Wed Aug 04, 2010 8:34 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: A new idea for a faster, simpler anti-moonwalk

Postby Game A Gogo » Wed Aug 04, 2010 9:19 pm

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
Programming games is an art,
    Respect it.
User avatar
Game A Gogo
 
Posts: 3466
Joined: Wed Jun 29, 2005 10:49 pm
Location: French Canada *laughs*
Score: 181 Give a positive score

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

Postby savvy » Wed Aug 04, 2010 9:28 pm

whoa, ok, u win.
--> For my help, i ask for a simple +1 if it helps! ^-^
--> I dont code, I type art which you dont understand.
--> I keep winning the 3D model challenge at college, teacher says: "you keep winning im not giving you prizes".
User avatar
savvy
 
Posts: 494
Joined: Wed Jun 03, 2009 11:55 am
Location: England
Score: 44 Give a positive score

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

Postby Game A Gogo » Wed Aug 04, 2010 11:07 pm

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!)
Programming games is an art,
    Respect it.
User avatar
Game A Gogo
 
Posts: 3466
Joined: Wed Jun 29, 2005 10:49 pm
Location: French Canada *laughs*
Score: 181 Give a positive score

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

Postby DilloDude » Thu Aug 05, 2010 3:37 am

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.
Image
User avatar
DilloDude
 
Posts: 866
Joined: Tue Jan 24, 2006 9:51 am
Location: Nyerellion
Score: 58 Give a positive score

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

Postby savvy » Thu Aug 05, 2010 8:08 am

what scripting documentation is this?
--> For my help, i ask for a simple +1 if it helps! ^-^
--> I dont code, I type art which you dont understand.
--> I keep winning the 3D model challenge at college, teacher says: "you keep winning im not giving you prizes".
User avatar
savvy
 
Posts: 494
Joined: Wed Jun 03, 2009 11:55 am
Location: England
Score: 44 Give a positive score

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

Postby Game A Gogo » Thu Aug 05, 2010 1:38 pm

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!
Programming games is an art,
    Respect it.
User avatar
Game A Gogo
 
Posts: 3466
Joined: Wed Jun 29, 2005 10:49 pm
Location: French Canada *laughs*
Score: 181 Give a positive score

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

Postby Bee-Ant » Thu Aug 05, 2010 2:57 pm

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);
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: A new idea for a faster, simpler anti-moonwalk

Postby Hblade » Thu Aug 05, 2010 9:29 pm

oh ma gawd thanks bee!! :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: A new idea for a faster, simpler anti-moonwalk

Postby Game A Gogo » Thu Aug 05, 2010 11:11 pm

don't forget the:
Code: Select all
char*key=GetKeyState();
x+=(key[KEY_RIGHT]-key[KEY_LEFT])*5;
Programming games is an art,
    Respect it.
User avatar
Game A Gogo
 
Posts: 3466
Joined: Wed Jun 29, 2005 10:49 pm
Location: French Canada *laughs*
Score: 181 Give a positive score

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

Postby Bee-Ant » Fri Aug 06, 2010 7:40 am

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;
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


Return to Game Development

Who is online

Users browsing this forum: No registered users and 1 guest