Page 1 of 1

Jump, attack, directions?

PostPosted: Sat Mar 05, 2011 3:33 pm
by johnx8x
I am trying to make a game, but after trying some demos and reading topics here I am still not figuring out how to make it the way I want it.. :oops:

What I am trying to do, is creating a game where the player do the normal stuff: walk, jump, attack. I want the character to extend a sword or other weapon when attacking. I have figured out how to do the walk and jump-part, but I'm struggling with adding a proper attack for it, especially when I also want the player to be able to attack both when standing on the ground as well as being in the air. I also want the character to switch to a "falling" animation when in the air (instead of just playing a walking animation when there's no ground to walk on :wink: ). To get the "falling" part I used this code (which I found here in a topic somewhere):

Code: Select all
if(yvelocity<=-3||yvelocity>=3)
{
    if(right==1) //facing right
    {
        ChangeAnimation("Event Actor", "FALLING right", NO_CHANGE);
    }
    if(right==0) //facing left
    {
        ChangeAnimation("Event Actor", "FALLING left", NO_CHANGE);
    }
    canjump=0;
}


For the walking animations, I use codes that looks like this:

Code: Select all
char *key=GetKeyState();
if(canjump == 1)
{
if (key[KEY_LEFT]==0&&key[KEY_RIGHT]==1) ChangeAnimation("Event Actor", "WALK right", FORWARD);
else if(key[KEY_LEFT]==1&&key[KEY_RIGHT]==1) ChangeAnimation("Event Actor", "STAY right", FORWARD);\
}
right = 1;


Now I'm wondering if I've chosen the wrong way to do it since I have problems adding an attack. It seems the "falling" code is messing it up whenever the player is trying to use the attack while in the air (it doesn't work at all, or it shows the attack animation for a brief second and then switches back to the falling animation). I have no experience in creating codes, so everything I've added were from topics and demos from the forum.

Can anyone give me some suggestions on how to add an attack, or maybe another way of doing it?

Thanks for helping out a noob :mrgreen:

Re: Jump, attack, directions?

PostPosted: Sat Mar 05, 2011 4:59 pm
by schnellboot
I could make a demo for ya, but it will take a while.
Or you can give me your game and I'll fix it that won't take a day then..

Re: Jump, attack, directions?

PostPosted: Sat Mar 05, 2011 6:39 pm
by johnx8x
Thank you! Here's the game file, I removed the attack code because it didn't work. Controls are arrow keys for left and right, and arrow key up for jump. I was thinking of space button for attack.

Re: Jump, attack, directions?

PostPosted: Sat Mar 05, 2011 7:25 pm
by schnellboot
lol it took about half an hour because I had to fix it again and again
but it should work now without any problem

Re: Jump, attack, directions?

PostPosted: Sat Mar 05, 2011 8:55 pm
by johnx8x
Wonderful! Works perfectly, thank you so much! :D