any one know code for is a key is pressed down

Talk about making games.

any one know code for is a key is pressed down

Postby lllllsp1d3rlllll » Sun Jun 20, 2010 2:02 am

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????
for more from me check out my web site!!!
http://venom-codings.bravehost.com/index.html
lllllsp1d3rlllll
 
Posts: 27
Joined: Sun Dec 13, 2009 6:26 pm
Score: 1 Give a positive score

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

Postby Camper1995 » Sun Jun 20, 2010 10:57 am

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?
Say hello to my little friend.
User avatar
Camper1995
 
Posts: 707
Joined: Tue Dec 30, 2008 7:20 pm
Location: Lost in the past.
Score: 44 Give a positive score

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

Postby Bee-Ant » Sun Jun 20, 2010 2:37 pm

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
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: any one know code for is a key is pressed down

Postby Hblade » Sun Jun 20, 2010 2:41 pm

AWESOME BEE-ANT :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: any one know code for is a key is pressed down

Postby Bee-Ant » Sun Jun 20, 2010 2:47 pm

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
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: any one know code for is a key is pressed down

Postby Camper1995 » Sun Jun 20, 2010 7:21 pm

That's exactly what I wanted to say! :mrgreen: :mrgreen: :D

Good job Bee 8)
Say hello to my little friend.
User avatar
Camper1995
 
Posts: 707
Joined: Tue Dec 30, 2008 7:20 pm
Location: Lost in the past.
Score: 44 Give a positive score

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

Postby krenisis » Sun Jun 20, 2010 7:56 pm

Solid coding from the master himself bee-ant.
Tutorial Database for all beginners click this link
viewtopic.php?f=4&t=8680
krenisis
 
Posts: 606
Joined: Sat Jul 25, 2009 3:27 pm
Score: 51 Give a positive score

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

Postby Bee-Ant » Sun Jun 20, 2010 8:06 pm

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
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: any one know code for is a key is pressed down

Postby krenisis » Sun Jun 20, 2010 8:31 pm

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.
Tutorial Database for all beginners click this link
viewtopic.php?f=4&t=8680
krenisis
 
Posts: 606
Joined: Sat Jul 25, 2009 3:27 pm
Score: 51 Give a positive score

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

Postby lllllsp1d3rlllll » Sun Jun 20, 2010 10:37 pm

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
for more from me check out my web site!!!
http://venom-codings.bravehost.com/index.html
lllllsp1d3rlllll
 
Posts: 27
Joined: Sun Dec 13, 2009 6:26 pm
Score: 1 Give a positive score

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

Postby Bee-Ant » Sun Jun 20, 2010 10:46 pm

Thats right.
Fighting games much more complicated that any other games...
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: any one know code for is a key is pressed down

Postby Chai » Wed Nov 10, 2010 7:05 am

Excellent code. This is code so wonderful.
Bee-Ant, you are really universe above the sky.
User avatar
Chai
 
Posts: 361
Joined: Sat Apr 30, 2005 2:26 pm
Location: Thailand
Score: 30 Give a positive score

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

Postby Bee-Ant » Thu Nov 11, 2010 4:03 am

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
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: any one know code for is a key is pressed down

Postby NightOfHorror » Fri Nov 12, 2010 12:35 am

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
viewtopic.php?f=2&t=12136
"I have not failed. I just found 10,000 ways that wont work." quoted by Thomas Edison.
Over the year, I decided my motto for me is I am knowledgeable, but not practical.
User avatar
NightOfHorror
 
Posts: 1823
Joined: Fri Aug 27, 2010 2:50 am
Location: Cedar Hill, MO, of the USA
Score: 51 Give a positive score


Return to Game Development

Who is online

Users browsing this forum: No registered users and 1 guest