In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-14 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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.