Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use function to realize bouncing Ball and eliminating Brick in C language

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

This article introduces the relevant knowledge of "how to use functions to realize bouncing balls and eliminating bricks in C language". In the operation of actual cases, many people will encounter such a dilemma. Next, let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

I. Project description and final results presentation

This is a series of optimization and encapsulation on the last bounce project. Event: bouncing ball

There was no encapsulation with functions last time. This time on the basis of the last package and some functional optimization.

The final effect is as follows:

Second, the encapsulated bouncing ball

The code is as follows:

# include#include#include#include// global variable int high,width; / / the coordinate of the int ball_x,ball_y;// ball in the game screen size void gotoxy (int x camera int y) / / move the cursor to the (x STD_OUTPUT_HANDLE y) position {HANDLE handle = GetStdHandle (STD_OUTPUT_HANDLE); COORD pos; pos.X = x; pos.Y = y; SetConsoleCursorPosition (handle,pos) Initialization of} void startup () / / data {high = 15; width = 20; ball_x = 0; ball_y = width/2; ball_vx = 1; ball_vy = 1;} void show () / / display screen {gotoxy (0d0); / / move the cursor to the origin position, the following redraw the screen int iMaging j; for

Tags: Brick position ball user update input screen bezel related move cursor data coordinates size output effect effect graph code global origin Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Xiaomi Redmi Huawei Shulou Information