Testing some code for storing brick information in mutli-dimensional arrays as leaf nodes in a tree. This approach is chosen with a view to introducting space partitioning for collision detection at a later date

This commit is contained in:
Joe Adams 2017-12-15 17:00:07 +00:00
parent a3017b0774
commit 2e61b6b9e4

View File

@ -33,6 +33,15 @@ typedef struct ball {
double radius; double radius;
} ball; } ball;
typedef struct brick {
char brickType;
int x;
int y;
int width;
int height;
struct brick *container;
} brick;
void updatePaddle(Uint32 tickrate, paddle *thePaddle, char moveX, int winWidth, int winHeight); void updatePaddle(Uint32 tickrate, paddle *thePaddle, char moveX, int winWidth, int winHeight);
void updateBall(Uint32 tickrate, ball *theBall, paddle *thePaddle, int winWidth, int winHeight); void updateBall(Uint32 tickrate, ball *theBall, paddle *thePaddle, int winWidth, int winHeight);
@ -140,6 +149,51 @@ int main(void) {
char moveX=0; char moveX=0;
brick bricklayout = {
.brickType = 0,
.x = 0,
.y = 0,
.width = winWidth,
.height = winHeight,
.container = malloc(sizeof(brick)*2),
};
bricklayout.container[0] = (brick) {
.brickType = 1,
.x = 0,
.y = 0,
.width = 100,
.height = 10,
.container = NULL
};
bricklayout.container[1] = (brick) {
.brickType = 1,
.x = 108,
.y = 0,
.width = 100,
.height = 10,
.container = NULL
};
char msgtxt[100];
sprintf(msgtxt, "Array seems to be %d long", sizeof(bricklayout.container));
MessageBox(0, msgtxt, "Debug info", MB_OK);
for (int i=0; i<(sizeof(*bricklayout.container) / sizeof(bricklayout.container[0]));i++) {
char msgtxt[100];
sprintf(msgtxt, "Brick type %d, x %d, y %d, width %d, height %d", bricklayout.container[i].brickType, bricklayout.container[i].x, bricklayout.container[i].y, bricklayout.container[i].width, bricklayout.container[i].height);
MessageBox(0, msgtxt, "Debug info", MB_OK);
}
//char isArray;
//int x;
//int y;
//int width;
//int height;
//brick *container;
//char brickType;
ball theBall = { ball theBall = {
.x = 0, .x = 0,
.y = 0, .y = 0,