弹跳小球动画

这是一个使用C语言编写的弹跳小球动画程序。通过改变小球的x和y坐标,模拟小球在屏幕上的上下左右移动,并在碰到边界时实现弹跳效果。程序中使用了Windows API函数Sleep来控制小球的运动速度,同时通过系统调用cls进行清屏,以达到连续显示小球下落动画的效果。
摘要由CSDN通过智能技术生成

代码如下

 

#include<stdio.h>
#include<stdlib.h>
#include<windows.h>

int main()
{
    int i, j;
    int x=1 , y = 20;
    int a , b ;
    int velocity_x = 1;
    int velocity_y = 1;
    int top = 1, bottom = 20, left = 1, right = 50;
    while(1){
        if (x > bottom || x < top) {
            velocity_x = -1 * velocity_x;//实现小球弹跳功能
            printf("\a");
        }
        if (y > right || y < left) {
            velocity_y = -1 * velocity_y;
            printf("\a");
        }
        x = x + velocity_x;
        y = y + velocity_y;
        system("cls"); /*在循环执行前加上清屏功能可达到小球下落效果
                       需要用到头文件<stdlib.h>*/
        for (i = 0; i < x; i++) {

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值