diff --git a/bin/Debug/cTest b/bin/Debug/cTest index 323b8a3..73346c8 100755 Binary files a/bin/Debug/cTest and b/bin/Debug/cTest differ diff --git a/cTest.depend b/cTest.depend index 08b6867..c221826 100644 --- a/cTest.depend +++ b/cTest.depend @@ -7,7 +7,7 @@ -1728637902 source:/home/fluffy/codeBlocks/blockBreaker/main.c +1728641201 source:/home/fluffy/codeBlocks/blockBreaker/main.c diff --git a/main.c b/main.c index d1b994c..b166515 100644 --- a/main.c +++ b/main.c @@ -4,15 +4,12 @@ #include #include #include - -//#include -//#include #define SCREEN_WIDTH 11 #define SCREEN_HEIGHT 20 #define PADDLE_SIZE 1 #define SLEEP_TIME_MS 100 * 1000 #define PADDLE_HEIGHT SCREEN_HEIGHT-4 -#define Y_BLOCK_LAYERS 4 +#define Y_BLOCK_LAYERS 10 #define X_BLOCK_LAYERS SCREEN_WIDTH uint8_t screen[SCREEN_WIDTH][SCREEN_HEIGHT]; @@ -33,12 +30,14 @@ void clearScreen() { printf("\e[1;1H\e[2J");//clear the screen of the prev frame } -struct ballStruct { + + +typedef struct ballStruct { uint8_t xPOS; uint8_t yPOS; int8_t xVEL; int8_t yVEL; -} ball= {.xPOS=0,.yPOS=0,.xVEL=0,.yVEL=0}; +} Ball_t; struct Paddle { uint8_t location; @@ -51,8 +50,14 @@ typedef struct block { bool visable; } Block_t; +bool ballOnXEdge(Ball_t ball){ + if(ball.xPOS==0) return true; + if (ball.xPOS==SCREEN_WIDTH-1) return true; + return false; +} + int main() { - //struct ballStruct ball; + Ball_t ball = {.xPOS=0,.yPOS=0,.xVEL=0,.yVEL=0}; time_t UNIXTIME = time(NULL); srand(UNIXTIME); //seed random number with time at run time Block_t blockArr[X_BLOCK_LAYERS][Y_BLOCK_LAYERS]; @@ -72,7 +77,6 @@ int main() { ball.xVEL=1; ball.yVEL=1; while(true) { - // std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_TIME_MS)); usleep(SLEEP_TIME_MS); clearScreen(); blockFlushHit = false; @@ -140,8 +144,12 @@ int main() { } if (screen[ball.xPOS+ball.xVEL][ball.yPOS+ball.yVEL]==PIXEL_BLOCK&&blockFlushHit==false) { blockArr[ball.xPOS+ball.xVEL][ball.yPOS+ball.yVEL].visable=false; - ball.xVEL = ball.xVEL *-1; - ball.yVEL=ball.yVEL *-1; + if(ballOnXEdge(ball)==false) { + ball.xVEL = ball.xVEL *-1; + } + if (ball.yPOS!=0) { + ball.yVEL=ball.yVEL *-1; + } } //detect when ball hits paddle diff --git a/obj/Debug/main.o b/obj/Debug/main.o index d948e2a..d4c7c40 100644 Binary files a/obj/Debug/main.o and b/obj/Debug/main.o differ