🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

breakout in opengl and c++

Started by
55 comments, last by pbivens67 2 years, 12 months ago

To OP, this topic went out of scope of interest for any general audience/viewers, so if you are addressing the question to a concrete user, please mention him and add some politeness sugar, along with at least, starting the post with capital alhabet character that you seem to not have time for while someone competent should have his time and energy helping you.

And functions are not initialized.

Advertisement

I meant to say how do I prototype the drawBrick function

pbivens67 said:
how do I prototype the drawBrick function

But that's obvious from the code already:

DrawBrick(br_x, br_y, br_w, br_h, brickType);

And we know first 4 params are float, final one is int, and there is no returned type. Thus:

void DrawBrick(float br_x, float br_y, float br_w, float br_h, int brickType);

I thought is was void too, but I was not sure

I have almost compiled my code, I do have an error on line 67 “redefinition of formal parameter board”

here is my code so far

#include <iostream>

using namespace std;

void CalcBrickCoords(float &br_x, float &br_y, float &br_w, float &br_h, const int boardX, const int boardY);
void DrawBrick(float &br_x, float &br_y, float &br_w, float &br_h, const bool black);

float brickWidth = 35.0f, brickHeight = 15.0f;
bool blackBrickType = false;
float scaleX = 35.0f, scaleY = 15.0f;
float offsetX = -135.0f, offsetY = 100.0f;
int boardHeight = 3, boardWidth = 8;
int test_coll_brick_x, test_coll_brick_y;

class Bricks
{
public:
	float ball_x;
	float ball_y;
	float ball_width;
	float ball_height;
	float brick_x;
	float brick_y;
	float brick_width;
	float brick_height;
	bool collision(float, float, float, float, float, float, float, float);
};

bool Bricks::collision(float ball_x, float ball_y, float ball_width, float ball_height, float brick_x, float brick_y, float brick_width, float brick_height)
{
	if (ball_x<brick_x + brick_width && ball_x + ball_width>brick_x&&ball_y<brick_y + brick_height && ball_y + ball_height>brick_y)
	{
		return 1;
	}
	else
	{
		return 0;
	}
}

int main()
{
	Bricks coll;

	float b_x, b_y, b_w, b_h;
	float br_x, br_y, br_w, br_h;

	CalcBrickCoords(br_x, br_y, br_w, br_h, test_coll_brick_x, test_coll_brick_y);

	if (coll.collision(b_x, b_y, b_w, b_h, br_x, br_y, br_w, br_h) == 1)
	{
		DrawBrick(br_x, br_y, br_w, br_h, blackBrickType);
	}
	return 0;
}

void CalcBrickCoords(float &br_x, float &br_y, float &br_w, float &br_h, const int boardX, const int boardY)
{
	br_x = float(boardX) * scaleX + offsetX;
	br_y = float(boardY) * scaleY + offsetY;
	br_w = brickWidth;
	br_h = brickHeight;
}

void DrawBoard(int *board)
{
	int board[24] = {0,0,1,1,1,1,0,0,
					 0,1,2,2,2,2,1,0,
	                 1,2,2,3,3,2,2,1};
	for (int y = 0; y < boardHeight; y++)
		for (int x = 0; x < boardWidth; x++)
		{
			int brickType = board[x + y * boardWidth];
			if (brickType == 0) // skip if no brick in that grid cell
				continue;

			float br_x, br_y, br_w, br_h;
			CalcBrickCoords(br_x, br_y, br_w, br_h, x, y);

			DrawBrick(br_x, br_y, br_w, br_h, brickType);
		}
}

Have you fixed the error on line 67, Phil?

-- Tom Sloper -- sloperama.com

pbivens67 said:
I have almost compiled my code, I do have an error on line 67 “redefinition of formal parameter board”

It's because you have ignored my former advise to create and fill the board data outside of the DrawBoard function, but giving the data using the function parameter. See above.

Also the DrawBoard function is never called, so you need to work on some initial code which creates all data once at startup (e.g. in main function), and a game loop to process physics and draw stuff each frame (using that Glut timers and redisplay stuff).

Do not write / design code over weeks without ever compiling it. Compile it constantly after each change. Helps to detect errors quickly and is easier because assumptions turn into certainty and can be removed from your mental planning.

well I have got one final error.

Severity Code Description Project File Line Suppression State

Error LNK2019 unresolved external symbol "void __cdecl DrawBrick(float,float,float,float,bool)" (?DrawBrick@@YAXMMMM_N@Z) referenced in function "void __cdecl DrawBoard(int *)" (?DrawBoard@@YAXPAH@Z) coll2 C:\Users\Owner\source\repos\coll2\coll2\coll2.obj 1

pbivens67 said:
Error LNK2019 unresolved external symbol

And this is the first time you get such error? Or are you trolling us?

Ok, it is because you have added a ‘DrawBrick’ function prototype, but not the actual implementation of said function.

Time to draw some rectangle… ; )

this is the first time I got this error

This topic is closed to new replies.

Advertisement