Hello,
I'm trying to implement keyboard controls to move a sphere(Player) with respondtokeypress.
Currently, when I press any key my character will move to the right by 0.1. This might be a noobie question but how can I move my character with w(up),a(left),s(down),d(right) in their respective directions using respondtokeypress?
Code:
class Player
{
private:
double x, y;
public:
Player(double a, double b){x=a;y=b;}
void respondtokeypress(char a)
{
a +=0.1;
a -=0.1;
b +=0.1;
b -=0.1;
glutPostRedisplay();
}
void draw()
{
//draw player
glLoadIdentity();
glColor3f (1.0, 0.0, 0.0);
glTranslatef(x,y,0);
glutSolidSphere(0.03,20,20);
}
};
void keyboard(unsigned char key, int x, int y)
{
Theseus.respondtokeypress(key);
glutPostRedisplay();
}