Hi I have a bug for pset3 breakout problem, I have already implemented all the features but somehow when I am trying to hit the bricks i run to the core segmentation error, I will put the code inside while loop that we need to implement and see if anyone can detect the problem:
while (lives > 0 && bricks > 0) {
// Check for mouse movement
GEvent event = getNextEvent(MOUSE_EVENT);
if (event != NULL)
{
// if the event was movement
if (getEventType(event) == MOUSE_MOVED)
{
// paddle movement
double x = getX(event) - getWidth(paddle) / 2;
setLocation(paddle, x, HEIGHT -100);
}
}
// bounce off top edge of window or right edge of window
GObject object = detectCollision(window,ball);
// checking for object detection collisions
if (object == paddle)
{
// checking if the ball hits middle of the paddle
if (getX(ball) == (getWidth(paddle) / 2))
{
// we want ball to go up vertically
velocityX = 0;
}
// checking if the ball hits the left half of the paddle
else if (getX(ball) > (getWidth(paddle) / 2))
{
// angling it towards right with some impulse from paddel
velocityX = velocityX * 1.1;
}
else if (getX(ball) < (getWidth(paddle) / 2))
{
// angling it towards left with some impulse from paddle
velocityX = -velocityX * 1.1;
}
// ball to go up
velocityY = -velocityY ;
}
if (getX(ball) + getWidth(ball) >= getWidth(window))
{
velocityX = -velocityX;
}
// bounce off left edge of window or bottom edge of window
if (getX(ball) <= 0)
{
velocityX = -velocityX;
}
// checking to see if ball goes above the screen
if (getY(ball) + getHeight(ball) <= 0)
{
// change the y direction
velocityY = -velocityY;
}
;
if (strcmp(getType(object),"GRect") == 0)
{
// removing the brick
removeGWindow(window,(getType(object),"GRect"));
// changing direction
velocityY = -velocityY;
// updating score
points++;
}
move(ball,velocityX , velocityY );
// linger before moving again
pause(10)
--- Everything works well up to the if (strcmp(getType(object),"GRect") == 0), and that's where I run in to the core segmentation problem. Any help would appreciated Thank you.