From 2e61b6b9e49fd8456efb8c61f0227864c85544bd Mon Sep 17 00:00:00 2001 From: Joe Date: Fri, 15 Dec 2017 17:00:07 +0000 Subject: [PATCH] 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 --- breakout/breakout.c | 54 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/breakout/breakout.c b/breakout/breakout.c index 4098d9f..8644b33 100644 --- a/breakout/breakout.c +++ b/breakout/breakout.c @@ -33,6 +33,15 @@ typedef struct ball { double radius; } 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 updateBall(Uint32 tickrate, ball *theBall, paddle *thePaddle, int winWidth, int winHeight); @@ -140,6 +149,51 @@ int main(void) { 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 = { .x = 0, .y = 0,