Игра пинг-понг Помогите помогите помогите ?
не могли бы вы помочь мне исправить код, потому что он не работает !!
Что я уже пробовал:
#include <graphics.h> #define RACKETLEN 50 #define RACKETWIDTH 5 static int racket1_x = 20; static int racket1_y = 280; static int racket2_x = 770-RACKETWIDTH; static int racket2_y = 280; static int ball_x= 100, ball_y = 45; static int ballSize = 10; static int RacketColor = 15; static int BallGNDColor = 0; static int BallColor = 15; int dirY = 0;int dirX = 0; void drawBoard(int color) { setcolor(color); rectangle (10,30, 780, 580); } void DrawLine(int color, int x0, int y0, int x1, int y1,int thickness) { while(thickness>=1) { int tx0,ty0,tx1,ty1; tx0=x0;tx1=x1;ty0=y0;ty1=y1; int dx = abs(x1-x0), sx = x0<x1 ? 1 : -1; int dy = abs(y1-y0), sy = y0<y1 ? 1 : -1; int err = (dx>dy ? dx : -dy)/2, e2; for(;;){ putpixel(x0, y0, color); //put_pixel(g,x0,y0); if (x0==x1 && y0==y1) break; e2 = err; if (e2 >-dx) { err -= dy; x0 += sx; } if (e2 < dy) { err += dx; y0 += sy; } } x0=tx0+1; y0=ty0; x1=tx1+1; y1=ty1; thickness--; } } void drawRackets(int color) { DrawLine(color,racket1_x,racket1_y,racket1_x,racket1_y+RACKETLEN,RACKETWIDTH); DrawLine(color,racket2_x,racket2_y,racket2_x,racket2_y+RACKETLEN,RACKETWIDTH); } void drawBall(int x, int y, int ballSize, int color) { DrawLine(color,x,y,x,y+ballSize,ballSize); } void drawTop() { setcolor(4); outtextxy(30, 5, "Pong Game !"); outtextxy(380, 5, "0 - 0"); outtextxy(680, 5, "SCORE: "); } void initGame() { initwindow(800, 600); cleardevice(); drawBoard(1); drawRackets(RacketColor); drawTop(); } void move_racket(int *x, int *y, int dir) { drawRackets(0); if (dir == 1) /* LEFT */ *y = *y - 5; else /* RIGHT */ *y = *y + 5; drawRackets(RacketColor); } void move_ball() { if(ball_y>=580-ballSize){ dirY = 0;} if(ball_y<=31){ dirY = 1;} if(ball_x>=780-ballSize) { dirX=0;} if (ball_x<=31){ dirX =1;} drawBall(ball_x,ball_y,ballSize,BallGNDColor); if(dirY == 1){ ball_y++;} else{ ball_y--;} if(dirX == 1){ ball_x++;} else{ ball_x--;} drawBall(ball_x,ball_y,ballSize,BallColor); } void playGame() { char c; initGame(); while(1) { if (kbhit()) { c = getch(); if (c == 'w') /* 'a' character */ move_racket(&racket1_x,&racket1_y,1); if (c == 's') move_racket(&racket1_x,&racket1_y,0); if (c == 119) /* 'w' character */ move_racket(&racket2_x,&racket2_y,0); // setpos(15,15); // putint(c); } delay(1); if (ball_x < 800 && ball_y < 600) { move_ball(); } // char* line; //line = readline(); //println(""); //println("You entered:"); //println(line); //free(line); } } main(int argc, char *argv[]) { playGame(); //while(1); //while(!kbhit()) delay(1); // pause screen }