Page 1 of 1

What is a good way to anti-moon walk?

PostPosted: Tue May 01, 2012 9:54 pm
by Goomba
I need help again... How do you do a moonwalk i did someone's tutorial... but I found a glitch that won't let me sleep :wink: but i need help i made a game that's very hard (so don't expect ged i will make an example with another file :D ) and the platforms are like the picture shows... then when you jump and hold jump you stick to the platform... you can move but are still stuck to the platform (like in "after" picture) then when you move off the platform you go up like you just jumped!!! its so annoying!! :evil: :evil: could someone help... and like i said the game itself is extremely hard so i wont put the ged up, i will make a similar game without enemies. :)

Re: What is a good way to anti-moon walk?

PostPosted: Tue May 01, 2012 10:09 pm
by skydereign
That isn't moonwalking. That is most likely caused by you not having separate collision events for the top and bottom of the ground actor. Because of that while you are colliding with the ceiling, your jump variable is set to 1 again, and you can keep jumping. If you are using collisions, you should have different collisions for the top side, bottom side, and another for the left/right side.

Re: What is a good way to anti-moon walk?

PostPosted: Tue May 01, 2012 10:28 pm
by Hblade
Draw Actor: Script Editor
Code: Select all
char*key=GetKeyState();

int dir=key[KEY_RIGHT]-key[KEY_LEFT];
int lastDir;


switch(dir)
{
    case 0: //none;
    switch(lastDir)
    {
        case 0: //right
            change animation to stop right
        break;
        case 1: //left
            change animation to stop left
        break;
    }
    break;
   
    case 1: //right;
        lastDir=0;
        x+=5;
        change animation to walk right
    break;
   
    case -1: //left;
        lastDir=1;
        x-=5;
        change animation to walk left
    break;
}


There may be typos in that, I don't know, I wrote that from memory and tried a different thing.

Re: What is a good way to anti-moon walk?

PostPosted: Wed May 02, 2012 5:02 pm
by Goomba
Thank you hblade and skydereign uh I didn't know what to call it, the slide stick, and hblade i read the script and as you know the default pac-man actor doesn't have any animations except for the still :D :arrow: :roll: :arrow: :lol: but will i still need ALL of the code or could i take out the animation snippets? or would it not work that way.

Re: What is a good way to anti-moon walk?

PostPosted: Wed May 02, 2012 5:21 pm
by Hblade
You can remove the animation parts :) Here's a simpler code if your not using animations
For left and right:
Code: Select all
int kDir=key[KEY_RIGHT]-key[KEY_LEFT];

switch(kDir)
{
    case 0:
    break;
   
    case 1: //right
    x+=5;
    break;

    case -1: //left
    x-=5;
    break;
}


For all 4 directions:
Code: Select all
int lrDir=key[KEY_RIGHT]-key[KEY_LEFT];
int udDir=key[KEY_UP]-key[KEY_DOWN];

switch(lrDir)
{
    case 0:
    break;
   
    case 1: //right
    x+=5;
    break;

    case -1: //left
    x-=5;
    break;
}
switch(udDir)
{
    case 0:
    break;
   
    case 1: //up
    y-=5;
    break;

    case -1: //down
    y+=5;
    break;
}


:D now you can use the arrow keys to move :)

Re: What is a good way to anti-moon walk?

PostPosted: Wed May 02, 2012 5:25 pm
by skydereign
Hblade wrote:You can remove the animation parts :) Here's a simpler code if your not using animations
For left and right:
Code: Select all
int kDir=key[KEY_RIGHT]-key[KEY_LEFT];

switch(kDir)
{
    case 0:
    break;
   
    case 1: //right
    x+=5;
    break;

    case -1: //left
    x-=5;
    break;
}

That is the same thing as this.
Code: Select all
char* key = GetKeyState();
x+=(key[KEY_RIGHT]-key[KEY_LEFT])*5;


Hblade wrote:For all 4 directions:
Code: Select all
int lrDir=key[KEY_RIGHT]-key[KEY_LEFT];
int udDir=key[KEY_UP]-key[KEY_DOWN];

switch(lrDir)
{
    case 0:
    break;
   
    case 1: //right
    x+=5;
    break;

    case -1: //left
    x-=5;
    break;
}
switch(udDir)
{
    case 0:
    break;
   
    case 1: //up
    y-=5;
    break;

    case -1: //down
    y+=5;
    break;
}

And that is the same as this.
Code: Select all
char* key = GetKeyState();
x+=(key[KEY_RIGHT]-key[KEY_LEFT])*5;
y+=(key[KEY_DOWN]-key[KEY_UP])*5;

Re: What is a good way to anti-moon walk?

PostPosted: Wed May 02, 2012 5:56 pm
by Goomba
Thanx to the both of you this is a great help i will test it soon and maybe put the game up...(after i make it easier :D ) Thank you very much... I have a question though... which code would be better to use hblade's or skydereign's skydereign's is shorter but hblade's is probably more detailed then again i daon't know much about C so it's probably the same... :oops: oops sorry i was ranting on was I? :oops: :arrow: :lol:

Re: What is a good way to anti-moon walk?

PostPosted: Wed May 02, 2012 6:34 pm
by Hblade
Oh wow sky :D wow... I really need to start thinking outside the box xD

Re: What is a good way to anti-moon walk?

PostPosted: Wed May 02, 2012 10:11 pm
by Goomba
SO are they the same? :?

Re: What is a good way to anti-moon walk?

PostPosted: Wed May 02, 2012 11:27 pm
by skydereign
If that is the only code you use, yes they are the same. My version is better, as it is more concise, and doesn't use unnecessary variables. But, if you wanted to add code depending on the direction (animation changes for instance) you would have to use Hblade's. I only posted the shorter code because he was posting them with the intent that there was no animation.

Re: What is a good way to anti-moon walk?

PostPosted: Thu May 03, 2012 2:56 am
by Hblade
Agreed, his code is for sure shorter, and less power-hungry

Re: What is a good way to anti-moon walk?

PostPosted: Thu May 03, 2012 4:37 pm
by Goomba
Got it and thank you very much :D :D :D