How to realize bouncing Ball and eliminating Brick with Array in C language
In this article, the editor introduces in detail "how C language uses array to realize bouncing ball eliminating brick". The content is detailed, the steps are clear, and the details are handled properly. I hope that this article "how C language uses an array to achieve bouncing ball eliminating bricks" can help you solve your doubts. Let's follow the editor's ideas to learn new knowledge.
First, the effect display:
2. The code is as follows: # include#include#include#include#include#define High 24 / / Game screen size # define Width 36 define Width / global variable int ball_vx,ball_vy;// ball coordinates int ball_vx,ball_vy;// ball speed int canvas [High] [Width] = {0}; int position_x,position_y;// bezel center coordinate int ridus;// bezel radius size int left,right;// bezel left and right size int score=0 / / score / / two-dimensional array stores the corresponding element / / 0 in the game canvas for spaces, 1 for balls, 2 for baffles, 3 for bricks (1 point), 4 for bricks (2 points), 5 for bricks (3 points) void gotoxy (int x STD_OUTPUT_HANDLE int y) / / move the cursor to the (x STD_OUTPUT_HANDLE) position {HANDLE handle=GetStdHandle (STD_OUTPUT_HANDLE); COORD pos; pos.X=x; pos.Y=y; SetConsoleCursorPosition (handle,pos) } void startup () / / initialization of data {int krecoveri; ridus=5; position_x=High-1; position_y=Width/2; left=position_y-ridus; right=position_y+ridus; ball_x=position_x-1; ball_y=position_y; ball_vx=-1; ball_vy=1; canvas [ball _ x] [ball_y] = 1; for (kumbleftmitk)