In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly explains "how to use easyx to achieve brick elimination game in C language". The explanation in this article is simple and clear and easy to learn and understand. Please follow Xiaobian's train of thought to study and learn "how to use easyx to realize brick elimination game in C language".
1. Display of the final effect
The effect picture is as follows:
Draw a static bezel
The code is as follows:
# include#include#define High 480 / / Game screen size # define Width 640 int ball_x,ball_y;// / global variable coordinates of the ball int ball_vx,ball_vy;// speed of the ball, radius of the ball, central coordinates of the int bar_x,bar_y;// bezel, height and width of the int bar_high,bar_width;// bezel / / the left and right upper and lower position coordinates of the bezel void startup () / / data initialization {ball_x=Width/2; ball_y=High/2; ball_vx=1; ball_vy=1; radius=20; bar_high=High/20; bar_width=Width/5; bar_x=Width/2; bar_y=High-bar_high/2; bar_left=bar_x-bar_width/2; bar_right=bar_x+bar_width/2 Bar_top=bar_y-bar_high/2; bar_bottom=bar_y+bar_high/2; initgraph (Width,High); BeginBatchDraw ();} void clean () / / display screen {setcolor (BLACK); / / draw black lines, black filled circle setfillcolor (BLACK); fillcircle (ball_x,ball_y,radius); bar (bar_left,bar_top,bar_right,bar_bottom) / / draw black, black filled bezel} void show () / / display screen {setcolor (YELLOW); / / draw yellow line, green filled circle setfillcolor (GREEN); fillcircle (ball_x,ball_y,radius); bar (bar_left,bar_top,bar_right,bar_bottom); / / draw yellow, green filled bezel FlushBatchDraw (); Sleep (3) } void updateWithoutInput () / / updates independent of user input {ball_x=ball_x+ball_vx; ball_y=ball_y,ball_vy;// update ball coordinates if ((ball_x=Width-radius)) ball_vx=-ball_vx; if ((ball_y=High-radius)) ball_vy=-ball_vy } void updateWithInput () / / updates related to user input {} void gameover () {EndBatchDraw (); closegraph ();} int main () {startup (); / / initialization of data while (1) {clean (); / / clear updateWithoutInput () of previously drawn content; / / update updateWithInput () that is not related to user input / / update show () related to user input; / / display new screen}}
The effect picture is as follows:
3. Control bezel
The code is as follows:
# include#include#define High 480 / / Game screen size # define Width 640 int ball_x,ball_y;// / global variable coordinates of the ball int ball_vx,ball_vy;// speed of the ball, radius of the ball, central coordinates of the int bar_x,bar_y;// bezel, height and width of the int bar_high,bar_width;// bezel / / the left and right upper and lower position coordinates of the bezel void startup () / / data initialization {ball_x=Width/2; ball_y=High/2; ball_vx=1; ball_vy=1; radius=20; bar_high=High/20; bar_width=Width/5; bar_x=Width/2; bar_y=High-bar_high/2; bar_left=bar_x-bar_width/2; bar_right=bar_x+bar_width/2 Bar_top=bar_y-bar_high/2; bar_bottom=bar_y+bar_high/2; initgraph (Width,High); BeginBatchDraw ();} void clean () / / display screen {setcolor (BLACK); / / draw black lines, black filled circle setfillcolor (BLACK); fillcircle (ball_x,ball_y,radius); bar (bar_left,bar_top,bar_right,bar_bottom) / / draw black, black filled bezel} void show () / / display screen {setcolor (YELLOW); / / draw yellow line, green filled circle setfillcolor (GREEN); fillcircle (ball_x,ball_y,radius); bar (bar_left,bar_top,bar_right,bar_bottom); / / draw yellow, green filled bezel FlushBatchDraw (); Sleep (3) } void updateWithoutInput () / / updates independent of user input {/ / the bezel collides with the ball, and the ball bounces if (ball_y+radius > = bar_top) & & (ball_y+radius=bar_left) & & (ball_x0) {bar_x=bar_x-15;// position moves left bar_left=bar_x-bar_width/2; bar_right=bar_x+bar_width/2) } if (input=='d'&&bar_right0) {bar_y=bar_y-15;// position move left bar_top=bar_y-bar_high/2; bar_bottom=bar_y+bar_high/2;} if (input=='s'&&bar_bottom
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.