0

This time, i will make sure I will tell you guys what I did and what I did to try to fix it.

breakout.c:27:5: error: implicit declaration of function
      'srand48' is invalid in C99
      [-Werror,-Wimplicit-function-declaration]
    srand48(time(NULL));

This one im not to sure of...

    ^
breakout.c:27:5: note: did you mean 'srand'?
/usr/include/stdlib.h:376:13: note: 'srand' declared here
extern void srand (unsigned int __seed) __THROW;
            ^

breakout.c:27:13: error: implicit declaration of function
      'time' is invalid in C99
      [-Werror,-Wimplicit-function-declaration]
    srand48(time(NULL));
            ^

breakout.c:33:11: error: expected identifier or '('
    GOval = initBall(window);
          ^
breakout.c:35:20: error: implicit declaration of function
      'intScoreboard' is invalid in C99
      [-Werror,-Wimplicit-function-declaration]
    GLabel label = intScoreboard(window);

This one I am confused on because I (im pretty sure) IntScoreboard in the beggining of the code
                   ^
breakout.c:35:12: error: incompatible integer to pointer
      conversion initializing 'GLabel' (aka 'void *') with an
      expression of type 'int' [-Werror,-Wint-conversion]
    GLabel label = intScoreboard(window);
           ^       ~~~~~~~~~~~~~~~~~~~~~
This one to

breakout.c:140:9: error: unused variable 'row_space'
      [-Werror,-Wunused-variable]

This one messed me up, how do you declare this variable?

I have been working on this and this is really confusing me, I may be looking too hard... please help

Code(if needed to reference)

#include <spl/gevents.h>
#include <spl/gobjects.h>
#include <spl/gwindow.h>
#include <string.h>
#include <stdlib.h>

#define HEIGHT 600
#define WIDTH 400
#define Rows 5
#define Cols 10
#define Radius 10
#define Lives 3

void intBricks(GWindow window);
GOval initBall(GWindow window);
GRect initPaddle(GWindow window);
GLabel initScoreboard(GWindow window);
void updateScoreboard(GWindow window, GLabel label, int points);
GObject detectCollision(GWindow window, GOval ball);
double x_velocity;
double y_velocity;
GOval ball;
GRect paddle;

int main(void)
{
    srand48(time(NULL));

    GWindow window = newGWindow(WIDTH, HEIGHT);

    intBricks(window);

    GOval = initBall(window);

    GLabel label = intScoreboard(window);

    int bricks = Cols*Rows;

    int lives = Lives;

    int points = 0;

    waitForClick();

    x_velocity = 2;
    y_velocity = 4;

    while(Lives > 0 && bricks > 0)
    {
        updateScoreboard(window, label, points);

        move(ball, x_velocity, y_velocity);

        pause(10);

        GEvent event = getNextEvent(MOUSE_EVENT);

        if (event != NULL)
        {
            if (getEventType(event) == MOUSE_MOVED)
            {
                double x = getX(event) - getWidth(paddle) / 2;
                double y = 500;
                setLocation(paddle, x, y);
            }
        }


        GObject object = detectCollision(window, ball);

        if (object != NULL)
        {
            if (object == paddle)
            {
                y_velocity = -y_velocity;
            }

            else if (strcmp(getType(object), "GRect") == 0)
            {
                removeGWindow(window, object);
                y_velocity = -y_velocity;
                points++;
                bricks--;                
            }
        }

        if (getX(ball) + getWidth(ball) >= getWidth(window))
        {
            x_velocity = -x_velocity;
        }

        if (getX(ball) <= 0)
        {
            x_velocity = -x_velocity;
        }

        if (getY(ball) <= 0)
        {
            y_velocity = -y_velocity;
        }

        if (getY(ball) + getHeight(ball) >= getHeight(window))
        {
            lives--;
            setLocation(ball, 190, 200);
            setLocation(paddle, 160, 500);
            waitForClick();
        }

    }

    if (bricks > 0)
    {
        GLabel game_over = newGLabel("YOU LOSE!");
        setFont(game_over, "SansSerif-70");
        setColor(game_over, "RED");
        add(window, game_over);
        setLocation(game_over, 15, 300);
    }
    else
    {
        GLabel game_over = newGLabel("YOU WIN!");
        setFont(game_over, "SansSerif-70");
        setColor(game_over, "GREEN");
        add(window, game_over);
        setLocation(game_over, 15, 300);
    }

    waitForClick();

    closeGWindow(window);
    return 0;
}

void initBricks(GWindow window)
{

    int brick_y = 50; 
    int row_space = 20; 

    for (int i = 0; i < Rows; i++) 
    {
        int brick_x = 2; 
        for (int j = 0; j < Cols; j++)
        {
            GRect brick = newGRect(brick_x + 5, brick_y, 35, 10);

            if (i == 0)
            {
                setColor(brick, "PURPLE");
            }
            if (i == 1)
            {
                setColor(brick, "BLUE");
            }
            if (i == 2)
            {
                setColor(brick, "CYAN");
            }
            if (i == 3)
            {
                setColor(brick, "GREEN");
            }
            if (i == 4)
            {
                setColor(brick, "YELLOW"); 
            }

            setFilled(brick, true);
            add(window, brick);
            brick_x = brick_x + 39; 
        }
        brick_y = brick_y + 15;
    }
}

GOval initBall(GWindow window)
{
    GOval ball = newGOval(200 - 10, 200, 20, 20); 
    setColor(ball, "BLACK");
    setFilled(ball, true);
    add(window, ball);
    return ball;
}

GRect initPaddle(GWindow window)
{
    GRect paddle = newGRect(200 - 35, 500, 70, 10);
    setColor(paddle, "7F00FF"); //purple
    setFilled(paddle, true);
    add(window, paddle);
    return paddle;
}

GLabel initScoreboard(GWindow window)
{
    GLabel label = newGLabel(" ");
    setFont(label, "SansSerif-50");
    setColor(label, "C0C0C0");
    add(window, label);
    setLocation(label, 185, 300);
    return label;
}

void updateScoreboard(GWindow window, GLabel label, int points)
{
    char s[12];
    sprintf(s, "%i", points);
    setLabel(label, s);

    double x = (getWidth(window) - getWidth(label)) / 2;
    double y = (getHeight(window) - getHeight(label)) / 2;
    setLocation(label, x, y);
}

GObject detectCollision(GWindow window, GOval ball)
{
    double x = getX(ball);
    double y = getY(ball);

    GObject object;

    object = getGObjectAt(window, x, y);
    if (object != NULL)
    {
        return object;
    }

    object = getGObjectAt(window, x + 2 * Radius, y);
    if (object != NULL)
    {
        return object;
    }

    object = getGObjectAt(window, x, y + 2 * Radius);
    if (object != NULL)
    {
        return object;
    }

    object = getGObjectAt(window, x + 2 * Radius, y + 2 * Radius);
    if (object != NULL)
    {
        return object;
    }

    return NULL;
}       
1
  • try putting #define _XOPEN_SOURCE in the line right before #include <stdlib.h>!
    – kzidane
    Jul 22, 2015 at 16:34

1 Answer 1

1

breakout.c:33:11: error: expected identifier or '(' GOval = initBall(window);

GOval is a type. You need a name for it, like ball. Instead, this should be GOval ball = initBall(window);

You should include stdio.h- you will need it.

breakout.c:140:9: error: unused variable 'row_space' [-Werror,-Wunused-variable] This one messed me up, how do you declare this variable?

This one it means you declare row_space, but you did not use it. Don't worry about this yet- you will use it eventually.

breakout.c:35:20: error: implicit declaration of function 'intScoreboard' is invalid in C99 [-Werror,-Wimplicit-function-declaration] GLabel label = intScoreboard(window); This one I am confused on because I (im pretty sure) IntScoreboard in the beginning of the code

For this one, you declared initscoreboard, not intscoreboard.

1
  • breakout.c:29:11: error: implicit declaration of function 'time' is invalid in C99 [-Werror,-Wimplicit-function-declaration] srand(time(NULL)); ^ breakout.c:141:9: error: unused variable 'row_space' [-Werror,-Wunused-variable] int row_space = 20; ^ I did not get your explanation for that
    – Ani
    Jul 23, 2015 at 14:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .