moving and attacking

Non-platform specific questions.

moving and attacking

Postby DollMaster » Tue Sep 04, 2007 6:44 am

Hey guys im back again, and I need help.

I used the code from http://game-editor.com/forum/viewtopic.php?f=2&t=1655&start=0&st=0&sk=t&sd=a this thread to make myself a walking script. However, I cannot seem to add an attacking feature to it. Can anyone show me what to add and how so that when I press 'L" the player changes to his attack animation. The player can still move while he is attacking, as long as he is facing the correct way. I played aroudn with this for quite some time, but i cannot get it to work.

Here is the code I used:

draw actor--

Code: Select all
char *key=GetKeyState();

if (key[KEY_UP]==1) y-=2;
if (key[KEY_DOWN]==1) y+=2;
if (key[KEY_LEFT]==1) x-=2;
if (key[KEY_RIGHT]==1) x+=2;



keydown - left
Code: Select all
char *key=GetKeyState();


if (key[KEY_UP]==0&&key[KEY_RIGHT]==0&&key[KEY_DOWN]==0)
ChangeAnimation("Event Actor", "run_left", FORWARD);
else if (key[KEY_UP]==1&&key[KEY_RIGHT]==0&&key[KEY_DOWN]==0)
ChangeAnimation("Event Actor", "run_up", FORWARD);
else if (key[KEY_UP]==0&&key[KEY_RIGHT]==1&&key[KEY_DOWN]==0)
ChangeAnimation("Event Actor", "stop_right", FORWARD);
else if (key[KEY_UP]==0&&key[KEY_RIGHT]==0&&key[KEY_DOWN]==1)
ChangeAnimation("Event Actor", "run_down", FORWARD);


keyup - left
Code: Select all
char *key=GetKeyState();


if (key[KEY_UP]==0&&key[KEY_DOWN]==0&&key[KEY_RIGHT]==0)
ChangeAnimation("Event Actor", "stop_left", FORWARD);
else if (key[KEY_UP]==1&&key[KEY_DOWN]==0&&key[KEY_RIGHT]==0)
ChangeAnimation("Event Actor", "run_up", FORWARD);
else if (key[KEY_UP]==0&&key[KEY_DOWN]==1&&key[KEY_RIGHT]==0)
ChangeAnimation("Event Actor", "run_down", FORWARD);
else if (key[KEY_UP]==0&&key[KEY_DOWN]==0&&key[KEY_RIGHT]==1)
ChangeAnimation("Event Actor", "run_right", FORWARD);
DollMaster
 
Posts: 65
Joined: Fri Jun 16, 2006 2:38 am
Score: 2 Give a positive score

Re: moving and attacking

Postby DollMaster » Thu Sep 06, 2007 4:05 am

Correction, I have changed my code to the following as it seems to allow me more freedom to modify code. However, there are a couple of problems. Someone please help me, I am a bad programmer...this is the extent of my abilities.

1)He moon walks when odd combination of buttons are pressed.Can anyone please help me fix this?

2)I do not want the attack animation to keep playing as the attack button is held down. But it happens. Also if pressed and released too fast, animation does not finish.Is there anyway to play an animation only once?

For each direction:
key down - down
Code: Select all
y=y+3;
dir=1;
move=1;


key up - down
Code: Select all
move=0;
if(dir==1&&move==0)
ChangeAnimation("Event Actor", "stop_down", FORWARD);


key down - l (attack)
Code: Select all
//this is my attack animation
if(dir==1)
ChangeAnimation("Event Actor", "heroa", FORWARD);
else if(dir==2)
ChangeAnimation("Event Actor", "heroal", FORWARD);
else if(dir==3)
ChangeAnimation("Event Actor", "heroau", FORWARD);
else if(dir==4)
ChangeAnimation("Event Actor", "heroar", FORWARD);


key up - l (attack)
Code: Select all
//this code makes the actor switch to walking or stopping depending on his direction.
//i do not like this code because if button is held down, the actor keeps swinging,
//also if pressed and released too quickly attack animation does not finish

if(dir==1&&move==1)
ChangeAnimation("Event Actor", "run_down", FORWARD);
else if(dir==2&&move==1)
ChangeAnimation("Event Actor", "run_left", FORWARD);
else if(dir==3&&move==1)
ChangeAnimation("Event Actor", "run_up", FORWARD);
else if(dir==4&&move==1)
ChangeAnimation("Event Actor", "run_right", FORWARD);

if(dir==1&&move==0)
ChangeAnimation("Event Actor", "stop_down", FORWARD);
else if(dir==2&&move==0)
ChangeAnimation("Event Actor", "stop_left", FORWARD);
else if(dir==3&&move==0)
ChangeAnimation("Event Actor", "stop_up", FORWARD);
else if(dir==4&&move==0)
ChangeAnimation("Event Actor", "stop_right", FORWARD);
DollMaster
 
Posts: 65
Joined: Fri Jun 16, 2006 2:38 am
Score: 2 Give a positive score

Re: moving and attacking

Postby pixelpoop » Thu Sep 06, 2007 4:37 am

I'm not a strong programmer but maybe you can use a switch instead of if/then statements for some. This way only one of the options will be executed.
User avatar
pixelpoop
 
Posts: 276
Joined: Tue Aug 29, 2006 9:32 pm
Score: 28 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest