- Code: Select all
char *key=GetKeyState();
angle=direction(xscreen, yscreen, xmouse, ymouse);
switch(mov) {
case 0: // not walking
if(angle>=-145&&angle<45) {
ChangeAnimation("Event Actor", "standRight", NO_CHANGE);
}
if(angle>=45&&angle<145) {
ChangeAnimation("Event Actor", "standUp", NO_CHANGE);
}
if(angle>=145&&angle<245) {
ChangeAnimation("Event Actor", "standLeft", NO_CHANGE);
}
if(angle>=245&&angle<345) {
ChangeAnimation("Event Actor", "standDown", NO_CHANGE);
}
break;
case 1: //moving
if(angle>=-145&&angle<45) {
ChangeAnimation("Event Actor", "walkRight", NO_CHANGE);
}
if(angle>=45&&angle<145) {
ChangeAnimation("Event Actor", "walkUp", NO_CHANGE);
}
if(angle>=145&&angle<245) {
ChangeAnimation("Event Actor", "walkLeft", NO_CHANGE);
}
if(angle>=245&&angle<345) {
ChangeAnimation("Event Actor", "walKDown", NO_CHANGE);
}
break;
}
if(key[KEY_d]==1 || key[KEY_a]==1 || key[KEY_s]==1 || key[KEY_w]==1) {
mov=1;
}
else { mov=0; }
if(key[KEY_d]==1) {
x+=5;
}
if(key[KEY_a]==1) {
x-=5;
}
if(key[KEY_s]==1) {
y+=5;
}
if(key[KEY_w]==1) {
y-=5;
}
Can someone clean this up? I'd like to know a shorter and more effective way of doing this I'm trying to make an MMO-styled game, but different. The player always faces the direction the mouse is pointing but he only has 4 actually facing directions
EDIT!
I have edited the code on my side and figured it out Using calculator. It's slightly different but its still large, I'd still like to know if there is an easier way of doing this