# Thread: 3D Game - When any arrow key is pressed the screen goes smaller then dissapears

1. ## 3D Game - When any arrow key is pressed the screen goes smaller then dissapears

I have made a 3d game when any arrow buttons are pressed the ball is meant to travel that way it was working until i put the aim targets on the wall after that it decided to stop working, instead the screen goes small first time a arrow button is pressed then after second press screen goes all black why is this

Heres some code that could help

GLfloat ballSpin = 0.0f;

GLfloat ballXpos = 40.0f;
GLfloat ballYpos = -30.0;
GLfloat ballZpos = 180.0;

GLfloat ballZspeed = 8.0f;
GLfloat ballXspeed = 2.0f;

GLfloat tempXpos = 40.0f;
GLfloat tempYpos = -30.0;
GLfloat tempZpos = 180.0;

void specialKeys(int key, int x, int y)
{
if(key == GLUT_KEY_UP){
ballZpos = ballZpos - ballZspeed;
ballSpin -= 90.0f;
glutPostRedisplay();
}

if(key == GLUT_KEY_DOWN){
ballZpos = ballZpos + ballZspeed;
ballSpin += 90.0f;
glutPostRedisplay();
}

if(key == GLUT_KEY_LEFT){
ballXpos = ballXpos - ballXspeed;
ballSpin += 45.0f;
glutPostRedisplay();
}

if(key == GLUT_KEY_RIGHT){
ballXpos = ballXpos + ballXspeed;
ballSpin -= 45.0f;
glutPostRedisplay();
}
}

void RenderScene(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
sky(skylight);
frontWall(bricks);
leftWall(bricks);
rightWall(bricks);
floor(grass);

eightPoints();
sixPoints();
fivePoints();

glPushMatrix();
glTranslatef(ballXpos, ballYpos, ballZpos);
glRotatef(ballSpin, 1.0, 1.0, 1.0);
ball(football);
glPopMatrix();
glFlush();

glutSwapBuffers();

}

Also can anybody tell me how I would code this for the when i press the z key it should shoot the ball toward the z axis, and if i use any of the arrows it will aim towards that angle.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•