In my code for breakout, the ball is unable to bounce up and down, though the same code works in bounce.c for bouncing the ball vertically!
Here's the main part meant for moving the ball:
while (lives > 0 && bricks > 0)
{
// TODO
double velocity = -0.5;
move(ball, 0, velocity);
// bounce off Y axis's edge of window
if ((getY(ball) + getHeight(ball)) >= getHeight(window) || getY(ball) <=0)
{
velocity *= -1;
}
pause (10);
GEvent event = getNextEvent(MOUSE_EVENT);
if (event != NULL)
{
if (getEventType(event) == MOUSE_MOVED)
{
double paddleX = getX(event) - (PADDLE_WIDTH / 2);
setLocation (paddle, paddleX, HEIGHT - 35);
}
}
}
This is only the first baby step I've taken towards this problem, and have failed. I am quite unhappy, please help me find errors!
This code though functions all right in the bounce.c program to bounce the ball between up and down, but when I place this code in the breakout.c file, it doesn't work. The ball just moves up and escapes the field of view and well, disappears...