Page 1 of 1

any one know code for is a key is pressed down

PostPosted: Sun Jun 20, 2010 2:02 am
by lllllsp1d3rlllll
if i press right key my starts walking to the right if while walking i press the punch button without letting up on the right key my guy stops walking and punches when i let up on my punch key right key is still down but my guy is not walking right and animation is not playing i need do some code after punch animation is finished to check if any other keys are down if so play animation for that key so my guy will after he punches to start walking again and play walking right animation any help????

Re: any one know code for is a key is pressed down

PostPosted: Sun Jun 20, 2010 10:57 am
by Camper1995
I know how to do
to that! But its little bit complicated.

I need to ask you, do you know what are variables and how to use them?

Re: any one know code for is a key is pressed down

PostPosted: Sun Jun 20, 2010 2:37 pm
by Bee-Ant
Add this on Global code :
Code: Select all
char State[2][8]={"Stop","Walk"};
char Names[4][16]={"Player1","Player2","Player3","Player4"};
char Direction[3][8]={"Left","NULL","Right"};
char AnimName[24]; //to return animation name later
int anim; //to break the animation
int direct; //the direction index, -1=Left, 1=Right
int type; //character index, 0=Player1, 1=Player2, etc...
int state; //state index, 0=Stop, 1=Walk
int attack; //attack index, 0=No attack, 1=Attack
int speed; //or change this value into any value you want


Add this on Player->CreateActor :
Code: Select all
type=0;
speed=6;
direct=1;
sprintf(AnimName,"%s%s%s",Names[type],State[state],Direction[direct+1]);
ChangeAnimation("Event Actor", AnimName, FORWARD);


Add this on Player->DrawActor :
Code: Select all
x+=state*direct*speed*(attack==0);
if(attack==0&&anim==0)
{
    sprintf(AnimName,"%s%s%s",Names[type],State[state],Direction[direct+1]);
    ChangeAnimation("Event Actor", AnimName, FORWARD);
    anim=1;
}


Add this on Player->AnimationFinish :
Code: Select all
anim=0;
attack=0;


Add this on Player->Keydown->Left :
Code: Select all
if(attack==0)
{
    state=1;
}
direct=-1;


Add this on Player->Keydown->Right :
Code: Select all
if(attack==0)
{
    state=1;
}
direct=1;


Add this on Player->Keydown->Punch :
Code: Select all
sprintf(AnimName,"%sPunch%s",Names[type],Direction[direct+1]);
ChangeAnimation("Event Actor", AnimName, FORWARD);
attack=1;


Add this on Player->Keydown->Kick :
Code: Select all
sprintf(AnimName,"%sKick%s",Names[type],Direction[direct+1]);
ChangeAnimation("Event Actor", AnimName, FORWARD);
attack=1;


Please note :
In this case, your player must has animation :
- Player1StopLeft
- Player1StopRight
- Player1WalkLeft
- Player1WalkRight
- Player1PunchLeft
- Player1PunchRight
- Player1KickLeft
- Player1KickRight

Good luck :D

Re: any one know code for is a key is pressed down

PostPosted: Sun Jun 20, 2010 2:41 pm
by Hblade
AWESOME BEE-ANT :D!

Re: any one know code for is a key is pressed down

PostPosted: Sun Jun 20, 2010 2:47 pm
by Bee-Ant
Hblade wrote:AWESOME BEE-ANT :D!

Thanks... :mrgreen:

Oh yah, you can also change the code on :
- Player->KeyDown->Left to be :
Code: Select all
state=(attack==0);
direct=-1;

- Player->KeyDown->Right to be :
Code: Select all
state=(attack==0);
direct=1;

to minimalize the IFs... :P

Re: any one know code for is a key is pressed down

PostPosted: Sun Jun 20, 2010 7:21 pm
by Camper1995
That's exactly what I wanted to say! :mrgreen: :mrgreen: :D

Good job Bee 8)

Re: any one know code for is a key is pressed down

PostPosted: Sun Jun 20, 2010 7:56 pm
by krenisis
Solid coding from the master himself bee-ant.

Re: any one know code for is a key is pressed down

PostPosted: Sun Jun 20, 2010 8:06 pm
by Bee-Ant
Camper1995 wrote:That's exactly what I wanted to say!

Good job Bee

Thanks... :D

krenisis wrote:Solid coding from the master himself bee-ant.

:P
I'm not a master...there's a sky above the sky

Re: any one know code for is a key is pressed down

PostPosted: Sun Jun 20, 2010 8:31 pm
by krenisis
Yes bee-ant there is a sky above the sky ....but your already in the universe above the sky. No way can sky ever compare to you.

Re: any one know code for is a key is pressed down

PostPosted: Sun Jun 20, 2010 10:37 pm
by lllllsp1d3rlllll
YEA I GOT IT TO MUCH CODE THERE ALL I HAVE TO DO IS ADD INTEGER AND TURN IT ON AND OFF OFF WHEN KEY PRESSED ON AFTER ANIMATION TO STOP EVERY THING ELSE IM NOT PLAYING AROUND IM MAKING SOMTHING 100% PLAYABLE LOL TAKES ME 1 DAY TO ADD ONE KICK OR PUNCH OR PARTICULAR FUNTION COUS I TAKE MY TIME AND GET EVERY THING CORRECT SO MY GAME WHEN FINISHED WILL LOOK EXACTLY LIKE A SUPER NINTENDO GAME FULL WITH ACTOR SELECT MENUE INJURY BAR SOUNDS AND SPEACIAL MOVES AND WILL USE ALL BUTTONS THAT A PS3 CONTROLER HAS WITCH IS 12 NOT INCLUDING 2 ANOLOG CONTROLS START BUTTON AND SELECT BUTTON

Re: any one know code for is a key is pressed down

PostPosted: Sun Jun 20, 2010 10:46 pm
by Bee-Ant
Thats right.
Fighting games much more complicated that any other games...

Re: any one know code for is a key is pressed down

PostPosted: Wed Nov 10, 2010 7:05 am
by Chai
Excellent code. This is code so wonderful.
Bee-Ant, you are really universe above the sky.

Re: any one know code for is a key is pressed down

PostPosted: Thu Nov 11, 2010 4:03 am
by Bee-Ant
Chai wrote:Excellent code. This is code so wonderful.
Bee-Ant, you are really universe above the sky.

Yet still I live on earth :P :P :P

Re: any one know code for is a key is pressed down

PostPosted: Fri Nov 12, 2010 12:35 am
by NightOfHorror
Bee-Ant wrote:
Chai wrote:Excellent code. This is code so wonderful.
Bee-Ant, you are really universe above the sky.

Yet still I live on earth :P :P :P

Okay, BEE for now on you will take every compliment.
You are the GE's best developer :D