Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How does C++ use easyx to play brick games?

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces "how C++ uses easyx to achieve brick games". In daily operation, I believe many people have doubts about how C++ uses easyx to achieve brick games. Xiaobian consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubts about "how C++ uses easyx to achieve brick games". Next, please follow the editor to study!

The effect is as follows:

Code:

# include#include#include#include#include#include#include # define HEIGHT 700#define WIDTH 400int ball_x, ball_y;int ball_vx, ball_vy;int radius;int left, right, top, bottom;int baffle_x, baffle_y;int baffle_size;int baffle_move;int brick_x, brick_y;int brick_r;int score;int sleep_time;bool isExit;bool isLose;void initBall () {left = 0; top = 0; right = WIDTH; bottom = HEIGHT Ball_x = (right-left) / 2; ball_y = (bottom-top) / 2; ball_vx = 1; ball_vy = 1; radius = 15; brick_x = 30; brick_y = 30; brick_r = 20; score = 0; sleep_time = 5; baffle_move = 8; isExit = false; isLose = false;} void initBaffle () {baffle_x = (right-left) / 2 Baffle_y = bottom-HEIGHT/8; baffle_size = WIDTH/2;} void drawBall () {setfillcolor (RGB (0Power255,0)); fillcircle (ball_x, ball_y, radius);} void drawBrick () {if (isExit = = true) {setfillcolor (RGB (255,255,0)); fillcircle (brick_x, brick_y, brick_r) } if (isExit = = false) {isExit = 1; brick_x = rand ()% WIDTH; brick_y = rand ()% HEIGHT / 2;} printf ("score:% d", score);} void drawBaffle () {setfillcolor (RGB (255 Journal 0,0)); line (baffle_x, baffle_y, baffle_x + baffle_size, baffle_y) } void updataWithInput () {/ / Interactive char input; / / judge the mobile if (_ kbhit ()) {input = _ getch (); switch (input) {case'asides: if (baffle_x > 0) baffle_x-= baffle_move; break of the platform based on keyboard input / * case'winters: if (baffle_y > 0) baffle_y-= baffle_move; break; case's songs: if (baffle_y)

< bottom - 1) baffle_y += baffle_move; break;*/ case 'd': if (baffle_x < right - baffle_size) baffle_x += baffle_move; break; default: break; } }}void updateBall() { static int count = 0; count++; if (count == 5) { count = 0; ball_x += ball_vx; ball_y += ball_vy; } if (ball_x = right - radius) { ball_vx = -ball_vx; } if (ball_y = bottom - radius) { isLose = true; } if (ball_y == baffle_y - radius && ball_x >

= baffle_x & & ball_x

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report