Get the App
SLTechnology News&Howtos  ›  Development  › 

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

Shulou Source: shulou.com Published: 2022-05-31 17:50:10 10月03日 Update

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

Tags: Bricks Clearing Learning more help practical next Code platform effects articles methods Theory knowledge articles websites Materials follow Keyboard questions Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno Redmi macOS Shulou Tech Info vpn