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);
}
}