added comments and removed old code

This commit is contained in:
Seth Samuel 2024-10-21 18:47:04 +13:00
parent 83d51667c2
commit 3bb78f6b44

33
main.c
View file

@ -4,17 +4,17 @@
#include <time.h> #include <time.h>
#include<unistd.h> #include<unistd.h>
#include<stdbool.h> #include<stdbool.h>
#define SCREEN_WIDTH 11 #define SCREEN_WIDTH 11 //set the width of the game screen
#define SCREEN_HEIGHT 20 #define SCREEN_HEIGHT 20 //set the height of the game screen
#define PADDLE_SIZE 2 #define PADDLE_SIZE 2 //set the paddle size. the blocks are added this amount either size of a central block.
#define SLEEP_TIME_MS 100 * 1000 #define SLEEP_TIME_MS 100 * 1000 //set the time to sleep between frames
#define PADDLE_HEIGHT SCREEN_HEIGHT-4 #define PADDLE_HEIGHT SCREEN_HEIGHT-4 //the negative number is distance from the bottom
#define Y_BLOCK_LAYERS 10 #define Y_BLOCK_LAYERS 10 //add the amount of layers of blocks from the top of the screen
#define X_BLOCK_LAYERS SCREEN_WIDTH #define X_BLOCK_LAYERS SCREEN_WIDTH
uint8_t screen[SCREEN_WIDTH][SCREEN_HEIGHT]; uint8_t screen[SCREEN_WIDTH][SCREEN_HEIGHT]; //this is the array the game lives in
enum PIXEL_TYPE { enum PIXEL_TYPE { //used to set what kind of pixel is shown on the screen array
PIXEL_EMPTY=0u, PIXEL_EMPTY=0u,
PIXEL_BALL=1u, PIXEL_BALL=1u,
PIXEL_BLOCK=2u, PIXEL_BLOCK=2u,
@ -23,7 +23,7 @@ enum PIXEL_TYPE {
PIXEL_PADDLE_RIGHT=5u PIXEL_PADDLE_RIGHT=5u
} PIXEL_TYPE; } PIXEL_TYPE;
void clearScreen() { void clearScreen() { //clears the screen of all pixels to redraw the screen
for (int y = 0; y < SCREEN_HEIGHT; y++) { for (int y = 0; y < SCREEN_HEIGHT; y++) {
for (int x=0; x<SCREEN_WIDTH; x++) { for (int x=0; x<SCREEN_WIDTH; x++) {
screen[x][y]=PIXEL_EMPTY; screen[x][y]=PIXEL_EMPTY;
@ -49,18 +49,18 @@ struct Paddle {
typedef struct block { typedef struct block {
uint8_t xLocation; uint8_t xLocation;
uint8_t yLocation; uint8_t yLocation;
bool visable; bool visable; //controls if the block is visible or not
} Block_t; } Block_t;
bool ballOnXEdge(Ball_t ball){ bool ballOnXEdge(Ball_t ball){ //work around to determine if the ball is on the edge of the screen
if(ball.xPOS==0) return true; if(ball.xPOS==0) return true;
if (ball.xPOS==SCREEN_WIDTH-1) return true; if (ball.xPOS==SCREEN_WIDTH-1) return true;
return false; return false;
} }
int main() { int main() {
Ball_t ball = {.xPOS=0,.yPOS=0,.xVEL=0,.yVEL=0}; Ball_t ball = {.xPOS=0,.yPOS=0,.xVEL=0,.yVEL=0}; //setup game ball
time_t UNIXTIME = time(NULL); time_t UNIXTIME = time(NULL); //create UNIXTIME struct
srand(UNIXTIME); //seed random number with time at run time srand(UNIXTIME); //seed random number with time at run time
Block_t blockArr[X_BLOCK_LAYERS][Y_BLOCK_LAYERS]; Block_t blockArr[X_BLOCK_LAYERS][Y_BLOCK_LAYERS];
bool blockFlushHit = false; //used to show if the ball has hit a block vertically or horizontally bool blockFlushHit = false; //used to show if the ball has hit a block vertically or horizontally
@ -92,13 +92,6 @@ int main() {
} }
} }
/* //draw paddel
screen[paddle.location][PADDLE_HEIGHT]=PIXEL_PADDLE_MIDDLE;
for(int x= 0; x<=PADDLE_SIZE; x++) {
screen[paddle.location-x][PADDLE_HEIGHT]=PIXEL_PADDLE_LEFT;
screen[paddle.location+x][PADDLE_HEIGHT]=PIXEL_PADDLE_RIGHT;
} */
for (int x=0-PADDLE_SIZE;x<PADDLE_SIZE;x++){ for (int x=0-PADDLE_SIZE;x<PADDLE_SIZE;x++){
if(x==0-PADDLE_SIZE){ if(x==0-PADDLE_SIZE){
screen[paddle.location+x][PADDLE_HEIGHT]=PIXEL_PADDLE_LEFT; screen[paddle.location+x][PADDLE_HEIGHT]=PIXEL_PADDLE_LEFT;