Hero can't go right until you pressing left key, and can't go left until you pressing right key.
To done this i created global variable string Xdirection. Then i made code for keys.
Problem is when i push left, hero can't go right, but when i push right hero can go left.
For right key.
- Code: Select all
if (strcmp (Xdirection,"left") != 1)
{
hero.xvelocity = 5;
strcpy (Xdirection,"right");
}
For left key.
- Code: Select all
if (strcmp (Xdirection,"right") != 1)
{
strcpy (Xdirection , "left");
hero.xvelocity = -5;
}
On key up.
- Code: Select all
hero.xvelocity = 0;
strcpy (Xdirection , "anyway");