Winbgı
Winbgı
h>
#include <conio.h>
#define SCREEN_WIDTH 79
#define SCREEN_HEIGHT 25
int board[4][40];
int ballx=750;
int rktx=700;
int rkty=600;
int rktx_size=150;
int boardx_size=70;
int boardy_size=30;
int ball_radius=10;
int move_rkt=5;
int move_ballx=2;
int move_bally=5;
int bally=250;
void init_board()
{
board[row][col] =1;
void draw_board(){
int top=50;
int right=200;
if(board[row][col]==1){
setfillstyle(SOLID_FILL,BLACK);
}
right+=100;
}
top+=50;
right=200;
}
void draw_ball(){
setfillstyle(SOLID_FILL,WHITE);
circle(ballx,bally,ball_radius);
floodfill(ballx,bally,WHITE);
}
void draw_rkt(){
setfillstyle(SOLID_FILL,BLACK);
move_ballx = -move_ballx;
break;
}
else {
if (move_ballx >= 0) {
if (ballx - ball_radius <= right +
boardx_size && ballx - ball_radius >= right)
{
board[row][col] = 0;
move_bally = move_bally * (-1);
break;
}
else if (ballx + ball_radius >= right &&
ballx + ball_radius <= right + boardx_size) {
board[row][col] = 0;
break;
}
}
if (move_ballx <= -1) {
if (ballx - ball_radius >= right && ballx
- ball_radius <= right + boardx_size) {
board[row][col] = 0;
break;
}
else if (ballx + ball_radius >= right &&
ballx + ball_radius <= right + boardx_size)
{
board[row][col] = 0;
break;
}
}
}
}
}
right+=100;
}
top+=50;
right=200;
}
void update_ball(){
setfillstyle(SOLID_FILL,RED);
circle(ballx,bally,ball_radius);
floodfill(ballx,bally,RED);
ballx+=move_ballx;
bally+=move_bally;
draw_ball();
check_collision();
if (bally - 10 <= 0) {
move_bally = -move_bally;
}
if ((bally + 11 >= rkty) && (ballx >= rktx) && (ballx <= rktx + 150)) {
move_bally = -move_bally;
if (ballx < rktx + 50) {
move_ballx = -2;
}
else if (ballx > rktx + 100) {
move_ballx = 2;
}
else if (ballx >= rktx + 50 && ballx <= rktx + 75) {
move_ballx = -2;
move_bally = -move_bally;
}
else if (ballx >= rktx + 75 && ballx <= rktx + 100) {
move_ballx = 2;
move_bally = -move_bally;
}
update_rkt(rktx);
}
if(ballx==150)move_ballx=-move_ballx;
if(ballx==1210)move_ballx=-move_ballx;
if(bally==0)move_bally=-move_bally;
if(bally==700)move_bally=-move_bally;
draw_board();
Sleep(1);
}
init_board();
draw_board();
draw_ball();
draw_rkt();
if(kbhit()){
char ch = getch();
switch(ch){
case 'a':
case 'A':
if(rktx>=150){
rktx=rktx-move_rkt;
update_rkt(rktx);
}
break;
case 'd':
case 'D':
if(rktx+rktx_size<=1160){
rktx=rktx+move_rkt;
update_rkt(rktx);
}
}
}
}}