added code to move paddle
This commit is contained in:
parent
3bb78f6b44
commit
64e70570e1
4 changed files with 29 additions and 10 deletions
Binary file not shown.
|
|
@ -1,5 +1,5 @@
|
||||||
# depslib dependency file v1.0
|
# depslib dependency file v1.0
|
||||||
1729487645 source:/home/fluffy/codeBlocks/blockBreaker/main.c
|
1729498522 source:/home/fluffy/codeBlocks/blockBreaker/main.c
|
||||||
<stdio.h>
|
<stdio.h>
|
||||||
<stdlib.h>
|
<stdlib.h>
|
||||||
<stdint.h>
|
<stdint.h>
|
||||||
|
|
|
||||||
25
main.c
25
main.c
|
|
@ -13,6 +13,7 @@
|
||||||
#define X_BLOCK_LAYERS SCREEN_WIDTH
|
#define X_BLOCK_LAYERS SCREEN_WIDTH
|
||||||
|
|
||||||
uint8_t screen[SCREEN_WIDTH][SCREEN_HEIGHT]; //this is the array the game lives in
|
uint8_t screen[SCREEN_WIDTH][SCREEN_HEIGHT]; //this is the array the game lives in
|
||||||
|
int moveArr[] = {-2,-1,0,1,2};
|
||||||
|
|
||||||
enum PIXEL_TYPE { //used to set what kind of pixel is shown on the screen array
|
enum PIXEL_TYPE { //used to set what kind of pixel is shown on the screen array
|
||||||
PIXEL_EMPTY=0u,
|
PIXEL_EMPTY=0u,
|
||||||
|
|
@ -41,10 +42,10 @@ typedef struct ballStruct {
|
||||||
int8_t yVEL;
|
int8_t yVEL;
|
||||||
} Ball_t;
|
} Ball_t;
|
||||||
|
|
||||||
struct Paddle {
|
typedef struct Paddle {
|
||||||
uint8_t location;
|
uint8_t location;
|
||||||
uint8_t paddleSize;
|
int paddleSize;
|
||||||
} paddle= {.location=(SCREEN_WIDTH/2),.paddleSize=PADDLE_SIZE};
|
} Paddle_t;
|
||||||
|
|
||||||
typedef struct block {
|
typedef struct block {
|
||||||
uint8_t xLocation;
|
uint8_t xLocation;
|
||||||
|
|
@ -58,8 +59,22 @@ bool ballOnXEdge(Ball_t ball){ //work around to determine if the ball is on the
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool movePaddle(Paddle_t* Paddle, int dir){ //negitave dir to move left positive to move right
|
||||||
|
if (dir==0) return false;
|
||||||
|
if (dir<=0){
|
||||||
|
if (Paddle ->location-Paddle->paddleSize+dir<=0) return false;
|
||||||
|
Paddle->location = Paddle->location+dir;
|
||||||
|
return true;
|
||||||
|
} else if (dir>=0) {
|
||||||
|
if (Paddle->location+Paddle->paddleSize+dir>= SCREEN_WIDTH-1) return false;
|
||||||
|
Paddle->location= Paddle->location+dir;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
Ball_t ball = {.xPOS=0,.yPOS=0,.xVEL=0,.yVEL=0}; //setup game ball
|
Ball_t ball = {.xPOS=0,.yPOS=0,.xVEL=0,.yVEL=0}; //setup game ball
|
||||||
|
Paddle_t paddle= {.location=(SCREEN_WIDTH/2),.paddleSize=PADDLE_SIZE};
|
||||||
time_t UNIXTIME = time(NULL); //create UNIXTIME struct
|
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];
|
||||||
|
|
@ -201,5 +216,9 @@ int main() {
|
||||||
ball.xPOS=ball.xPOS+ball.xVEL;
|
ball.xPOS=ball.xPOS+ball.xVEL;
|
||||||
ball.yPOS= ball.yPOS+ball.yVEL;
|
ball.yPOS= ball.yPOS+ball.yVEL;
|
||||||
|
|
||||||
|
|
||||||
|
//move paddle
|
||||||
|
movePaddle(&paddle,moveArr[rand()%6]);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
BIN
obj/Debug/main.o
BIN
obj/Debug/main.o
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue