Why Code No Work?
Posted: Mon Nov 12, 2012 9:14 pm
I have this movement code for my player:
But for some reason I can only move left... And I have no idea why. Can you help???
- Code: Select all
int dir;
char*key=GetKeyState();
int tim;
int move;
int mov[4];
mov[0]=key[KEY_RIGHT];
mov[1]=key[KEY_LEFT];
mov[2]=key[KEY_UP];
mov[3]=key[KEY_DOWN];
dir = mov[0]-mov[1]+10*(mov[2]-mov[3]);
if (tim<8)
{
tim+=1;
}
if (tim==8)
{
move=1;
tim=0;
}
if (move ==1)
{
switch(dir)
{
case 1:
x+=width;
break;
case -1:
x-=width;
break;
case 10:
y-=height;
break;
case -10:
y+=height;
break;
}
move=0;
}
But for some reason I can only move left... And I have no idea why. Can you help???