added diagonal hitters on ends of paddle
This commit is contained in:
parent
0796688df7
commit
83d51667c2
4 changed files with 59 additions and 18 deletions
Binary file not shown.
|
|
@ -1,5 +1,5 @@
|
||||||
# depslib dependency file v1.0
|
# depslib dependency file v1.0
|
||||||
1728643125 source:/home/fluffy/codeBlocks/blockBreaker/main.c
|
1729487645 source:/home/fluffy/codeBlocks/blockBreaker/main.c
|
||||||
<stdio.h>
|
<stdio.h>
|
||||||
<stdlib.h>
|
<stdlib.h>
|
||||||
<stdint.h>
|
<stdint.h>
|
||||||
|
|
|
||||||
75
main.c
75
main.c
|
|
@ -5,11 +5,11 @@
|
||||||
#include<unistd.h>
|
#include<unistd.h>
|
||||||
#include<stdbool.h>
|
#include<stdbool.h>
|
||||||
#define SCREEN_WIDTH 11
|
#define SCREEN_WIDTH 11
|
||||||
#define SCREEN_HEIGHT 10
|
#define SCREEN_HEIGHT 20
|
||||||
#define PADDLE_SIZE 1
|
#define PADDLE_SIZE 2
|
||||||
#define SLEEP_TIME_MS 100 * 1000
|
#define SLEEP_TIME_MS 100 * 1000
|
||||||
#define PADDLE_HEIGHT SCREEN_HEIGHT-1
|
#define PADDLE_HEIGHT SCREEN_HEIGHT-4
|
||||||
#define Y_BLOCK_LAYERS 4
|
#define Y_BLOCK_LAYERS 10
|
||||||
#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];
|
||||||
|
|
@ -18,7 +18,9 @@ enum PIXEL_TYPE {
|
||||||
PIXEL_EMPTY=0u,
|
PIXEL_EMPTY=0u,
|
||||||
PIXEL_BALL=1u,
|
PIXEL_BALL=1u,
|
||||||
PIXEL_BLOCK=2u,
|
PIXEL_BLOCK=2u,
|
||||||
PIXEL_PADDLE=3u
|
PIXEL_PADDLE_MIDDLE=3u,
|
||||||
|
PIXEL_PADDLE_LEFT=4u,
|
||||||
|
PIXEL_PADDLE_RIGHT=5u
|
||||||
} PIXEL_TYPE;
|
} PIXEL_TYPE;
|
||||||
|
|
||||||
void clearScreen() {
|
void clearScreen() {
|
||||||
|
|
@ -73,7 +75,7 @@ int main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
ball.xPOS=rand()% SCREEN_WIDTH;
|
ball.xPOS=rand()% SCREEN_WIDTH;
|
||||||
ball.yPOS= rand()% SCREEN_HEIGHT;
|
ball.yPOS= PADDLE_HEIGHT-1;
|
||||||
ball.xVEL=1;
|
ball.xVEL=1;
|
||||||
ball.yVEL=1;
|
ball.yVEL=1;
|
||||||
while(true) {
|
while(true) {
|
||||||
|
|
@ -90,11 +92,21 @@ int main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//draw paddel
|
/* //draw paddel
|
||||||
screen[paddle.location][PADDLE_HEIGHT]=PIXEL_PADDLE;
|
screen[paddle.location][PADDLE_HEIGHT]=PIXEL_PADDLE_MIDDLE;
|
||||||
for(int x= 0; x<=PADDLE_SIZE; x++) {
|
for(int x= 0; x<=PADDLE_SIZE; x++) {
|
||||||
screen[paddle.location-x][PADDLE_HEIGHT]=PIXEL_PADDLE;
|
screen[paddle.location-x][PADDLE_HEIGHT]=PIXEL_PADDLE_LEFT;
|
||||||
screen[paddle.location+x][PADDLE_HEIGHT]=PIXEL_PADDLE;
|
screen[paddle.location+x][PADDLE_HEIGHT]=PIXEL_PADDLE_RIGHT;
|
||||||
|
} */
|
||||||
|
|
||||||
|
for (int x=0-PADDLE_SIZE;x<PADDLE_SIZE;x++){
|
||||||
|
if(x==0-PADDLE_SIZE){
|
||||||
|
screen[paddle.location+x][PADDLE_HEIGHT]=PIXEL_PADDLE_LEFT;
|
||||||
|
} else if (x==PADDLE_SIZE-1){
|
||||||
|
screen[paddle.location+x][PADDLE_HEIGHT]=PIXEL_PADDLE_RIGHT;
|
||||||
|
} else {
|
||||||
|
screen[paddle.location+x][PADDLE_HEIGHT]=PIXEL_PADDLE_MIDDLE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
//draw ball
|
//draw ball
|
||||||
screen[ball.xPOS][ball.yPOS]=PIXEL_BALL;
|
screen[ball.xPOS][ball.yPOS]=PIXEL_BALL;
|
||||||
|
|
@ -109,12 +121,16 @@ int main() {
|
||||||
for (int x=0; x<SCREEN_WIDTH; x++) {
|
for (int x=0; x<SCREEN_WIDTH; x++) {
|
||||||
if (screen[x][y]==PIXEL_EMPTY) {
|
if (screen[x][y]==PIXEL_EMPTY) {
|
||||||
printf(" ");
|
printf(" ");
|
||||||
} else if (screen[x][y]==PIXEL_BALL) {
|
|
||||||
printf("<>");
|
|
||||||
} else if(screen[x][y]==PIXEL_PADDLE) {
|
|
||||||
printf("==");
|
|
||||||
} else if(screen[x][y]==PIXEL_BLOCK) {
|
} else if(screen[x][y]==PIXEL_BLOCK) {
|
||||||
printf("[]");
|
printf("[]");
|
||||||
|
} else if (screen[x][y]==PIXEL_BALL) {
|
||||||
|
printf("<>");
|
||||||
|
} else if(screen[x][y]==PIXEL_PADDLE_MIDDLE) {
|
||||||
|
printf("==");
|
||||||
|
} else if(screen[x][y]==PIXEL_PADDLE_LEFT){
|
||||||
|
printf("<=");
|
||||||
|
} else if(screen[x][y]==PIXEL_PADDLE_RIGHT){
|
||||||
|
printf("=>");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
printf("|\n");
|
printf("|\n");
|
||||||
|
|
@ -153,16 +169,41 @@ int main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
//detect when ball hits paddle
|
//detect when ball hits paddle
|
||||||
if(screen[ball.xPOS+ball.xVEL][ball.yPOS]==PIXEL_PADDLE) {
|
if(screen[ball.xPOS+ball.xVEL][ball.yPOS]==PIXEL_PADDLE_MIDDLE) {
|
||||||
ball.xVEL = ball.xVEL *-1;
|
ball.xVEL = ball.xVEL *-1;
|
||||||
}
|
}
|
||||||
if (screen[ball.xPOS][ball.yPOS+ball.yVEL]== PIXEL_PADDLE) { //hit detection y direction
|
if (screen[ball.xPOS][ball.yPOS+ball.yVEL]== PIXEL_PADDLE_MIDDLE) { //hit detection y direction
|
||||||
ball.yVEL= ball.yVEL*-1;
|
ball.yVEL= ball.yVEL*-1;
|
||||||
}
|
}
|
||||||
if (screen[ball.xPOS+ball.xVEL][ball.yPOS+ball.yVEL]==PIXEL_PADDLE) { //diagonal hit detection
|
if (screen[ball.xPOS+ball.xVEL][ball.yPOS+ball.yVEL]==PIXEL_PADDLE_MIDDLE) { //diagonal hit detection
|
||||||
ball.xVEL = ball.xVEL *-1;
|
ball.xVEL = ball.xVEL *-1;
|
||||||
ball.yVEL=ball.yVEL *-1;
|
ball.yVEL=ball.yVEL *-1;
|
||||||
}
|
}
|
||||||
|
//paddle left
|
||||||
|
if (screen[ball.xPOS+ball.xVEL][ball.yPOS+ball.yVEL]==PIXEL_PADDLE_LEFT) { //diagonal hit detection
|
||||||
|
if(ball.xVEL==-1){
|
||||||
|
ball.xVEL=-1;
|
||||||
|
} else if (ball.xVEL==0){
|
||||||
|
ball.xVEL=-1;
|
||||||
|
} else {
|
||||||
|
ball.xVEL=-1;
|
||||||
|
}
|
||||||
|
ball.yVEL=ball.yVEL *-1;
|
||||||
|
}
|
||||||
|
|
||||||
|
//paddle right
|
||||||
|
if (screen[ball.xPOS+ball.xVEL][ball.yPOS+ball.yVEL]==PIXEL_PADDLE_RIGHT) { //diagonal hit detection
|
||||||
|
if (ball.xVEL==-1){ //moving left
|
||||||
|
ball.xVEL=1;
|
||||||
|
} else if (ball.xVEL==0){ //moving straight down
|
||||||
|
ball.xVEL=1;
|
||||||
|
} else { //moving right
|
||||||
|
ball.xVEL=1;
|
||||||
|
}
|
||||||
|
ball.yVEL=ball.yVEL *-1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//update ball position
|
//update ball position
|
||||||
ball.xPOS=ball.xPOS+ball.xVEL;
|
ball.xPOS=ball.xPOS+ball.xVEL;
|
||||||
ball.yPOS= ball.yPOS+ball.yVEL;
|
ball.yPOS= ball.yPOS+ball.yVEL;
|
||||||
|
|
|
||||||
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