diff --git a/bin/Debug/cTest b/bin/Debug/cTest new file mode 100755 index 0000000..8304fd2 Binary files /dev/null and b/bin/Debug/cTest differ diff --git a/cTest.cbp b/cTest.cbp new file mode 100644 index 0000000..f8ed285 --- /dev/null +++ b/cTest.cbp @@ -0,0 +1,39 @@ + + + + + + diff --git a/cTest.depend b/cTest.depend new file mode 100644 index 0000000..83bd3a8 --- /dev/null +++ b/cTest.depend @@ -0,0 +1,17 @@ +# depslib dependency file v1.0 +1727778794 source:/home/fluffy/codeBlocks/cTest/main.c + + + + + + + +1728183838 source:/home/fluffy/codeBlocks/blockBreaker/main.c + + + + + + + diff --git a/cTest.layout b/cTest.layout new file mode 100644 index 0000000..14ed64e --- /dev/null +++ b/cTest.layout @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/main.c b/main.c new file mode 100644 index 0000000..d86f35b --- /dev/null +++ b/main.c @@ -0,0 +1,133 @@ +#include +#include +#include +#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 + +uint8_t screen[SCREEN_WIDTH][SCREEN_HEIGHT]; + +enum PIXEL_TYPE { + PIXEL_EMPTY=0u, + PIXEL_BALL=1u, + PIXEL_BLOCK=2u, + PIXEL_PADDLE=3u +} PIXEL_TYPE; + +void clearScreen() { + for (int y = 0; y < SCREEN_HEIGHT; y++) { + for (int x=0; x"); + } else if(screen[x][y]==PIXEL_PADDLE) { + printf("=="); + } + } + printf("|\n"); + } + for (int x =0; x<=SCREEN_WIDTH; x++) { + printf("--"); + } + printf("\n"); + + //detect when ball hits the edge of the screen + if (ball.xPOS==0||ball.xPOS==(SCREEN_WIDTH-1)) { + ball.xVEL=ball.xVEL*-1; + } + if (ball.yPOS==0||ball.yPOS==(SCREEN_HEIGHT-1)) { + ball.yVEL=ball.yVEL*-1; + } + //detect when ball hits a block or paddle + if(screen[ball.xPOS+ball.xVEL][ball.yPOS]==PIXEL_BLOCK||screen[ball.xPOS+ball.xVEL][ball.yPOS]==PIXEL_PADDLE) { + ball.xVEL = ball.xVEL *-1; + } + if (screen[ball.xPOS][ball.yPOS+ball.yVEL]==PIXEL_BLOCK||screen[ball.xPOS][ball.yPOS+ball.yVEL]== PIXEL_PADDLE) { //hit detection y direction + ball.yVEL= ball.yVEL*-1; + } + if (screen[ball.xPOS+ball.xVEL][ball.yPOS+ball.yVEL]==PIXEL_BLOCK||screen[ball.xPOS+ball.xVEL][ball.yPOS+ball.yVEL]==PIXEL_PADDLE) { //diagonal hit detection + ball.xVEL = ball.xVEL *-1; + ball.xVEL=ball.yVEL *-1; + } + //update ball position + ball.xPOS=ball.xPOS+ball.xVEL; + ball.yPOS= ball.yPOS+ball.yVEL; + + } +} diff --git a/obj/Debug/main.o b/obj/Debug/main.o new file mode 100644 index 0000000..4476c59 Binary files /dev/null and b/obj/Debug/main.o differ