弹跳小球

jump_ball_1

# include <stdio.h>

# include <stdlib.h>
# include <conio.h>
# include <windows.h>
/*
弹跳小球:
画布 20*10
小球位置 10*5
画布 left top right bottom
速度 velocity_x velocity_y
*/
int main()
{
int ball_x = 0, ball_y = 5;
int left = 0, top = 0, right = 20, bottom = 10; //画布
int position_x = bottom / 2, position_y = right / 2; //小球的位置
int velocity_x = 1, velocity_y = 1;//速度

int bottom_black, right_black; //小球上面的空行和左面的空格

while (1)
{
ball_x = ball_x + velocity_x;
ball_y = ball_y + velocity_y;
system("cls");
for (bottom_black = 0; bottom_black <ball_x; bottom_black++)
printf("\n");
for (right_black = 0; right_black < ball_y; right_black++)
printf(" ");
printf("o");
/* 不能这样写的原因是因为小球的位置是不断变化的 
//画出小球
for (bottom_black = 0; bottom_black <ball_x ; bottom_black++)
{

for (right_black = 0; right_black < ball_y; right_black++)
{
if ((bottom_black == position_x) && (right_black == position_y))
printf("o");
else printf(" ");
}
printf("\n");
}*/

Sleep(50);


if ((ball_x == top) || (ball_x == bottom))
velocity_x = -velocity_x;
if ((ball_y == left) || (ball_y == right))
velocity_y = -velocity_y;
}
_getch();
return 0;

}


此程序来自学习知乎童星老师的作品,本人由于在一个不太好的学校,所以只能靠自学来度日。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值